Skip to content

Commit

Permalink
Merge pull request #277 from uuf6429/chore/phpcsfixer-setup
Browse files Browse the repository at this point in the history
chore: Add initial PHP-CS-Fixer configuration and apply cs fixes
  • Loading branch information
acoulton authored Dec 22, 2024
2 parents 6b652ca + 2b55509 commit 51ddede
Show file tree
Hide file tree
Showing 88 changed files with 2,169 additions and 1,850 deletions.
15 changes: 15 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Git 2.23+ allows ignoring commits from git-blame, useful to not display large automated commits.
#
# This file is a list of such commits, that you most probably are not interested in.
# To make this work for your local setup, you need to run the following command:
#
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
#
# A few rules for changing this file:
# - Commits are in chronological order - oldest on top. Therefore new commits should be added in the end.
# - The purpose is specifically for large commits - avoid adding commits with a very small impact, even if related
# to automated code style formatting.
# - Each commit should be preceded with a comment detailing the purpose of the commit.

# PHP-CS-Fixer Setup - Apply automated changes
cc23fdc9376975d209489ae88b22ed945871d9cb
18 changes: 10 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/.github/ export-ignore
/bin/ export-ignore
/tests/ export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CONTRIBUTING.md export-ignore
/phpunit.dist.xml export-ignore
/.github/ export-ignore
/bin/ export-ignore
/tests/ export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CONTRIBUTING.md export-ignore
/phpunit.dist.xml export-ignore
/.php-cs-fixer.dist.php export-ignore
/.git-blame-ignore-revs export-ignore
16 changes: 16 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ on:
types: [ created ]

jobs:
check_code_style:
name: Check code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: '8.3'

- name: Install dependencies
run: composer update

- run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots

tests:
runs-on: ubuntu-latest
name: Build and test
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ composer.lock
.phpunit.cache
.phpunit.result.cache
phpunit.xml
.php-cs-fixer.php
.php-cs-fixer.cache
34 changes: 34 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->notPath('i18n.php');

