From 8aa592e57cf5b6d16d08fcb0cc1471e143232451 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Wed, 22 Jan 2025 22:29:54 +0100 Subject: [PATCH] CR fixes --- .../Loader/CucumberNDJsonAstLoader.php | 44 +++++++------------ src/Behat/Gherkin/Loader/DirectoryLoader.php | 6 ++- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Behat/Gherkin/Loader/CucumberNDJsonAstLoader.php b/src/Behat/Gherkin/Loader/CucumberNDJsonAstLoader.php index ee6e5764..53be5f54 100644 --- a/src/Behat/Gherkin/Loader/CucumberNDJsonAstLoader.php +++ b/src/Behat/Gherkin/Loader/CucumberNDJsonAstLoader.php @@ -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), @@ -60,8 +60,6 @@ private static function getFeature(array $json, $filePath) preg_replace('/(?<=\\.feature).*$/', '', $filePath), $featureJson['location']['line'] ); - - return $feature; } /** @@ -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'] + ); } /** @@ -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'); } diff --git a/src/Behat/Gherkin/Loader/DirectoryLoader.php b/src/Behat/Gherkin/Loader/DirectoryLoader.php index 84778c2a..93f1e60e 100644 --- a/src/Behat/Gherkin/Loader/DirectoryLoader.php +++ b/src/Behat/Gherkin/Loader/DirectoryLoader.php @@ -12,6 +12,8 @@ use Behat\Gherkin\Gherkin; use Behat\Gherkin\Node\FeatureNode; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; /** * Directory contents loader. @@ -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(...));