Skip to content
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

PHPStan setup #276

Draft
wants to merge 5 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
19 changes: 11 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/.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
/phpstan.dist.neon export-ignore
/phpstan-baseline.neon export-ignore
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ on:
types: [ created ]

jobs:
check_composer:
name: Check composer.json
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: '8.3'
- run: composer validate --strict --no-check-lock

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

static_analysis:
name: Static analysis
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/phpstan analyze

tests:
runs-on: ubuntu-latest
name: Build and test
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ composer.lock
.phpunit.cache
.phpunit.result.cache
phpunit.xml
.php-cs-fixer.php
.php-cs-fixer.cache
phpstan.neon
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())
->setRiskyAllowed(true)
->setRules([
'@PER-CS' => true,
'@Symfony' => true,
'header_comment' => [
'header' => <<<'TEXT'
This file is part of the Behat Gherkin Parser.
(c) Konstantin Kudryashov <ever.zet@gmail.com>

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'],
'phpdoc_array_type' => true,
'phpdoc_list_type' => true,
])
->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
20 changes: 18 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"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",
"phpstan/phpstan": "^2",
"phpstan/extension-installer": "^1",
"phpstan/phpstan-phpunit": "^2"
},

"suggest": {
Expand Down Expand Up @@ -67,11 +71,23 @@

"scripts": {
"lint": [
"Composer\\Config::disableProcessTimeout"
"Composer\\Config::disableProcessTimeout",
"vendor/bin/phpstan analyse --no-progress --memory-limit 512M",
"vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots"
],
"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": true
}
}
}
6 changes: 6 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 0
paths:
- bin
- src
- tests
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 <ever.zet@gmail.com>
*
* 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 <ever.zet@gmail.com>
*
* 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 <ever.zet@gmail.com>
*
* 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 <ever.zet@gmail.com>
*
* 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 <ever.zet@gmail.com>
*
* 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();
}
}
6 changes: 2 additions & 4 deletions 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 <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
Expand All @@ -10,13 +10,11 @@

namespace Behat\Gherkin\Exception;

use RuntimeException;

/**
* Cache exception.
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*/
class CacheException extends RuntimeException implements Exception
class CacheException extends \RuntimeException implements Exception
{
}
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 <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
Expand Down
6 changes: 2 additions & 4 deletions 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 <ever.zet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
Expand All @@ -10,8 +10,6 @@

namespace Behat\Gherkin\Exception;

use RuntimeException;

class LexerException extends RuntimeException implements Exception
class LexerException extends \RuntimeException implements Exception
{
}
Loading
Loading