diff --git a/.github/workflows/architectural-rules.yml b/.github/workflows/architectural-rules.yml
index cc491ac6..1346b4ff 100644
--- a/.github/workflows/architectural-rules.yml
+++ b/.github/workflows/architectural-rules.yml
@@ -11,7 +11,7 @@ jobs:
steps:
- name: "Checkout"
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: PHPArkitect
uses: docker://phparkitect/arkitect-github-actions:latest
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c1a1f9a2..c875e372 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -9,11 +9,11 @@ on:
jobs:
build:
- runs-on: "ubuntu-22.04"
+ runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
- php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
+ php-versions: [ '8.1', '8.2', '8.3', '8.4']
coverage-driver: [ 'pcov' ]
steps:
@@ -23,7 +23,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- tools: composer:v2.2
+ tools: composer:v2.8
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
@@ -32,7 +32,7 @@ jobs:
- name: Cache Composer packages
id: composer-cache
- uses: actions/cache@v2
+ uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
@@ -52,13 +52,13 @@ jobs:
run: ./bin/phpunit -d memory_limit=-1 --coverage-clover clover.xml
- name: Upload coverage to Codecov
- if: ${{ matrix.php-versions == '7.1' }}
+ if: ${{ matrix.php-versions == '8.4' }}
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
phar:
- runs-on: "ubuntu-20.04"
+ runs-on: ubuntu-24.04
needs: build
steps:
- uses: actions/checkout@v3
@@ -66,8 +66,8 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
- php-version: 7.1
- tools: composer:v2.2
+ php-version: 8.1
+ tools: composer:v2.8
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
@@ -84,7 +84,7 @@ jobs:
run: mv ./phparkitect.phar phparkitect-${{ github.sha }}.phar
- name: "Upload phar file artifact"
- uses: actions/upload-artifact@v3
+ uses: actions/upload-artifact@v4
with:
name: phar-artifact
path: ./phparkitect-${{ github.sha }}.phar
@@ -92,11 +92,10 @@ jobs:
smoke-test-phar:
needs: phar
- runs-on: "ubuntu-20.04"
+ runs-on: ubuntu-24.04
strategy:
matrix:
- php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
- coverage-driver: [ 'pcov' ]
+ php-versions: [ '8.1', '8.2', '8.3', '8.4' ]
steps:
- name: Install PHP
@@ -107,7 +106,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}
- name: "Download phar ./phparkitect-${{ github.sha }}.phar"
- uses: actions/download-artifact@v3
+ uses: actions/download-artifact@v4
with:
# will download phar in project root
name: phar-artifact
@@ -117,11 +116,11 @@ jobs:
publish_phar:
needs: [build, smoke-test-phar]
- runs-on: "ubuntu-20.04"
+ runs-on: ubuntu-24.04
if: github.event_name == 'release'
steps:
- name: "Download phar ./phparkitect-${{ github.sha }}.phar"
- uses: actions/download-artifact@v3
+ uses: actions/download-artifact@v4
with:
# will download phar in project root
name: phar-artifact
@@ -136,7 +135,7 @@ jobs:
publish_docker_images:
needs: [build, smoke-test-phar]
- runs-on: "ubuntu-20.04"
+ runs-on: ubuntu-24.04
if: github.ref == 'refs/heads/main' || github.event_name == 'release'
steps:
diff --git a/.gitignore b/.gitignore
index 87a73ec0..18411a7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
/vendor/
-.phpunit.result.cache
+.phpunit.cache
.idea
.php_cs.cache
.php-cs-fixer.cache
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 64388f3f..4166b25c 100644
--- a/.php-cs-fixer.dist.php
+++ b/.php-cs-fixer.dist.php
@@ -11,6 +11,7 @@
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
+ '@PHP84Migration' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PSR2' => true,
diff --git a/Dockerfile b/Dockerfile
index 6b96ba7c..46dfa40b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,8 +1,8 @@
-ARG PHP_VERSION=7.1
+ARG PHP_VERSION=8.1
FROM php:${PHP_VERSION}-cli-alpine AS php_build
-COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer
+COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer
WORKDIR /arkitect
diff --git a/README.md b/README.md
index 15cd4738..745f3369 100644
--- a/README.md
+++ b/README.md
@@ -464,7 +464,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.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2
+Supported PHP versions are: 8.1, 8.2, 8.3, 8.4
* `--stop-on-failure`: With this option the process will end immediately after the first violation.
## Run only a specific rule
diff --git a/bin/box.phar b/bin/box.phar
index e3017577..23b693c3 100644
Binary files a/bin/box.phar and b/bin/box.phar differ
diff --git a/composer.json b/composer.json
index 600433b4..3a113d82 100644
--- a/composer.json
+++ b/composer.json
@@ -23,25 +23,24 @@
}
],
"require": {
- "php": "^7.1|^8",
- "symfony/finder": "^3.0|^4.0|^5.0|^6.0|^7.0",
- "symfony/event-dispatcher": "^3.0|^4.0|^5.0|^6.0|^7.0",
- "symfony/console": "^3.0|^4.0|^5.0|^6.0|^7.0",
- "symfony/polyfill-php80": "^1.20",
- "nikic/php-parser": "~4",
- "webmozart/assert": "^1.9",
+ "php": "^8",
+ "symfony/finder": "^6.0|^7.0",
+ "symfony/event-dispatcher": "^6.0|^7.0",
+ "symfony/console": "^6.0|^7.0",
+ "nikic/php-parser": "^5.4",
+ "webmozart/assert": "^1.11",
"ext-json": "*",
- "phpstan/phpdoc-parser": "^1.2",
- "ondram/ci-detector": "^4.1"
+ "phpstan/phpdoc-parser": "^2.0",
+ "ondram/ci-detector": "^4.2"
},
"require-dev": {
"roave/security-advisories": "dev-master",
- "symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0",
- "vimeo/psalm": "^4.6",
- "friendsofphp/php-cs-fixer": "^3.0",
- "phpunit/phpunit": "^7.5|^9.0|^10.0",
+ "symfony/var-dumper": "^6.0|^7.0",
+ "vimeo/psalm": "^6.0",
+ "friendsofphp/php-cs-fixer": "^3.68",
+ "phpunit/phpunit": "^10.0|^11.0",
"mikey179/vfsstream": "^1.6",
- "phpspec/prophecy": "^1.10"
+ "phpspec/prophecy": "^1.20"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index f388db62..15ed459d 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,21 +1,17 @@
-
+ cacheDirectory=".phpunit.cache">
tests
-
-
- src
-
-
+
+
+ src
+
+
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
new file mode 100644
index 00000000..3a89d93b
--- /dev/null
+++ b/psalm-baseline.xml
@@ -0,0 +1,353 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ get() ?? phpversion()]]>
+
+
+
+
+
+
+
+
+
+ class->isAnonymous()]]>
+ isSpecialClassName()]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/psalm.xml b/psalm.xml
index b6e24917..027a77ff 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -6,6 +6,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
allowStringToStandInForClass="true"
+ errorBaseline="psalm-baseline.xml"
>
diff --git a/src/Analyzer/ClassDependency.php b/src/Analyzer/ClassDependency.php
index fc5f6a22..2476249a 100644
--- a/src/Analyzer/ClassDependency.php
+++ b/src/Analyzer/ClassDependency.php
@@ -5,11 +5,9 @@
class ClassDependency
{
- /** @var int */
- private $line;
+ private int $line;
- /** @var FullyQualifiedClassName */
- private $FQCN;
+ private FullyQualifiedClassName $FQCN;
public function __construct(string $FQCN, int $line)
{
diff --git a/src/Analyzer/ClassDescription.php b/src/Analyzer/ClassDescription.php
index 2f61ff50..4f62bbb9 100644
--- a/src/Analyzer/ClassDescription.php
+++ b/src/Analyzer/ClassDescription.php
@@ -5,46 +5,37 @@
class ClassDescription
{
- /** @var FullyQualifiedClassName */
- private $FQCN;
+ private FullyQualifiedClassName $FQCN;
/** @var list */
- private $dependencies;
+ private array $dependencies;
/** @var list */
- private $interfaces;
+ private array $interfaces;
- /** @var ?FullyQualifiedClassName */
- private $extends;
+ private ?FullyQualifiedClassName $extends;
- /** @var bool */
- private $final;
+ private bool $final;
- /** @var bool */
- private $readonly;
+ private bool $readonly;
- /** @var bool */
- private $abstract;
+ private bool $abstract;
- /** @var bool */
- private $interface;
+ private bool $interface;
- /** @var bool */
- private $trait;
+ private bool $trait;
- /** @var bool */
- private $enum;
+ private bool $enum;
/** @var list */
- private $docBlock;
+ private array $docBlock;
/** @var list */
- private $attributes;
+ private array $attributes;
/**
* @param list $dependencies
* @param list $interfaces
- * @param ?FullyQualifiedClassName $extends
* @param list $attributes
*/
public function __construct(
@@ -59,7 +50,7 @@ public function __construct(
bool $trait,
bool $enum,
array $docBlock = [],
- array $attributes = []
+ array $attributes = [],
) {
$this->FQCN = $FQCN;
$this->dependencies = $dependencies;
diff --git a/src/Analyzer/ClassDescriptionBuilder.php b/src/Analyzer/ClassDescriptionBuilder.php
index 82d0a914..f3940075 100644
--- a/src/Analyzer/ClassDescriptionBuilder.php
+++ b/src/Analyzer/ClassDescriptionBuilder.php
@@ -8,40 +8,32 @@
class ClassDescriptionBuilder
{
/** @var list */
- private $classDependencies = [];
+ private array $classDependencies = [];
- /** @var ?FullyQualifiedClassName */
- private $FQCN;
+ private ?FullyQualifiedClassName $FQCN = null;
/** @var list */
- private $interfaces = [];
+ private array $interfaces = [];
- /** @var ?FullyQualifiedClassName */
- private $extend;
+ private ?FullyQualifiedClassName $extend = null;
- /** @var bool */
- private $final = false;
+ private bool $final = false;
- /** @var bool */
- private $readonly = false;
+ private bool $readonly = false;
- /** @var bool */
- private $abstract = false;
+ private bool $abstract = false;
/** @var list */
- private $docBlock = [];
+ private array $docBlock = [];
/** @var list */
- private $attributes = [];
+ private array $attributes = [];
- /** @var bool */
- private $interface = false;
+ private bool $interface = false;
- /** @var bool */
- private $trait = false;
+ private bool $trait = false;
- /** @var bool */
- private $enum = false;
+ private bool $enum = false;
public function clear(): void
{
diff --git a/src/Analyzer/FileParser.php b/src/Analyzer/FileParser.php
index 7684f306..c5b97704 100644
--- a/src/Analyzer/FileParser.php
+++ b/src/Analyzer/FileParser.php
@@ -6,39 +6,31 @@
use Arkitect\CLI\TargetPhpVersion;
use Arkitect\Rules\ParsingError;
use PhpParser\ErrorHandler\Collecting;
-use PhpParser\Lexer\Emulative;
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
+use PhpParser\PhpVersion;
class FileParser implements Parser
{
/** @var \PhpParser\Parser */
private $parser;
- /** @var NodeTraverser */
- private $traverser;
+ private NodeTraverser $traverser;
- /** @var FileVisitor */
- private $fileVisitor;
+ private FileVisitor $fileVisitor;
- /** @var array */
- private $parsingErrors;
+ private array $parsingErrors;
public function __construct(
NodeTraverser $traverser,
FileVisitor $fileVisitor,
NameResolver $nameResolver,
- TargetPhpVersion $targetPhpVersion
+ TargetPhpVersion $targetPhpVersion,
) {
$this->fileVisitor = $fileVisitor;
$this->parsingErrors = [];
- $lexer = new Emulative([
- 'usedAttributes' => ['comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos'],
- 'phpVersion' => $targetPhpVersion->get() ?? phpversion(),
- ]);
-
- $this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, $lexer);
+ $this->parser = (new ParserFactory())->createForVersion(PhpVersion::fromString($targetPhpVersion->get() ?? phpversion()));
$this->traverser = $traverser;
$this->traverser->addVisitor($nameResolver);
$this->traverser->addVisitor($this->fileVisitor);
diff --git a/src/Analyzer/FilePath.php b/src/Analyzer/FilePath.php
index 60ce3292..c5acd6c9 100644
--- a/src/Analyzer/FilePath.php
+++ b/src/Analyzer/FilePath.php
@@ -5,8 +5,7 @@
class FilePath
{
- /** @var string */
- private $path = '';
+ private string $path = '';
public function toString(): string
{
diff --git a/src/Analyzer/FileVisitor.php b/src/Analyzer/FileVisitor.php
index 35195586..4e485a0a 100644
--- a/src/Analyzer/FileVisitor.php
+++ b/src/Analyzer/FileVisitor.php
@@ -10,11 +10,9 @@
class FileVisitor extends NodeVisitorAbstract
{
- /** @var ClassDescriptionBuilder */
- private $classDescriptionBuilder;
+ private ClassDescriptionBuilder $classDescriptionBuilder;
- /** @var array */
- private $classDescriptions = [];
+ private array $classDescriptions = [];
public function __construct(ClassDescriptionBuilder $classDescriptionBuilder)
{
diff --git a/src/Analyzer/FullyQualifiedClassName.php b/src/Analyzer/FullyQualifiedClassName.php
index 590ed8ce..c0c1f4e7 100644
--- a/src/Analyzer/FullyQualifiedClassName.php
+++ b/src/Analyzer/FullyQualifiedClassName.php
@@ -7,14 +7,11 @@
class FullyQualifiedClassName
{
- /** @var PatternString */
- private $fqcnString;
+ private PatternString $fqcnString;
- /** @var PatternString */
- private $namespace;
+ private PatternString $namespace;
- /** @var PatternString */
- private $class;
+ private PatternString $class;
private function __construct(PatternString $fqcnString, PatternString $namespace, PatternString $class)
{
diff --git a/src/Analyzer/NameResolver.php b/src/Analyzer/NameResolver.php
index 47e5a49d..5e251164 100644
--- a/src/Analyzer/NameResolver.php
+++ b/src/Analyzer/NameResolver.php
@@ -23,11 +23,12 @@
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
+use PHPStan\PhpDocParser\ParserConfig;
class NameResolver extends NodeVisitorAbstract
{
/** @var NameContext Naming context */
- protected $nameContext;
+ protected NameContext $nameContext;
/** @var bool Whether to preserve original names */
protected $preserveOriginalNames;
@@ -38,11 +39,9 @@ class NameResolver extends NodeVisitorAbstract
/** @var bool Whether to parse DocBlock Custom Annotations */
protected $parseCustomAnnotations;
- /** @var PhpDocParser */
- protected $phpDocParser;
+ protected PhpDocParser $phpDocParser;
- /** @var Lexer */
- protected $phpDocLexer;
+ protected Lexer $phpDocLexer;
/**
* Constructs a name resolution visitor.
@@ -65,10 +64,11 @@ public function __construct(?ErrorHandler $errorHandler = null, array $options =
$this->replaceNodes = $options['replaceNodes'] ?? true;
$this->parseCustomAnnotations = $options['parseCustomAnnotations'] ?? true;
- $typeParser = new TypeParser();
- $constExprParser = new ConstExprParser();
- $this->phpDocParser = new PhpDocParser($typeParser, $constExprParser);
- $this->phpDocLexer = new Lexer();
+ $config = new ParserConfig(usedAttributes: ['lines' => true, 'indexes' => true]);
+ $constExprParser = new ConstExprParser($config);
+ $typeParser = new TypeParser($config, $constExprParser);
+ $this->phpDocParser = new PhpDocParser($config, $typeParser, $constExprParser);
+ $this->phpDocLexer = new Lexer($config);
}
/**
@@ -323,8 +323,7 @@ private function addAlias(Stmt\UseUse $use, int $type, ?Name $prefix = null): vo
);
}
- /** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure|Expr\ArrowFunction $node */
- private function resolveSignature($node): void
+ private function resolveSignature(Stmt\Function_|Expr\ArrowFunction|Expr\Closure|Stmt\ClassMethod $node): void
{
$phpDocNode = $this->getPhpDocNode($node);
diff --git a/src/Analyzer/PatternString.php b/src/Analyzer/PatternString.php
index 60ab84c7..67609d48 100644
--- a/src/Analyzer/PatternString.php
+++ b/src/Analyzer/PatternString.php
@@ -5,8 +5,7 @@
class PatternString
{
- /** @var string */
- private $value;
+ private string $value;
public function __construct(string $value)
{
diff --git a/src/CLI/Command/Check.php b/src/CLI/Command/Check.php
index 63534770..08620f58 100644
--- a/src/CLI/Command/Check.php
+++ b/src/CLI/Command/Check.php
@@ -125,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->printHeadingLine($output);
$rulesFilename = $this->getConfigFilename($input);
- $output->writeln(sprintf("Config file: %s\n", $rulesFilename));
+ $output->writeln(\sprintf("Config file: %s\n", $rulesFilename));
$config = new Config();
@@ -239,14 +239,14 @@ private function getConfigFilename(InputInterface $input): string
private function printViolations(Violations $violations, OutputInterface $output): void
{
$output->writeln('ERRORS!');
- $output->writeln(sprintf('%s', $violations->toString()));
- $output->writeln(sprintf('%s VIOLATIONS DETECTED!', \count($violations)));
+ $output->writeln(\sprintf('%s', $violations->toString()));
+ $output->writeln(\sprintf('%s VIOLATIONS DETECTED!', \count($violations)));
}
private function printParsedErrors(ParsingErrors $parsingErrors, OutputInterface $output): void
{
$output->writeln('ERROR ON PARSING THESE FILES:');
- $output->writeln(sprintf('%s', $parsingErrors->toString()));
+ $output->writeln(\sprintf('%s', $parsingErrors->toString()));
}
private function printNoViolationsDetectedMessage(OutputInterface $output): void
diff --git a/src/CLI/Command/DebugExpression.php b/src/CLI/Command/DebugExpression.php
index 34df2459..ecced16d 100644
--- a/src/CLI/Command/DebugExpression.php
+++ b/src/CLI/Command/DebugExpression.php
@@ -18,13 +18,13 @@ class DebugExpression extends Command
{
/** @var string|null */
public static $defaultDescription = <<< 'EOT'
-Check which classes respect an expression
-EOT;
+ Check which classes respect an expression
+ EOT;
/** @var string */
public static $help = <<< 'EOT'
-Check which classes respect an expression
-EOT;
+ Check which classes respect an expression
+ EOT;
public function __construct()
{
diff --git a/src/CLI/Command/Init.php b/src/CLI/Command/Init.php
index 215d0867..b93a9f48 100644
--- a/src/CLI/Command/Init.php
+++ b/src/CLI/Command/Init.php
@@ -13,14 +13,14 @@ class Init extends Command
{
/** @var string|null */
public static $defaultDescription = <<< 'EOT'
-Creates a new phparkitect.php file
-EOT;
+ Creates a new phparkitect.php file
+ EOT;
/** @var string */
public static $help = <<< 'EOT'
-This command creates a new phparkitect.php in the current directory
-You can customize the directory where the file is created specifying -d /dest/path
-EOT;
+ This command creates a new phparkitect.php in the current directory
+ You can customize the directory where the file is created specifying -d /dest/path
+ EOT;
public function __construct()
{
diff --git a/src/CLI/Config.php b/src/CLI/Config.php
index 039563f6..489e32d2 100644
--- a/src/CLI/Config.php
+++ b/src/CLI/Config.php
@@ -9,12 +9,9 @@
class Config
{
- /** @var array */
- private $classSetRules;
- /** @var bool */
- private $runOnlyARule;
- /** @var bool */
- private $parseCustomAnnotations;
+ private array $classSetRules;
+ private bool $runOnlyARule;
+ private bool $parseCustomAnnotations;
public function __construct()
{
diff --git a/src/CLI/PhpArkitectApplication.php b/src/CLI/PhpArkitectApplication.php
index 22ce0052..a40237d5 100644
--- a/src/CLI/PhpArkitectApplication.php
+++ b/src/CLI/PhpArkitectApplication.php
@@ -9,14 +9,13 @@
class PhpArkitectApplication extends \Symfony\Component\Console\Application
{
- /** @var string */
- private static $logo = <<< 'EOD'
- ____ _ _ ____ _ _ _ _ _
- | _ \| | | | _ \ / \ _ __| | _(_) |_ ___ ___| |_
- | |_) | |_| | |_) / _ \ | '__| |/ / | __/ _ \/ __| __|
- | __/| _ | __/ ___ \| | | <| | || __/ (__| |_
- |_| |_| |_|_| /_/ \_\_| |_|\_\_|\__\___|\___|\__|
-EOD;
+ private static string $logo = <<< 'EOD'
+ ____ _ _ ____ _ _ _ _ _
+ | _ \| | | | _ \ / \ _ __| | _(_) |_ ___ ___| |_
+ | |_) | |_| | |_) / _ \ | '__| |/ / | __/ _ \/ __| __|
+ | __/| _ | __/ ___ \| | | <| | || __/ (__| |_
+ |_| |_| |_|_| /_/ \_\_| |_|\_\_|\__\___|\___|\__|
+ EOD;
public function __construct()
{
@@ -28,6 +27,6 @@ public function __construct()
public function getLongVersion(): string
{
- return sprintf("%s\n\n%s version %s", self::$logo, $this->getName(), $this->getVersion());
+ return \sprintf("%s\n\n%s version %s", self::$logo, $this->getName(), $this->getVersion());
}
}
diff --git a/src/CLI/Progress/DebugProgress.php b/src/CLI/Progress/DebugProgress.php
index 284547a9..c4483414 100644
--- a/src/CLI/Progress/DebugProgress.php
+++ b/src/CLI/Progress/DebugProgress.php
@@ -8,7 +8,7 @@
class DebugProgress implements Progress
{
- private $output;
+ private OutputInterface $output;
public function __construct(OutputInterface $output)
{
diff --git a/src/CLI/Progress/ProgressBarProgress.php b/src/CLI/Progress/ProgressBarProgress.php
index 39c5a871..ceb01bd6 100644
--- a/src/CLI/Progress/ProgressBarProgress.php
+++ b/src/CLI/Progress/ProgressBarProgress.php
@@ -15,11 +15,9 @@
*/
class ProgressBarProgress implements Progress
{
- /** @var OutputInterface */
- private $output;
+ private OutputInterface $output;
- /** @var ProgressBar */
- private $progress;
+ private ProgressBar $progress;
public function __construct(OutputInterface $output)
{
diff --git a/src/CLI/Runner.php b/src/CLI/Runner.php
index 7987c138..d5c927b3 100644
--- a/src/CLI/Runner.php
+++ b/src/CLI/Runner.php
@@ -16,11 +16,9 @@
class Runner
{
- /** @var Violations */
- private $violations;
+ private Violations $violations;
- /** @var ParsingErrors */
- private $parsingErrors;
+ private ParsingErrors $parsingErrors;
public function __construct(bool $stopOnFailure = false)
{
@@ -48,7 +46,7 @@ public function check(
Progress $progress,
Parser $fileParser,
Violations $violations,
- ParsingErrors $parsingErrors
+ ParsingErrors $parsingErrors,
): void {
/** @var SplFileInfo $file */
foreach ($classSetRule->getClassSet() as $file) {
diff --git a/src/CLI/TargetPhpVersion.php b/src/CLI/TargetPhpVersion.php
index 9c33f795..c3f6f0b3 100644
--- a/src/CLI/TargetPhpVersion.php
+++ b/src/CLI/TargetPhpVersion.php
@@ -9,18 +9,13 @@
class TargetPhpVersion
{
public const VALID_PHP_VERSIONS = [
- '7.1',
- '7.2',
- '7.3',
- '7.4',
- '8.0',
'8.1',
'8.2',
'8.3',
+ '8.4',
];
- /** @var string|null */
- private $version;
+ private string $version;
private function __construct(string $version)
{
diff --git a/src/ClassSet.php b/src/ClassSet.php
index 519a8953..93d6bffe 100644
--- a/src/ClassSet.php
+++ b/src/ClassSet.php
@@ -7,11 +7,9 @@
class ClassSet implements \IteratorAggregate
{
- /** @var string */
- private $directory;
+ private string $directory;
- /** @var array */
- private $exclude;
+ private array $exclude;
private function __construct(string $directory)
{
diff --git a/src/ClassSetRules.php b/src/ClassSetRules.php
index 7928b82a..86eb85c4 100644
--- a/src/ClassSetRules.php
+++ b/src/ClassSetRules.php
@@ -8,12 +8,11 @@
class ClassSetRules
{
- /** @var ClassSet */
- private $classSet;
+ private ClassSet $classSet;
/**
* @var ArchRule[]
*/
- private $rules;
+ private array $rules;
private function __construct(ClassSet $classSet, ArchRule ...$rules)
{
diff --git a/src/Exceptions/IndexNotFoundException.php b/src/Exceptions/IndexNotFoundException.php
index e7b0e927..0a643a41 100644
--- a/src/Exceptions/IndexNotFoundException.php
+++ b/src/Exceptions/IndexNotFoundException.php
@@ -7,6 +7,6 @@ class IndexNotFoundException extends \Exception
{
public function __construct(int $index)
{
- parent::__construct(sprintf('Index not found %d', $index));
+ parent::__construct(\sprintf('Index not found %d', $index));
}
}
diff --git a/src/Exceptions/PhpVersionNotValidException.php b/src/Exceptions/PhpVersionNotValidException.php
index bdbefbc3..4f3f7348 100644
--- a/src/Exceptions/PhpVersionNotValidException.php
+++ b/src/Exceptions/PhpVersionNotValidException.php
@@ -7,6 +7,6 @@ class PhpVersionNotValidException extends \Exception
{
public function __construct(string $phpVersion)
{
- parent::__construct(sprintf('PHP version not valid for PHPArkitect parser %s', $phpVersion));
+ parent::__construct(\sprintf('PHP version not valid for PHPArkitect parser %s', $phpVersion));
}
}
diff --git a/src/Expression/Description.php b/src/Expression/Description.php
index 5d81b210..177787e1 100644
--- a/src/Expression/Description.php
+++ b/src/Expression/Description.php
@@ -6,8 +6,7 @@
class Description
{
- /** @var string */
- private $description;
+ private string $description;
public function __construct(string $description, string $because)
{
diff --git a/src/Expression/ForClasses/ContainDocBlockLike.php b/src/Expression/ForClasses/ContainDocBlockLike.php
index 08d49a92..f4729dfe 100644
--- a/src/Expression/ForClasses/ContainDocBlockLike.php
+++ b/src/Expression/ForClasses/ContainDocBlockLike.php
@@ -13,8 +13,7 @@
class ContainDocBlockLike implements Expression
{
- /** @var string */
- private $docBlock;
+ private string $docBlock;
public function __construct(string $docBlock)
{
diff --git a/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php b/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php
index 55a346f3..b082d5ce 100644
--- a/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php
+++ b/src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php
@@ -15,7 +15,7 @@
class DependsOnlyOnTheseNamespaces implements Expression
{
/** @var string[] */
- private $namespaces;
+ private array $namespaces;
public function __construct(string ...$namespace)
{
diff --git a/src/Expression/ForClasses/Extend.php b/src/Expression/ForClasses/Extend.php
index c9434a08..4f12c5c5 100644
--- a/src/Expression/ForClasses/Extend.php
+++ b/src/Expression/ForClasses/Extend.php
@@ -14,7 +14,7 @@
class Extend implements Expression
{
/** @var string[] */
- private $classNames;
+ private array $classNames;
public function __construct(string ...$classNames)
{
diff --git a/src/Expression/ForClasses/HaveAttribute.php b/src/Expression/ForClasses/HaveAttribute.php
index 8a542fdf..8caf398d 100644
--- a/src/Expression/ForClasses/HaveAttribute.php
+++ b/src/Expression/ForClasses/HaveAttribute.php
@@ -12,8 +12,7 @@
final class HaveAttribute implements Expression
{
- /** @var string */
- private $attribute;
+ private string $attribute;
public function __construct(string $attribute)
{
diff --git a/src/Expression/ForClasses/HaveNameMatching.php b/src/Expression/ForClasses/HaveNameMatching.php
index 858c3928..04b12eea 100644
--- a/src/Expression/ForClasses/HaveNameMatching.php
+++ b/src/Expression/ForClasses/HaveNameMatching.php
@@ -14,8 +14,7 @@
class HaveNameMatching implements Expression
{
- /** @var string */
- private $name;
+ private string $name;
public function __construct(string $name)
{
diff --git a/src/Expression/ForClasses/Implement.php b/src/Expression/ForClasses/Implement.php
index b097a865..b72ae419 100644
--- a/src/Expression/ForClasses/Implement.php
+++ b/src/Expression/ForClasses/Implement.php
@@ -14,8 +14,7 @@
class Implement implements Expression
{
- /** @var string */
- private $interface;
+ private string $interface;
public function __construct(string $interface)
{
diff --git a/src/Expression/ForClasses/MatchOneOfTheseNames.php b/src/Expression/ForClasses/MatchOneOfTheseNames.php
index 351782dc..189bea0c 100644
--- a/src/Expression/ForClasses/MatchOneOfTheseNames.php
+++ b/src/Expression/ForClasses/MatchOneOfTheseNames.php
@@ -15,7 +15,7 @@
class MatchOneOfTheseNames implements Expression
{
/** @var array */
- private $names;
+ private array $names;
public function __construct(array $names)
{
diff --git a/src/Expression/ForClasses/NotContainDocBlockLike.php b/src/Expression/ForClasses/NotContainDocBlockLike.php
index 164f6a66..b6878a14 100644
--- a/src/Expression/ForClasses/NotContainDocBlockLike.php
+++ b/src/Expression/ForClasses/NotContainDocBlockLike.php
@@ -13,8 +13,7 @@
class NotContainDocBlockLike implements Expression
{
- /** @var string */
- private $docBlock;
+ private string $docBlock;
public function __construct(string $docBlock)
{
diff --git a/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php b/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php
index eb5c73a9..f7052a3a 100644
--- a/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php
+++ b/src/Expression/ForClasses/NotDependsOnTheseNamespaces.php
@@ -15,7 +15,7 @@
class NotDependsOnTheseNamespaces implements Expression
{
/** @var string[] */
- private $namespaces;
+ private array $namespaces;
public function __construct(string ...$namespace)
{
diff --git a/src/Expression/ForClasses/NotExtend.php b/src/Expression/ForClasses/NotExtend.php
index 49177500..7c1d7660 100644
--- a/src/Expression/ForClasses/NotExtend.php
+++ b/src/Expression/ForClasses/NotExtend.php
@@ -14,7 +14,7 @@
class NotExtend implements Expression
{
/** @var string[] */
- private $classNames;
+ private array $classNames;
public function __construct(string ...$classNames)
{
diff --git a/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php b/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php
index 906131ee..64b5f1fd 100644
--- a/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php
+++ b/src/Expression/ForClasses/NotHaveDependencyOutsideNamespace.php
@@ -14,12 +14,9 @@
class NotHaveDependencyOutsideNamespace implements Expression
{
- /** @var string */
- private $namespace;
- /** @var array */
- private $externalDependenciesToExclude;
- /** @var bool */
- private $excludeCoreNamespace;
+ private string $namespace;
+ private array $externalDependenciesToExclude;
+ private bool $excludeCoreNamespace;
public function __construct(string $namespace, array $externalDependenciesToExclude = [], bool $excludeCoreNamespace = false)
{
diff --git a/src/Expression/ForClasses/NotHaveNameMatching.php b/src/Expression/ForClasses/NotHaveNameMatching.php
index 05b80f01..a0761eb6 100644
--- a/src/Expression/ForClasses/NotHaveNameMatching.php
+++ b/src/Expression/ForClasses/NotHaveNameMatching.php
@@ -14,8 +14,7 @@
class NotHaveNameMatching implements Expression
{
- /** @var string */
- private $name;
+ private string $name;
public function __construct(string $name)
{
diff --git a/src/Expression/ForClasses/NotImplement.php b/src/Expression/ForClasses/NotImplement.php
index e01a51bf..cad270bb 100644
--- a/src/Expression/ForClasses/NotImplement.php
+++ b/src/Expression/ForClasses/NotImplement.php
@@ -14,8 +14,7 @@
class NotImplement implements Expression
{
- /** @var string */
- private $interface;
+ private string $interface;
public function __construct(string $interface)
{
diff --git a/src/Expression/ForClasses/NotResideInTheseNamespaces.php b/src/Expression/ForClasses/NotResideInTheseNamespaces.php
index 23949ff3..4d778461 100644
--- a/src/Expression/ForClasses/NotResideInTheseNamespaces.php
+++ b/src/Expression/ForClasses/NotResideInTheseNamespaces.php
@@ -14,7 +14,7 @@
class NotResideInTheseNamespaces implements Expression
{
/** @var string[] */
- private $namespaces;
+ private array $namespaces;
public function __construct(string ...$namespaces)
{
diff --git a/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php b/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php
index fd468933..786d81c9 100644
--- a/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php
+++ b/src/PHPUnit/ArchRuleCheckerConstraintAdapter.php
@@ -17,20 +17,15 @@
class ArchRuleCheckerConstraintAdapter extends Constraint
{
- /** @var ClassSet */
- private $classSet;
+ private ClassSet $classSet;
- /** @var Violations */
- private $violations;
+ private Violations $violations;
- /** @var Runner */
- private $runner;
+ private Runner $runner;
- /** @var FileParser */
- private $fileparser;
+ private FileParser $fileparser;
- /** @var ParsingErrors */
- private $parsingErrors;
+ private ParsingErrors $parsingErrors;
public function __construct(ClassSet $classSet)
{
diff --git a/src/RuleBuilders/Architecture/Architecture.php b/src/RuleBuilders/Architecture/Architecture.php
index 4a0714c2..6894a077 100644
--- a/src/RuleBuilders/Architecture/Architecture.php
+++ b/src/RuleBuilders/Architecture/Architecture.php
@@ -10,14 +10,13 @@
class Architecture implements Component, DefinedBy, Where, MayDependOnComponents, MayDependOnAnyComponent, ShouldNotDependOnAnyComponent, ShouldOnlyDependOnComponents, Rules
{
- /** @var string */
- private $componentName;
+ private string $componentName;
/** @var array */
- private $componentSelectors;
+ private array $componentSelectors;
/** @var array */
- private $allowedDependencies;
+ private array $allowedDependencies;
/** @var array */
- private $componentDependsOnlyOnTheseNamespaces;
+ private array $componentDependsOnlyOnTheseNamespaces;
private function __construct()
{
@@ -39,42 +38,42 @@ public function component(string $name): DefinedBy
return $this;
}
- public function definedBy(string $selector)
+ public function definedBy(string $selector): static
{
$this->componentSelectors[$this->componentName] = $selector;
return $this;
}
- public function where(string $componentName)
+ public function where(string $componentName): static
{
$this->componentName = $componentName;
return $this;
}
- public function shouldNotDependOnAnyComponent()
+ public function shouldNotDependOnAnyComponent(): static
{
$this->allowedDependencies[$this->componentName] = [];
return $this;
}
- public function shouldOnlyDependOnComponents(string ...$componentNames)
+ public function shouldOnlyDependOnComponents(string ...$componentNames): static
{
$this->componentDependsOnlyOnTheseNamespaces[$this->componentName] = $componentNames;
return $this;
}
- public function mayDependOnComponents(string ...$componentNames)
+ public function mayDependOnComponents(string ...$componentNames): static
{
$this->allowedDependencies[$this->componentName] = $componentNames;
return $this;
}
- public function mayDependOnAnyComponent()
+ public function mayDependOnAnyComponent(): static
{
$this->allowedDependencies[$this->componentName] = array_keys($this->componentSelectors);
diff --git a/src/Rules/AllClasses.php b/src/Rules/AllClasses.php
index 95910572..55d40bad 100644
--- a/src/Rules/AllClasses.php
+++ b/src/Rules/AllClasses.php
@@ -9,8 +9,7 @@
class AllClasses implements ThatParser
{
- /** @var RuleBuilder */
- protected $ruleBuilder;
+ protected RuleBuilder $ruleBuilder;
public function __construct()
{
diff --git a/src/Rules/AndThatShould.php b/src/Rules/AndThatShould.php
index c6848f53..28bbbe41 100644
--- a/src/Rules/AndThatShould.php
+++ b/src/Rules/AndThatShould.php
@@ -9,8 +9,7 @@
class AndThatShould implements AndThatShouldParser
{
- /** @var RuleBuilder */
- private $ruleBuilder;
+ private RuleBuilder $ruleBuilder;
public function __construct(RuleBuilder $expressionBuilder)
{
diff --git a/src/Rules/ArchRule.php b/src/Rules/ArchRule.php
index 2909d417..68c05e87 100644
--- a/src/Rules/ArchRule.php
+++ b/src/Rules/ArchRule.php
@@ -7,27 +7,22 @@
class ArchRule implements DSL\ArchRule
{
- /** @var Specs */
- private $thats;
+ private Specs $thats;
- /** @var Constraints */
- private $shoulds;
+ private Constraints $shoulds;
- /** @var string */
- private $because;
+ private string $because;
- /** @var array */
- private $classesToBeExcluded;
+ private array $classesToBeExcluded;
- /** @var bool */
- private $runOnlyThis;
+ private bool $runOnlyThis;
public function __construct(
Specs $specs,
Constraints $constraints,
string $because,
array $classesToBeExcluded,
- bool $runOnlyThis
+ bool $runOnlyThis,
) {
$this->thats = $specs;
$this->shoulds = $constraints;
diff --git a/src/Rules/Because.php b/src/Rules/Because.php
index 539ac97a..cc14c1d1 100644
--- a/src/Rules/Because.php
+++ b/src/Rules/Because.php
@@ -9,8 +9,7 @@
class Because implements BecauseParser
{
- /** @var RuleBuilder */
- private $ruleBuilder;
+ private RuleBuilder $ruleBuilder;
public function __construct(RuleBuilder $expressionBuilder)
{
diff --git a/src/Rules/Constraints.php b/src/Rules/Constraints.php
index 1b4bc8a4..eb268d54 100644
--- a/src/Rules/Constraints.php
+++ b/src/Rules/Constraints.php
@@ -8,8 +8,7 @@
class Constraints
{
- /** @var array */
- private $expressions = [];
+ private array $expressions = [];
public function add(Expression $expression): void
{
diff --git a/src/Rules/ParsingError.php b/src/Rules/ParsingError.php
index 089bf068..f2f169cc 100644
--- a/src/Rules/ParsingError.php
+++ b/src/Rules/ParsingError.php
@@ -6,11 +6,9 @@
class ParsingError
{
- /** @var string */
- private $relativeFilePath;
+ private string $relativeFilePath;
- /** @var string */
- private $error;
+ private string $error;
public function __construct(string $relativeFilePath, string $error)
{
diff --git a/src/Rules/ParsingErrors.php b/src/Rules/ParsingErrors.php
index 007ce001..12ed6b59 100644
--- a/src/Rules/ParsingErrors.php
+++ b/src/Rules/ParsingErrors.php
@@ -10,7 +10,7 @@ class ParsingErrors implements \IteratorAggregate, \Countable
/**
* @var ParsingError[]
*/
- private $parsingErrors;
+ private array $parsingErrors;
public function __construct(array $parsingErrors = [])
{
diff --git a/src/Rules/RuleBuilder.php b/src/Rules/RuleBuilder.php
index e6f12bf2..1d7e749b 100644
--- a/src/Rules/RuleBuilder.php
+++ b/src/Rules/RuleBuilder.php
@@ -7,19 +7,14 @@
class RuleBuilder
{
- /** @var Specs */
- private $thats;
+ private Specs $thats;
- /** @var Constraints */
- private $shoulds;
+ private Constraints $shoulds;
- /** @var string */
- private $because;
+ private string $because;
- /** @var array */
- private $classesToBeExcluded;
- /** @var bool */
- private $runOnlyThis;
+ private array $classesToBeExcluded;
+ private bool $runOnlyThis;
public function __construct()
{
diff --git a/src/Rules/Specs.php b/src/Rules/Specs.php
index c131d78f..55e99039 100644
--- a/src/Rules/Specs.php
+++ b/src/Rules/Specs.php
@@ -8,8 +8,7 @@
class Specs
{
- /** @var array */
- private $expressions = [];
+ private array $expressions = [];
public function add(Expression $expression): void
{
diff --git a/src/Rules/Violation.php b/src/Rules/Violation.php
index dd1bfb8f..3f149390 100644
--- a/src/Rules/Violation.php
+++ b/src/Rules/Violation.php
@@ -6,14 +6,11 @@
class Violation implements \JsonSerializable
{
- /** @var string */
- private $fqcn;
+ private string $fqcn;
- /** @var int|null */
- private $line;
+ private ?int $line;
- /** @var string */
- private $error;
+ private string $error;
public function __construct(string $fqcn, string $error, ?int $line = null)
{
diff --git a/src/Rules/ViolationMessage.php b/src/Rules/ViolationMessage.php
index eb794046..f2209d81 100644
--- a/src/Rules/ViolationMessage.php
+++ b/src/Rules/ViolationMessage.php
@@ -8,10 +8,8 @@
class ViolationMessage
{
- /** @var string */
- private $rule;
- /** @var string|null */
- private $violation;
+ private string $rule;
+ private ?string $violation;
private function __construct(string $rule, ?string $violation)
{
diff --git a/src/Rules/Violations.php b/src/Rules/Violations.php
index 48c24879..9df8f65f 100644
--- a/src/Rules/Violations.php
+++ b/src/Rules/Violations.php
@@ -13,10 +13,7 @@ class Violations implements \IteratorAggregate, \Countable, \JsonSerializable
* @var Violation[]
*/
private $violations;
- /**
- * @var bool
- */
- private $stopOnFailure;
+ private bool $stopOnFailure;
public function __construct(bool $stopOnFailure = false)
{
diff --git a/tests/E2E/Cli/CheckCommandTest.php b/tests/E2E/Cli/CheckCommandTest.php
index 136d44c5..1b760425 100644
--- a/tests/E2E/Cli/CheckCommandTest.php
+++ b/tests/E2E/Cli/CheckCommandTest.php
@@ -165,7 +165,7 @@ protected function runCheck(
?string $useBaseline = null,
$generateBaseline = false,
bool $skipBaseline = false,
- bool $ignoreBaselineNumbers = false
+ bool $ignoreBaselineNumbers = false,
): ApplicationTester {
$input = ['check'];
if (null !== $configFilePath) {
diff --git a/tests/E2E/Cli/DebugExpressionCommandTest.php b/tests/E2E/Cli/DebugExpressionCommandTest.php
index 4fa0aee0..f56504ff 100644
--- a/tests/E2E/Cli/DebugExpressionCommandTest.php
+++ b/tests/E2E/Cli/DebugExpressionCommandTest.php
@@ -70,13 +70,13 @@ public function test_parse_error_dont_stop_execution(): void
$appTester = $this->createAppTester();
$appTester->run(['debug:expression', 'expression' => 'NotExtend', 'arguments' => ['NotFound'], '--from-dir' => __DIR__.'/../_fixtures/parse_error']);
$errorMessage = <<assertEquals($errorMessage, $appTester->getDisplay());
$this->assertEquals(0, $appTester->getStatusCode());
}
diff --git a/tests/E2E/Cli/InitCommandTest.php b/tests/E2E/Cli/InitCommandTest.php
index 947c5e75..0cabd083 100644
--- a/tests/E2E/Cli/InitCommandTest.php
+++ b/tests/E2E/Cli/InitCommandTest.php
@@ -65,7 +65,7 @@ public function test_do_nothing_if_file_exists(): void
public function test_returns_error_if_directory_is_not_writable(): void
{
- $fs = vfsStream::setup('root', 0000)->url();
+ $fs = vfsStream::setup('root', 0o000)->url();
$appTester = $this->runInit($fs);
diff --git a/tests/Unit/Analyzer/ClassDependencyTest.php b/tests/Unit/Analyzer/ClassDependencyTest.php
index e9ae03e9..389f0b90 100644
--- a/tests/Unit/Analyzer/ClassDependencyTest.php
+++ b/tests/Unit/Analyzer/ClassDependencyTest.php
@@ -10,9 +10,9 @@
class ClassDependencyTest extends TestCase
{
- private $FQCN;
- private $line;
- private $classDependency;
+ private string $FQCN;
+ private int $line;
+ private ClassDependency $classDependency;
protected function setUp(): void
{
diff --git a/tests/Unit/Analyzer/ClassDescriptionTest.php b/tests/Unit/Analyzer/ClassDescriptionTest.php
index 4726d027..45e6f150 100644
--- a/tests/Unit/Analyzer/ClassDescriptionTest.php
+++ b/tests/Unit/Analyzer/ClassDescriptionTest.php
@@ -10,8 +10,7 @@
class ClassDescriptionTest extends TestCase
{
- /** @var ClassDescriptionBuilder */
- private $builder;
+ private ClassDescriptionBuilder $builder;
protected function setUp(): void
{
diff --git a/tests/Unit/Analyzer/FileParserTest.php b/tests/Unit/Analyzer/FileParserTest.php
index 52dd2ca5..304de3d9 100644
--- a/tests/Unit/Analyzer/FileParserTest.php
+++ b/tests/Unit/Analyzer/FileParserTest.php
@@ -11,14 +11,16 @@
use PhpParser\NodeTraverser;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
+use Prophecy\Prophet;
class FileParserTest extends TestCase
{
public function test_parse_file(): void
{
- $traverser = $this->prophesize(NodeTraverser::class);
- $fileVisitor = $this->prophesize(FileVisitor::class);
- $nameResolver = $this->prophesize(NameResolver::class);
+ $prophet = new Prophet();
+ $traverser = $prophet->prophesize(NodeTraverser::class);
+ $fileVisitor = $prophet->prophesize(FileVisitor::class);
+ $nameResolver = $prophet->prophesize(NameResolver::class);
$traverser->addVisitor($nameResolver);
$traverser->addVisitor($fileVisitor);
@@ -29,7 +31,7 @@ public function test_parse_file(): void
$traverser->reveal(),
$fileVisitor->reveal(),
$nameResolver->reveal(),
- TargetPhpVersion::create('7.4')
+ TargetPhpVersion::create('8.1')
);
$content = 'traverse(Argument::type('array'))->shouldBeCalled();
$fileParser->parse($content, 'foo');
- }
-
- /**
- * @requires PHP < 8.0
- */
- public function test_parse_file_with_name_match(): void
- {
- $traverser = $this->prophesize(NodeTraverser::class);
- $fileVisitor = $this->prophesize(FileVisitor::class);
- $nameResolver = $this->prophesize(NameResolver::class);
-
- $traverser->addVisitor($nameResolver);
- $traverser->addVisitor($fileVisitor);
-
- $fileVisitor->clearParsedClassDescriptions()->shouldBeCalled();
- $fileParser = new FileParser(
- $traverser->reveal(),
- $fileVisitor->reveal(),
- $nameResolver->reveal(),
- TargetPhpVersion::create('7.4')
- );
-
- $content = 'traverse(Argument::type('array'))->shouldBeCalled();
- $fileParser->parse($content, 'foo');
+ $this->expectNotToPerformAssertions();
}
}
diff --git a/tests/Unit/Analyzer/FileVisitorTest.php b/tests/Unit/Analyzer/FileVisitorTest.php
index 40f92ac0..960cb255 100644
--- a/tests/Unit/Analyzer/FileVisitorTest.php
+++ b/tests/Unit/Analyzer/FileVisitorTest.php
@@ -22,24 +22,24 @@ class FileVisitorTest extends TestCase
public function test_should_create_a_class_description(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -51,40 +51,40 @@ class Cat implements AnInterface
public function test_should_create_a_class_description_and_parse_anonymous_class(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -105,22 +105,22 @@ class Cat implements AnInterface
public function test_it_should_parse_extends_class(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions()[1];
@@ -131,25 +131,25 @@ class Cat extends Animal
public function test_it_should_not_parse_extends_from_insider_anonymousclass(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions()[1];
@@ -160,24 +160,24 @@ public function methodWithAnonymous(): void
public function test_should_depends_on_these_namespaces(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -192,27 +192,27 @@ public function __construct(Request $request)
public function test_should_returns_all_dependencies(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -233,22 +233,22 @@ public function __construct(Request $request, ?Nullable $nullable)
public function test_it_should_parse_arrow_function(): void
{
$code = <<< 'EOF'
- $x + $y;
- }
-}
-EOF;
+ class Animal
+ {
+ public function __construct()
+ {
+ $y = 1;
+ $fn1 = fn($x) => $x + $y;
+ }
+ }
+ EOF;
/** @var FileParser $fp */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.4'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -264,21 +264,21 @@ public function __construct()
public function test_it_should_catch_parsing_errors(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$parsingErrors = $fp->getParsingErrors();
@@ -290,25 +290,25 @@ public function __construct()
public function test_null_class_description_builder(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$violations = new Violations();
@@ -319,29 +319,29 @@ public function save(Quote $quote): void;
public function test_it_should_parse_self_correctly(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -357,24 +357,24 @@ public function doSomething(self $self, static $static)
public function test_it_should_return_errors_for_class_outside_namespace(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -393,16 +393,16 @@ public function foo()
public function test_should_parse_class_attributes(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -418,30 +418,30 @@ class Foo {}
public function test_it_should_return_errors_for_const_outside_namespace(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -457,16 +457,16 @@ public function getStatic(): self
public function test_it_can_parse_enum(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
@@ -519,23 +519,23 @@ enum Enum
public function test_it_parse_docblocks(): void
{
$code = <<< 'EOF'
-
-*/
- public $baz;
-}
-EOF;
+
+ */
+ public $baz;
+ }
+ EOF;
/** @var FileParser $fp */
$fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
@@ -709,18 +709,18 @@ class ApplicationLevelDto
public function test_it_parse_custom_tags_in_docblocks(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -862,17 +862,17 @@ public function getRequest(): Request //the violations is reported here
public function test_it_skip_custom_annotations_in_docblocks_if_the_option_parse_custom_annotation_is_false(): void
{
$code = <<< 'EOF'
-field1 = $field1;
- }
-}
-EOF;
+ field1 = $field1;
+ }
+ }
+ EOF;
/** @var FileParser $fp */
$fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
@@ -920,22 +920,22 @@ public function __construct(array $field1)
public function test_it_handles_typed_arrays_in_properties_with_generics_syntax(): void
{
$code = <<< 'EOF'
-
- */
- private array $dtoList;
-}
-EOF;
+ class MyClass
+ {
+ /**
+ * @var array
+ */
+ private array $dtoList;
+ }
+ EOF;
/** @noinspection PhpUnhandledExceptionInspection */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -950,22 +950,22 @@ class MyClass
public function test_it_handles_typed_arrays_in_properties_with_list_syntax(): void
{
$code = <<< 'EOF'
-
- */
- private array $dtoList;
-}
-EOF;
+ class MyClass
+ {
+ /**
+ * @var list
+ */
+ private array $dtoList;
+ }
+ EOF;
/** @noinspection PhpUnhandledExceptionInspection */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -980,22 +980,22 @@ class MyClass
public function test_it_handles_typed_arrays_in_properties_with_legacy_syntax(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1010,24 +1010,24 @@ class MyClass
public function test_it_handles_typed_arrays_in_method_params_with_generics_syntax(): void
{
$code = <<< 'EOF'
- $dtoList
- */
- public function __construct(array $dtoList)
- {
- }
-}
-EOF;
+ class MyClass
+ {
+ /**
+ * @param array $dtoList
+ */
+ public function __construct(array $dtoList)
+ {
+ }
+ }
+ EOF;
/** @noinspection PhpUnhandledExceptionInspection */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1042,24 +1042,24 @@ public function __construct(array $dtoList)
public function test_it_handles_typed_arrays_in_method_params_with_list_syntax(): void
{
$code = <<< 'EOF'
- $dtoList
- */
- public function __construct(array $dtoList)
- {
- }
-}
-EOF;
+ class MyClass
+ {
+ /**
+ * @param list $dtoList
+ */
+ public function __construct(array $dtoList)
+ {
+ }
+ }
+ EOF;
/** @noinspection PhpUnhandledExceptionInspection */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1074,24 +1074,24 @@ public function __construct(array $dtoList)
public function test_it_handles_typed_arrays_in_method_params_with_legacy_syntax(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1106,27 +1106,27 @@ public function __construct(array $dtoList)
public function test_it_handles_typed_arrays_in_method_params_with_multiple_params(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1141,25 +1141,25 @@ public function __construct(string $var1, array $dtoList, $var2, array $voList)
public function test_it_handles_typed_arrays_in_return_type_with_generics_syntax(): void
{
$code = <<< 'EOF'
-
- */
- public function getList(): array
- {
- return [];
- }
-}
-EOF;
+ class MyClass
+ {
+ /**
+ * @return array
+ */
+ public function getList(): array
+ {
+ return [];
+ }
+ }
+ EOF;
/** @noinspection PhpUnhandledExceptionInspection */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1174,25 +1174,25 @@ public function getList(): array
public function test_it_handles_typed_arrays_in_return_type_with_list_syntax(): void
{
$code = <<< 'EOF'
-
- */
- public function getList(): array
- {
- return [];
- }
-}
-EOF;
+ class MyClass
+ {
+ /**
+ * @return list
+ */
+ public function getList(): array
+ {
+ return [];
+ }
+ }
+ EOF;
/** @noinspection PhpUnhandledExceptionInspection */
- $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('7.1'));
+ $fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1207,25 +1207,25 @@ public function getList(): array
public function test_it_handles_typed_arrays_in_return_type_with_legacy_syntax(): void
{
$code = <<< 'EOF'
-parse($code, 'relativePathName');
$cd = $fp->getClassDescriptions();
@@ -1240,17 +1240,17 @@ public function getList(): array
public function test_it_parse_traits(): void
{
$code = <<< 'EOF'
- [
<<< 'EOF'
- [
<<< 'EOF'
- [
<<< 'EOF'
- [
<<< 'EOF'
-prophesize(OutputInterface::class);
+ $prophet = new Prophet();
+ $output = $prophet->prophesize(OutputInterface::class);
$debugProgress = new DebugProgress($output->reveal());
$output->writeln('parsing filename')->shouldBeCalled();
$debugProgress->startParsingFile('filename');
+
+ $this->expectNotToPerformAssertions();
}
public function test_it_should_generate_text_on_start_file_set_analysis(): void
{
- $output = $this->prophesize(OutputInterface::class);
+ $prophet = new Prophet();
+ $output = $prophet->prophesize(OutputInterface::class);
$debugProgress = new DebugProgress($output->reveal());
$output->writeln('Start analyze dir directory')->shouldBeCalled();
$debugProgress->startFileSetAnalysis(ClassSet::fromDir('directory'));
+
+ $this->expectNotToPerformAssertions();
}
public function test_it_should_not_generate_text_on_end_parsing_file(): void
{
- $output = $this->prophesize(OutputInterface::class);
+ $prophet = new Prophet();
+ $output = $prophet->prophesize(OutputInterface::class);
$debugProgress = new DebugProgress($output->reveal());
$output->writeln()->shouldNotBeCalled();
$debugProgress->endParsingFile('filename');
+
+ $this->expectNotToPerformAssertions();
}
public function test_it_should_not_generate_text_on_end_file_set_analysis(): void
{
- $output = $this->prophesize(OutputInterface::class);
+ $prophet = new Prophet();
+ $output = $prophet->prophesize(OutputInterface::class);
$debugProgress = new DebugProgress($output->reveal());
$output->writeln()->shouldNotBeCalled();
$debugProgress->endFileSetAnalysis(ClassSet::fromDir('directory'));
+
+ $this->expectNotToPerformAssertions();
}
}
diff --git a/tests/Unit/CLI/TargetPhpVersionTest.php b/tests/Unit/CLI/TargetPhpVersionTest.php
index ce0813a4..b10a5093 100644
--- a/tests/Unit/CLI/TargetPhpVersionTest.php
+++ b/tests/Unit/CLI/TargetPhpVersionTest.php
@@ -12,9 +12,9 @@ class TargetPhpVersionTest extends TestCase
{
public function test_it_should_return_passed_php_version(): void
{
- $targetPhpVersion = TargetPhpVersion::create('8.3');
+ $targetPhpVersion = TargetPhpVersion::create('8.4');
- $this->assertEquals('8.3', $targetPhpVersion->get());
+ $this->assertEquals('8.4', $targetPhpVersion->get());
}
public function test_it_should_ignore_the_patch_number(): void
@@ -26,9 +26,9 @@ public function test_it_should_ignore_the_patch_number(): void
public function test_it_should_ignore_extra_informations(): void
{
- $targetPhpVersion = TargetPhpVersion::create('7.3.33-14+ubuntu22.04.1+deb.sury.org+1');
+ $targetPhpVersion = TargetPhpVersion::create('8.1.33-14+ubuntu22.04.1+deb.sury.org+1');
- $this->assertEquals('7.3', $targetPhpVersion->get());
+ $this->assertEquals('8.1', $targetPhpVersion->get());
}
public function test_it_should_throw_exception_if_not_valid_php_version(): void
diff --git a/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php b/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php
index 4f8dce9e..cb95d377 100644
--- a/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php
+++ b/tests/Unit/Expressions/ForClasses/ResideInOneOfTheseNamespacesTest.php
@@ -11,7 +11,7 @@
class ResideInOneOfTheseNamespacesTest extends TestCase
{
- public function shouldMatchNamespacesProvider(): array
+ public static function shouldMatchNamespacesProvider(): array
{
return [
['Food\Vegetables', 'Food\Vegetables\Carrot', 'matches a class in the root namespace'],
@@ -30,12 +30,8 @@ public function shouldMatchNamespacesProvider(): array
/**
* @dataProvider shouldMatchNamespacesProvider
- *
- * @param mixed $expectedNamespace
- * @param mixed $actualFQCN
- * @param mixed $explanation
*/
- public function test_it_should_match_namespace_and_descendants($expectedNamespace, $actualFQCN, $explanation): void
+ public function test_it_should_match_namespace_and_descendants(string $expectedNamespace, string $actualFQCN, string $explanation): void
{
$haveNameMatching = new ResideInOneOfTheseNamespaces($expectedNamespace);
diff --git a/tests/Unit/Rules/ConstraintsTest.php b/tests/Unit/Rules/ConstraintsTest.php
index 53530d12..65c87cbd 100644
--- a/tests/Unit/Rules/ConstraintsTest.php
+++ b/tests/Unit/Rules/ConstraintsTest.php
@@ -18,7 +18,7 @@ class ConstraintsTest extends TestCase
{
public function test_it_should_not_add_to_violation_if_constraint_is_not_violated(): void
{
- $trueExpression = new class() implements Expression {
+ $trueExpression = new class implements Expression {
public function describe(ClassDescription $theClass, string $because): Description
{
return new Description('', '');
@@ -48,7 +48,7 @@ public function evaluate(ClassDescription $theClass, Violations $violations, str
public function test_it_should_add_to_violation_store_if_constraint_is_violated(): void
{
- $falseExpression = new class() implements Expression {
+ $falseExpression = new class implements Expression {
public function describe(ClassDescription $theClass, string $because): Description
{
return new Description('bar', 'we want to add this rule');
diff --git a/tests/Unit/Rules/ParsingErrorsTest.php b/tests/Unit/Rules/ParsingErrorsTest.php
index 7ae384ad..e6d08b6e 100644
--- a/tests/Unit/Rules/ParsingErrorsTest.php
+++ b/tests/Unit/Rules/ParsingErrorsTest.php
@@ -11,11 +11,9 @@
class ParsingErrorsTest extends TestCase
{
- /** @var ParsingErrors */
- private $parsingStore;
+ private ParsingErrors $parsingStore;
- /** @var ParsingError */
- private $parsingError;
+ private ParsingError $parsingError;
protected function setUp(): void
{
diff --git a/tests/Unit/Rules/ViolationsTest.php b/tests/Unit/Rules/ViolationsTest.php
index 4326c2df..d4dc767f 100644
--- a/tests/Unit/Rules/ViolationsTest.php
+++ b/tests/Unit/Rules/ViolationsTest.php
@@ -11,11 +11,9 @@
class ViolationsTest extends TestCase
{
- /** @var Violations */
- private $violationStore;
+ private Violations $violationStore;
- /** @var Violation */
- private $violation;
+ private Violation $violation;
protected function setUp(): void
{