8000 PHP-CS-Fixer enable risky and list rules by uuf6429 · Pull Request #280 · Behat/Gherkin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PHP-CS-Fixer enable risky and list rules #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->setRules([
'@PER-CS' => true,
'@Symfony' => true,
Expand All @@ -30,5 +31,7 @@
'single_line_throw' => false,
'ternary_to_null_coalescing' => true,
'global_namespace_import' => false,
'phpdoc_array_type' => true,
'phpdoc_list_type' => true,
])
->setFinder($finder);
18 changes: 8 additions & 10 deletions src/Behat/Gherkin/Filter/PathsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@ class PathsFilter extends SimpleFilter
/**
* Initializes filter.
*
* @param string[] $paths List of approved paths
* @param array<array-key, string> $paths List of approved paths
*/
public function __construct(array $paths)
{
$this->filterPaths = array_map(
function ($realpath) {
return rtrim($realpath, DIRECTORY_SEPARATOR) .
(is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
},
array_filter(
array_map('realpath', $paths)
)
);
foreach ($paths as $path) {
if (($realpath = realpath($path)) === false) {
continue;
}
$this->filterPaths[] = rtrim($realpath, DIRECTORY_SEPARATOR)
. (is_dir($realpath) ? DIRECTORY_SEPARATOR : '');
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Filter/TagFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function isScenarioMatch(FeatureNode $feature, ScenarioInterface $scenari
/**
* Checks that node matches condition.
*
* @param string[] $tags
* @param array<array-key, string> $tags
*
* @return bool
*/
Expand Down
14 changes: 7 additions & 7 deletions src/Behat/Gherkin/Gherkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class Gherkin
public const VERSION = '4.8.0';

/**
* @var LoaderInterface[]
* @var list<LoaderInterface>
*/
protected $loaders = [];
/**
* @var FeatureFilterInterface[]
* @var list<FeatureFilterInterface>
*/
protected $filters = [];

Expand All @@ -62,12 +62,12 @@ public function addFilter(FeatureFilterInterface $filter)
/**
* Sets filters to the parser.
*
* @param FeatureFilterInterface[] $filters
* @param array<array-key, FeatureFilterInterface> $filters
*/
public function setFilters(array $filters)
{
$this->filters = [];
array_map([$this, 'addFilter'], $filters);
array_map($this->addFilter(...), $filters);
}

/**
Expand All @@ -88,7 +88,7 @@ public function setBasePath($path)
* Loads & filters resource with added loaders.
*
* @param mixed $resource Resource to load
* @param FeatureFilterInterface[] $filters Additional filters
* @param array<array-key, FeatureFilterInterface> $filters Additional filters
*
* @return array
*/
Expand All @@ -97,10 +97,10 @@ public function load($resource, array $filters = [])
$filters = array_merge($this->filters, $filters);

$matches = [];
if (preg_match('/^(.*)\:(\d+)-(\d+|\*)$/', $resource, $matches)) {
if (preg_match('/^(.*):(\d+)-(\d+|\*)$/', $resource, $matches)) {
$resource = $matches[1];
$filters[] = new LineRangeFilter($matches[2], $matches[3]);
} elseif (preg_match('/^(.*)\:(\d+)$/', $resource, $matches)) {
} elseif (preg_match('/^(.*):(\d+)$/', $resource, $matches)) {
$resource = $matches[1];
$filters[] = new LineFilter($matches[2]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Behat/Gherkin/Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function supports($resource)
*
* @param mixed $resource Resource to load
*
* @return FeatureNode[]
* @return list<FeatureNode>
*/
public function load($resource)
{
Expand Down Expand Up @@ -195,7 +195,7 @@ protected function loadOutlineHash(array $hash, $line = 0)
/**
* Loads steps from provided hash.
*
* @return StepNode[]
* @return list<StepNode>
*/
private function loadStepsHash(array $hash)
{
Expand Down
91 changes: 36 additions & 55 deletions src/Behat/Gherkin/Loader/CucumberNDJsonAstLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ private static function getFeature(array $json, $filePath)
}

/**
* @return string[]
* @return list<string>
*/
private static function getTags(array $json)
{
return array_map(
static function (array $tag) { return preg_replace('/^@/', '', $tag['name']); },
$json['tags'] ?? []
static fn (array $tag) => preg_replace('/^@/', '', $tag['name']),
array_values($json['tags'] ?? [])
);
}

/**
* @return ScenarioInterface[]
* @return list<ScenarioInterface>
*/
private static function getScenarios(array $json)
{
Expand All @@ -92,15 +92,15 @@ static function ($child) {
$child['scenario']['keyword'],
$child['scenario']['location']['line']
);
} else {
return new ScenarioNode(
$child['scenario']['name'],
self::getTags($child['scenario']),
self::getSteps($child['scenario']['steps'] ?? []),
$child['scenario']['keyword'],
$child['scenario']['location']['line']
);
}

return new ScenarioNode(
$child['scenario']['name'],
self::getTags($child['scenario']),
self::getSteps($child['scenario']['steps'] ?? []),
$child['scenario']['keyword'],
$child['scenario']['location']['line']
);
},
array_filter(
$json['children'] ?? [],
Expand All @@ -112,75 +112,56 @@ static function ($child) {
);
}

/**
* @return BackgroundNode|null
*/
private static function getBackground(array $json)
private static function getBackground(array $json): ?BackgroundNode
{
$backgrounds = array_values(
array_map(
static function ($child) {
return new BackgroundNode(
$child['background']['name'],
self::getSteps($child['background']['steps'] ?? []),
$child['background']['keyword'],
$child['background']['location']['line']
);
},
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 function ($child) {
return isset($child['background']);
}
static fn ($child) => isset($child['background']),
)
)
);

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

/**
* @return StepNode[]
* @return list<StepNode>
*/
private static function getSteps(array $json)
private static function getSteps(array $items): array
{
return array_map(
static function (array $json) {
return new StepNode(
trim($json['keyword']),
$json['text'],
[],
$json['location']['line'],
trim($json['keyword'])
);
},
$json
static fn (array $item) => new StepNode(
trim($item['keyword']),
$item['text'],
[],
$item['location']['line'],
trim($item['keyword'])
),
array_values($items)
);
}

/**
* @return ExampleTableNode[]
* @return list<ExampleTableNode>
*/
private static function getTables(array $json)
private static function getTables(array $items): array
{
return array_map(
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');
}

return new ExampleTableNode(
Expand All @@ -189,7 +170,7 @@ static function ($cell) {
self::getTags($tableJson)
);
},
$json
array_values($items)
);
}
}
22 changes: 11 additions & 11 deletions src/Behat/Gherkin/Loader/DirectoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ public function __construct(Gherkin $gherkin)
/**
* Checks if current loader supports provided resource.
*
* @param mixed $path Resource to load
* @param mixed $resource Resource to load
*
* @return bool
*/
public function supports($path)
public function supports($resource)
{
return is_string($path)
&& is_dir($this->findAbsolutePath($path));
return is_string($resource)
&& is_dir($this->findAbsolutePath($resource));
}

/**
* Loads features from provided resource.
*
* @param string $path Resource to load
* @param string $resource Resource to load
*
* @return FeatureNode[]
* @return list<FeatureNode>
*/
public function load($path)
public function load($resource)
{
$path = $this->findAbsolutePath($path);
$path = $this->findAbsolutePath($resource);

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

$features = [];

Expand All @@ -71,7 +71,7 @@ public function load($path)
$loader = $this->gherkin->resolveLoader($path);

if ($loader !== null) {
$features = array_merge($features, $loader->load($path));
array_push($features, ...$loader->load($path));
}
}

Expand Down
21 changes: 10 additions & 11 deletions src/Behat/Gherkin/Loader/GherkinFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ public function setCache(CacheInterface $cache)
/**
* Checks if current loader supports provided resource.
*
* @param mixed $path Resource to load
* @param mixed $resource Resource to load
*
* @return bool
*/
public function supports($path)
public function supports($resource)
{
return is_string($path)
&& is_file($absolute = $this->findAbsolutePath($path))
&& pathinfo($absolute, PATHINFO_EXTENSION) === 'feature';
return is_string($resource)
&& is_file($absolute = $this->findAbsolutePath($resource))
&& pathinfo($absolute, PATHINFO_EXTENSION) === 'feature';
}

/**
* Loads features from provided resource.
*
* @param string $path Resource to load
* @param string $resource Resource to load
*
* @return FeatureNode[]
* @return list<FeatureNode>
*/
public function load($path)
public function load($resource)
{
$path = $this->findAbsolutePath($path);
$path = $this->findAbsolutePath($resource);

if ($this->cache) {
if ($this->cache->isFresh($path, filemtime($path))) {
Expand All @@ -94,8 +94,7 @@ public function load($path)
protected function parseFeature($path)
{
$content = file_get_contents($path);
$feature = $this->parser->parse($content, $path);

return $feature;
return $this->parser->parse($content, $path);
}
}
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Loader/LoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function supports($resource);
*
* @param mixed $resource Resource to load
*
* @return FeatureNode[]
* @return list<FeatureNode>
*/
public function load($resource);
}
Loading
Loading
0