Skip to content

Commit

Permalink
Add support for PHP >8.1 and PHPStan >1.*
Browse files Browse the repository at this point in the history
  • Loading branch information
ikvasnica committed Aug 23, 2023
1 parent 27ba292 commit d31e420
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@master
with:
php-version: 7.3
php-version: 8.2
coverage: xdebug
- name: Load dependencies from cache
id: composer-cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coding_standards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@master
with:
php-version: 7.3
php-version: 8.2
coverage: none
- name: Load dependencies from cache
id: composer-cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@master
with:
php-version: 7.3
php-version: 8.2
coverage: none
- name: Load dependencies from cache
id: composer-cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
php-versions: ['8.1', '8.2']

name: Tests on PHP ${{ matrix.php-versions }}
steps:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
],
"minimum-stability": "stable",
"require": {
"php": ">=7.2",
"php": ">=8.1",
"nette/utils": "~3.0",
"nikic/php-parser": "^4.3",
"phpstan/phpstan": "~0.12"
"phpstan/phpstan": "^1.10"
},
"require-dev": {
"ergebnis/phpstan-rules": "^0.14.2",
"ergebnis/phpstan-rules": "^2.1.0",
"php-coveralls/php-coveralls": "2.*",
"phpstan/phpstan-strict-rules": "~0.12",
"phpunit/phpunit": "^8.5.2 || ^9.0.0",
"symplify/easy-coding-standard": "~7.2.2"
"phpstan/phpstan-strict-rules": "^1.5.1",
"phpunit/phpunit": "^9.0.0",
"symplify/easy-coding-standard": "^12.0.6"
},
"suggest": {
"phpstan/phpstan-deprecation-rules": "Rules for disallowing deprecation code.",
Expand Down
34 changes: 34 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$ecsConfig->skip([
__DIR__ . '/tests/*/data/*',
]);

// this way you add a single rule
$ecsConfig->rules([
NoUnusedImportsFixer::class,
]);

// this way you can add sets - group of rules
$ecsConfig->sets([
// run and fix, one by one
SetList::SPACES,
SetList::ARRAY,
SetList::NAMESPACES,
SetList::COMMON,
SetList::PSR_12,
SetList::CLEAN_CODE,
]);
};
23 changes: 0 additions & 23 deletions ecs.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ parameters:
unitTestNamespaceContainsString: Rules

ergebnis:
classesAllowedToBeExtended:
- PHPStan\Testing\RuleTestCase
noExtends:
classesAllowedToBeExtended:
- PHPStan\Testing\RuleTestCase
4 changes: 2 additions & 2 deletions src/Rules/AssertSameOverAssertEqualsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$firstType = $scope->getType($node->args[0]->value);
$secondType = $scope->getType($node->args[1]->value);
$firstType = $scope->getType($node->getArgs()[0]->value);
$secondType = $scope->getType($node->getArgs()[1]->value);

if ($this->isScalarType($firstType) || $this->isScalarType($secondType)) {
return ['Using "assertEquals" is forbidden with a scalar type as an argument. Use "assertSame" instead.'];
Expand Down
18 changes: 13 additions & 5 deletions src/Rules/DisallowSetupAndConstructorRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@
namespace ikvasnica\PHPStan\Rules;

use ikvasnica\PHPStan\Rules\Helpers\TestClassDetector;
use function in_array;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use function in_array;
use function sprintf;

/**
* @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\ClassMethod>
*/
final class DisallowSetupAndConstructorRule implements Rule
{
/** @var string */
/**
* @var string
*/
private const SETUP_METHOD_NAME = 'setUp';

/** @var array<string> */
/**
* @var array<string>
*/
private const DISALLOWED_METHODS = ['__construct', self::SETUP_METHOD_NAME];

/** @var string */
/**
* @var string
*/
private $unitTestNamespaceContainsString;

/** @var bool */
/**
* @var bool
*/
private $allowSetupInUnitTests;

public function __construct(string $unitTestNamespaceContainsString, bool $allowSetupInUnitTests)
Expand Down
4 changes: 3 additions & 1 deletion src/Rules/Helpers/TestClassDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

final class TestClassDetector
{
/** @var string */
/**
* @var string
*/
private const TEST_CLASS_ENDING_STRING = 'Test';

public static function isUnitTest(string $namespace, string $className, string $unitTestNamespacePattern): bool
Expand Down
8 changes: 6 additions & 2 deletions src/Rules/NoNullableArgumentRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
*/
final class NoNullableArgumentRule implements Rule
{
/** @var string */
/**
* @var string
*/
private const TEST_ANNOTATION = '@test';

/** @var string */
/**
* @var string
*/
private const TEST_METHOD_NAME_BEGINNING = 'test';

public function getNodeType(): string
Expand Down
8 changes: 6 additions & 2 deletions src/Rules/UnitExtendsFromTestCaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
*/
final class UnitExtendsFromTestCaseRule implements Rule
{
/** @var array<int, string> */
/**
* @var array<int, string>
*/
private $classesAllowedToBeExtendedInTests;

/** @var string */
/**
* @var string
*/
private $unitTestNamespaceContainsString;

/**
Expand Down

0 comments on commit d31e420

Please sign in to comment.