Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Jan 22, 2025
1 parent 5db6995 commit 8aa592e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
44 changes: 15 additions & 29 deletions src/Behat/Gherkin/Loader/CucumberNDJsonAstLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static function getFeature(array $json, $filePath)

$featureJson = $json['gherkinDocument']['feature'];

$feature = new FeatureNode(
return new FeatureNode(
$featureJson['name'] ?? null,
$featureJson['description'] ? trim($featureJson['description']) : null,
self::getTags($featureJson),
Expand All @@ -60,8 +60,6 @@ private static function getFeature(array $json, $filePath)
preg_replace('/(?<=\\.feature).*$/', '', $filePath),
$featureJson['location']['line']
);

return $feature;
}

/**
Expand Down Expand Up @@ -114,22 +112,22 @@ static function ($child) {

private static function getBackground(array $json): ?BackgroundNode
{
$backgrounds = array_values(
array_map(
static fn ($child) => new BackgroundNode(
$child['background']['name'],
self::getSteps($child['background']['steps'] ?? []),
$child['background']['keyword'],
$child['background']['location']['line']
),
array_filter(
$json['children'] ?? [],
static fn ($child) => isset($child['background']),
)
)
$backgrounds = array_filter(
$json['children'] ?? [],
static fn($child) => isset($child['background']),
);

return count($backgrounds) === 1 ? $backgrounds[0] : null;
if (count($backgrounds) !== 1) {
return null;
}

$background = array_shift($backgrounds);
return new BackgroundNode(
$background['background']['name'],
self::getSteps($background['background']['steps'] ?? []),
$background['background']['keyword'],
$background['background']['location']['line']
);
}

/**
Expand Down Expand Up @@ -158,21 +156,9 @@ private static function getTables(array $items): array
static function ($tableJson) {
$table = [];

$table[$tableJson['tableHeader']['location']['line']] = array_map(
static function ($cell) {
return $cell['value'];
},
$tableJson['tableHeader']['cells']
);
$table[$tableJson['tableHeader']['location']['line']] = array_column($tableJson['tableHeader']['cells'], 'value');

foreach ($tableJson['tableBody'] as $bodyRow) {
$table[$bodyRow['location']['line']] = array_map(
static function ($cell) {
return $cell['value'];
},
$bodyRow['cells']
);
$table[$bodyRow['location']['line']] = array_column($bodyRow['cells'], 'value');
}

Expand Down
6 changes: 4 additions & 2 deletions src/Behat/Gherkin/Loader/DirectoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Behat\Gherkin\Gherkin;
use Behat\Gherkin\Node\FeatureNode;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

/**
* Directory contents loader.
Expand Down Expand Up @@ -56,8 +58,8 @@ public function load($resource)
{
$path = $this->findAbsolutePath($resource);

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS)
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)
);
$paths = array_map(strval(...), iterator_to_array($iterator));
uasort($paths, strnatcasecmp(...));
Expand Down

0 comments on commit 8aa592e

Please sign in to comment.