Skip to content
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
21 changes: 13 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
coverage-driver: [ 'pcov' ]
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]

steps:
- uses: actions/checkout@v6
Expand All @@ -23,6 +22,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: pcov
tools: composer:v2.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -43,18 +43,23 @@ jobs:
run: composer install --prefer-dist

- name: Coding Standard Checks
if: ${{ matrix.php-versions == '7.4' }}
if: ${{ matrix.php-versions == '8.0' }}
run: PHP_CS_FIXER_IGNORE_ENV=1 ./bin/php-cs-fixer fix --dry-run --diff

- name: Static Analysis
if: ${{ matrix.php-versions == '7.4' }}
if: ${{ matrix.php-versions == '8.0' }}
run: ./bin/psalm.phar --no-cache

- name: Test
- name: Test with coverage
if: ${{ matrix.php-versions == '8.0' }}
run: ./bin/phpunit -d memory_limit=-1 --coverage-clover clover.xml

- name: Test without coverage
if: ${{ matrix.php-versions != '8.0' }}
run: ./bin/phpunit -d memory_limit=-1

- name: Upload coverage to Codecov
if: ${{ matrix.php-versions == '7.4' }}
if: ${{ matrix.php-versions == '8.0' }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -68,7 +73,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
tools: composer:v2.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -97,7 +102,7 @@ jobs:
runs-on: "ubuntu-22.04"
strategy:
matrix:
php-versions: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
steps:
- name: Install PHP
uses: shivammathur/setup-php@v2
Expand Down
4 changes: 2 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'@PER-CS' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PHP80Migration:risky' => true,
'@PSR2' => true,
'@DoctrineAnnotation' => true,
'array_syntax' => ['syntax' => 'short'],
Expand All @@ -24,7 +24,7 @@
'modernize_types_casting' => true, // Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
'multiline_whitespace_before_semicolons' => true, // Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.
'no_unreachable_default_argument_value' => true, // In function arguments there must not be arguments with default values before non-default ones.
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], // To avoid problems of compatibility with the old php-cs-fixer version used on PHP 7.3
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true, // Orders the elements of classes/interfaces/traits.
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build:
environment:
php: 7.4
php: 8.0

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=7.4
ARG PHP_VERSION=8.0