return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@PER-CS' => true,
'@Symfony' => true,
'header_comment' => [
'header' => <<<'TEXT'
This file is part of the Behat Gherkin Parser.
(c) Konstantin Kudryashov <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
TEXT
],
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
],
'concat_space' => ['spacing' => 'one'],
'phpdoc_align' => ['align' => 'left'],
'heredoc_to_nowdoc' => true,
'heredoc_indentation' => ['indentation' => 'same_as_start'],
'single_line_throw' => false,
'ternary_to_null_coalescing' => true,
'global_namespace_import' => false,
])
->setFinder($finder);
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ We use automated tools to ensure that the code has a consistent style and is of
composer lint
```

## Automated Fixes

Some problems detected by the linting tools can be fixed automatically. Simply run the following:

```shell
composer fix
```

## Contributing to Gherkin Translations

Gherkin supports &rarr;40 different languages and you could add more! You might notice `i18n.php` file in the root of
Expand Down
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"require-dev": {
"symfony/yaml": "^5.4 || ^6.4 || ^7.0",
"phpunit/phpunit": "^10.5",
"cucumber/cucumber": "dev-gherkin-24.1.0"
"cucumber/cucumber": "dev-gherkin-24.1.0",
"friendsofphp/php-cs-fixer": "^3.65"
},

"suggest": {
Expand Down Expand Up @@ -67,11 +68,21 @@

"scripts": {
"lint": [
"Composer\\Config::disableProcessTimeout"
"Composer\\Config::disableProcessTimeout",
"vendor/bin/php-cs-fixer check --diff --show-progress=dots --verbose"
],
"test": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpunit ./tests"
],
"fix": [
"Composer\\Config::disableProcessTimeout",
"vendor/bin/php-cs-fixer fix --diff --show-progress=dots"
]
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": false
}
}
}
8 changes: 4 additions & 4 deletions src/Behat/Gherkin/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand All @@ -22,8 +22,8 @@ interface CacheInterface
/**
* Checks that cache for feature exists and is fresh.
*
* @param string $path Feature path
* @param integer $timestamp The last time feature was updated
* @param string $path Feature path
* @param int $timestamp The last time feature was updated
*
* @return bool
*/
Expand All @@ -41,7 +41,7 @@ public function read($path);
/**
* Caches feature node.
*
* @param string $path Feature path
* @param string $path Feature path
* @param FeatureNode $feature Feature instance
*/
public function write($path, FeatureNode $feature);
Expand Down
28 changes: 14 additions & 14 deletions src/Behat/Gherkin/Cache/FileCache.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

/*
* This file is part of the Behat Gherkin.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Behat\Gherkin\Cache;

use Behat\Gherkin\Exception\CacheException;
use Behat\Gherkin\Node\FeatureNode;
use Behat\Gherkin\Gherkin;
use Behat\Gherkin\Node\FeatureNode;

/**
* File cache.
Expand All @@ -27,13 +27,13 @@ class FileCache implements CacheInterface
/**
* Initializes file cache.
*
* @param string $path Path to the folder where to store caches.
* @param string $path path to the folder where to store caches
*
* @throws CacheException
*/
public function __construct($path)
{
$this->path = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'v'.Gherkin::VERSION;
$this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'v' . Gherkin::VERSION;

if (!is_dir($this->path)) {
@mkdir($this->path, 0777, true);
Expand All @@ -47,8 +47,8 @@ public function __construct($path)
/**
* Checks that cache for feature exists and is fresh.
*
* @param string $path Feature path
* @param integer $timestamp The last time feature was updated
* @param string $path Feature path
* @param int $timestamp The last time feature was updated
*
* @return bool
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ public function read($path)
$feature = unserialize(file_get_contents($cachePath));

if (!$feature instanceof FeatureNode) {
throw new CacheException(sprintf('Can not load cache for a feature "%s" from "%s".', $path, $cachePath ));
throw new CacheException(sprintf('Can not load cache for a feature "%s" from "%s".', $path, $cachePath));
}

return $feature;
Expand All @@ -87,7 +87,7 @@ public function read($path)
/**
* Caches feature node.
*
* @param string $path Feature path
* @param string $path Feature path
* @param FeatureNode $feature Feature instance
*/
public function write($path, FeatureNode $feature)
Expand All @@ -104,6 +104,6 @@ public function write($path, FeatureNode $feature)
*/
protected function getCachePathFor($path)
{
return $this->path.'/'.md5($path).'.feature.cache';
return $this->path . '/' . md5($path) . '.feature.cache';
}
}
24 changes: 12 additions & 12 deletions src/Behat/Gherkin/Cache/MemoryCache.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/*
* This file is part of the Behat Gherkin.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Behat\Gherkin\Cache;

Expand All @@ -20,14 +20,14 @@
*/
class MemoryCache implements CacheInterface
{
private $features = array();
private $timestamps = array();
private $features = [];
private $timestamps = [];

/**
* Checks that cache for feature exists and is fresh.
*
* @param string $path Feature path
* @param integer $timestamp The last time feature was updated
* @param string $path Feature path
* @param int $timestamp The last time feature was updated
*
* @return bool
*/
Expand Down Expand Up @@ -55,12 +55,12 @@ public function read($path)
/**
* Caches feature node.
*
* @param string $path Feature path
* @param string $path Feature path
* @param FeatureNode $feature Feature instance
*/
public function write($path, FeatureNode $feature)
{
$this->features[$path] = $feature;
$this->features[$path] = $feature;
$this->timestamps[$path] = time();
}
}
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Exception/CacheException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Exception/LexerException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Exception/NodeException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Gherkin/Exception/ParserException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand Down
6 changes: 2 additions & 4 deletions src/Behat/Gherkin/Filter/ComplexFilter.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand All @@ -22,13 +22,11 @@ abstract class ComplexFilter implements ComplexFilterInterface
/**
* Filters feature according to the filter.
*
* @param FeatureNode $feature
*
* @return FeatureNode
*/
public function filterFeature(FeatureNode $feature)
{
$scenarios = array();
$scenarios = [];
foreach ($feature->getScenarios() as $scenario) {
if (!$this->isScenarioMatch($feature, $scenario)) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Behat/Gherkin/Filter/ComplexFilterInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of the Behat Gherkin.
* This file is part of the Behat Gherkin Parser.
* (c) Konstantin Kudryashov <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
Expand All @@ -23,7 +23,7 @@ interface ComplexFilterInterface extends FeatureFilterInterface
/**
* Checks if scenario or outline matches specified filter.
*
* @param FeatureNode $feature Feature node instance
* @param FeatureNode $feature Feature node instance
* @param ScenarioInterface $scenario Scenario or Outline node instance
*
* @return bool
Expand Down
Loading

0 comments on commit 51ddede

Please sign in to comment.