FROM php:${PHP_VERSION}-cli-alpine AS php_build

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ You can add parameters when you launch the tool. At the moment you can add these
phparkitect check --config=/project/yourConfigFile.php
```
* `--target-php-version`: With this parameter, you can specify which PHP version should use the parser. This can be useful to debug problems and to understand if there are problems with a different PHP version.
Supported PHP versions are: 7.4, 8.0, 8.1, 8.2 8.3
Supported PHP versions are: 8.0, 8.1, 8.2, 8.3, 8.4, 8.5
* `--stop-on-failure`: With this option the process will end immediately after the first violation.
* `--autoload`: specify the path of an autoload file to be loaded when running phparkitect.

Expand Down
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,24 @@
}
],
"require": {
"php": "^7.4|^8",
"php": "^8.0",
"ext-json": "*",
"nikic/php-parser": "~5",
"ondram/ci-detector": "^4.2",
"phpstan/phpdoc-parser": "^1.2|^2.0",
"symfony/console": "^3.0|^4.0|^5.0|^6.0|^7.0|^8.0",
"symfony/event-dispatcher": "^3.0|^4.0|^5.0|^6.0|^7.0|^8.0",
"symfony/finder": "^3.0|^4.0|^5.0|^6.0|^7.0|^8.0",
"symfony/polyfill-php80": "^1.33",
"phpstan/phpdoc-parser": "^2.0",
"symfony/console": "^5.4 || ^6.0 <6.4",
"symfony/event-dispatcher": "^5.4 || ^6.0 <6.4",
"symfony/finder": "^5.4 || ^6.0 <6.4",
"webmozart/assert": "^1.12"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.92",
"mikey179/vfsstream": "^1.6",
"phpspec/prophecy": "^1.10",
"phpspec/prophecy-phpunit": "^2.4",
"phpunit/phpunit": "^7.5|^9.0|^10.0",
"phpunit/phpunit": "^9.6|^10.0|^11.0",
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0|^8.0"
"symfony/var-dumper": "^5.4 || ^6.0 <6.4"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 2 additions & 4 deletions src/Analyzer/ClassDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(
bool $enum,
array $docBlock,
array $attributes,
string $filePath
string $filePath,
) {
$this->FQCN = $FQCN;
$this->filePath = $filePath;
Expand Down Expand Up @@ -196,9 +196,7 @@ public function hasAttribute(string $pattern): bool
{
return array_reduce(
$this->attributes,
static function (bool $carry, FullyQualifiedClassName $attribute) use ($pattern): bool {
return $carry || $attribute->matches($pattern);
},
static fn (bool $carry, FullyQualifiedClassName $attribute): bool => $carry || $attribute->matches($pattern),
false
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/FileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
FileVisitor $fileVisitor,
NameResolver $nameResolver,
DocblockTypesResolver $docblockTypesResolver,
TargetPhpVersion $targetPhpVersion
TargetPhpVersion $targetPhpVersion,
) {
$this->fileVisitor = $fileVisitor;
$this->parsingErrors = [];
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function check(
Parser $fileParser,
Violations $violations,
ParsingErrors $parsingErrors,
bool $stopOnFailure
bool $stopOnFailure,
): void {
/** @var SplFileInfo $file */
foreach ($classSetRule->getClassSet() as $file) {
Expand Down
2 changes: 0 additions & 2 deletions src/CLI/TargetPhpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class TargetPhpVersion
{
public const PHP_7_4 = '7.4';
public const PHP_8_0 = '8.0';
public const PHP_8_1 = '8.1';
public const PHP_8_2 = '8.2';
Expand All @@ -17,7 +16,6 @@ class TargetPhpVersion
public const PHP_8_5 = '8.5';

public const VALID_PHP_VERSIONS = [
'7.4',
'8.0',
'8.1',
'8.2',
Expand Down
4 changes: 1 addition & 3 deletions src/Expression/ForClasses/Implement.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str

$interface = $this->interface;
$interfaces = $theClass->getInterfaces();
$implements = function (FullyQualifiedClassName $FQCN) use ($interface): bool {
return $FQCN->matches($interface);
};
$implements = fn (FullyQualifiedClassName $FQCN): bool => $FQCN->matches($interface);

if (0 === \count(array_filter($interfaces, $implements))) {
$violation = Violation::create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti
public function evaluate(ClassDescription $theClass, Violations $violations, string $because): void
{
$namespace = $this->namespace;
$depends = function (ClassDependency $dependency) use ($namespace): bool {
return !$dependency->getFQCN()->matches($namespace);
};
$depends = fn (ClassDependency $dependency): bool => !$dependency->getFQCN()->matches($namespace);

$dependencies = $theClass->getDependencies();
$externalDeps = array_filter($dependencies, $depends);
Expand Down
4 changes: 1 addition & 3 deletions src/Expression/ForClasses/NotImplement.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str

$interface = $this->interface;
$interfaces = $theClass->getInterfaces();
$implements = function (FullyQualifiedClassName $FQCN) use ($interface): bool {
return $FQCN->matches($interface);
};
$implements = fn (FullyQualifiedClassName $FQCN): bool => $FQCN->matches($interface);

if (\count(array_filter($interfaces, $implements)) > 0) {
$violation = Violation::create(
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/ArchRuleCheckerConstraintAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function toString(): string

protected function matches(
/** @var ArchRule $rule */
$other
$other,
): bool {
$this->runner->check(
ClassSetRules::create($this->classSet, $other),
Expand Down
8 changes: 2 additions & 6 deletions src/RuleBuilders/Architecture/Architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public function rules(string $because = 'of component architecture'): iterable
$forbiddenComponents = array_diff($layerNames, [$name], $this->allowedDependencies[$name]);

if (!empty($forbiddenComponents)) {
$forbiddenSelectors = array_values(array_map(function (string $componentName): string {
return $this->componentSelectors[$componentName];
}, $forbiddenComponents));
$forbiddenSelectors = array_values(array_map(fn (string $componentName): string => $this->componentSelectors[$componentName], $forbiddenComponents));

yield Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces($selector))
Expand All @@ -105,9 +103,7 @@ public function rules(string $because = 'of component architecture'): iterable
continue;
}

$allowedDependencies = array_values(array_map(function (string $componentName): string {
return $this->componentSelectors[$componentName];
}, $this->componentDependsOnlyOnTheseNamespaces[$name]));
$allowedDependencies = array_values(array_map(fn (string $componentName): string => $this->componentSelectors[$componentName], $this->componentDependsOnlyOnTheseNamespaces[$name]));

yield Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces($selector))
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/ArchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
Constraints $constraints,
string $because,
array $classesToBeExcluded,
bool $runOnlyThis
bool $runOnlyThis,
) {
$this->thats = $specs;
$this->shoulds = $constraints;
Expand Down
8 changes: 2 additions & 6 deletions src/Rules/Violations.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public static function fromJson(string $json): self

$instance = new self();

$instance->violations = array_map(function (array $json): Violation {
return Violation::fromJson($json);
}, $json['violations']);
$instance->violations = array_map(fn (array $json): Violation => Violation::fromJson($json), $json['violations']);

return $instance;
}
Expand Down Expand Up @@ -113,9 +111,7 @@ public function remove(self $violations, bool $ignoreBaselineLinenumbers = false

public function sort(): void
{
usort($this->violations, static function (Violation $v1, Violation $v2): int {
return $v1 <=> $v2;
});
usort($this->violations, static fn (Violation $v1, Violation $v2): int => $v1 <=> $v2);
}

public function jsonSerialize(): array
Expand Down
2 changes: 1 addition & 1 deletion tests/E2E/Cli/CheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected function runCheck(
bool $skipBaseline = false,
bool $ignoreBaselineNumbers = false,
string $format = 'text',
?string $autoloadFilePath = null
?string $autoloadFilePath = null,
): ApplicationTester {
$input = ['check'];

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Analyzer/FileParser/CanParseClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function __construct() {

private function parseCode(string $code, ?string $version = null): array
{
$fp = FileParserFactory::forPhpVersion($version ?? TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion($version ?? TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');

return $fp->getClassDescriptions();
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/Analyzer/FileParser/CanParseDocblocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class MyClass
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -134,7 +134,7 @@ class MyClass
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -163,7 +163,7 @@ class MyClass
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -194,7 +194,7 @@ public function __construct(array $dtoList)
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -225,7 +225,7 @@ public function __construct(array $dtoList)
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -256,7 +256,7 @@ public function __construct(array $dtoList)
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -290,7 +290,7 @@ public function __construct(string $var1, array $dtoList, $var2, array $voList)
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -322,7 +322,7 @@ public function getList(): array
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -354,7 +354,7 @@ public function getList(): array
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down Expand Up @@ -386,7 +386,7 @@ public function getList(): array
}
EOF;

$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_7_4);
$fp = FileParserFactory::forPhpVersion(TargetPhpVersion::PHP_8_0);
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();

Expand Down
Loading