diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
index 82ce106..86f2b72 100644
--- a/.github/workflows/continuous-integration.yml
+++ b/.github/workflows/continuous-integration.yml
@@ -45,9 +45,9 @@ jobs:
${{ runner.os }}-codestyle-${{ env.cache-name }}-
- name: Setup PHP and Composer
- uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d
+ uses: shivammathur/setup-php@e77cdb393f70751e0417891f9ae9de6a41096210
with:
- php-version: '8.2'
+ php-version: '8.4'
extensions: gd
tools: cs2pr, composer
env:
@@ -118,9 +118,9 @@ jobs:
${{ runner.os }}-tests-${{ env.cache-name }}-
- name: Setup PHP and Composer
- uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d
+ uses: shivammathur/setup-php@e77cdb393f70751e0417891f9ae9de6a41096210
with:
- php-version: '8.2'
+ php-version: '8.4'
tools: composer:${{ matrix.composer_version }}
extensions: xdebug
env:
diff --git a/Dockerfile b/Dockerfile
index dd93462..9af4c72 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,13 +1,14 @@
-FROM php:8.2-cli-alpine
+FROM php:8.4-cli-alpine
RUN set -eux ; \
- apk add --no-cache --virtual .composer-rundeps \
+ apk add --update --no-cache --virtual .composer-rundeps \
bash \
coreutils \
git \
nodejs \
npm \
openssh-client \
+ sqlite-dev \
tini \
unzip \
zip \
diff --git a/README.md b/README.md
index fb8582b..4fdd65e 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,6 @@ Coding Standard.
It incorporates
* [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer)
and its configuration
-* [PHP Mess Detector](https://github.com/phpmd/phpmd) and its configuration
* [PHP Copy Paste Detector](https://github.com/sebastianbergmann/phpcpd)
* [PHP-Parallel-Lint](https://github.com/JakubOnderka/PHP-Parallel-Lint)
* [PHPStan - PHP Static Analysis Tool](https://github.com/phpstan/phpstan)
diff --git a/composer.json b/composer.json
index 11ceceb..f7ea96c 100644
--- a/composer.json
+++ b/composer.json
@@ -1,118 +1,118 @@
{
- "name": "zooroyal/coding-standard-source",
- "description": "This is the ZooRoyal coding standard source package.",
- "type": "phpcodesniffer-standard",
- "keywords": [
- "ZooRoyal",
- "phpcs",
- "standards",
- "phpmd",
- "phpcpd",
- "lint"
- ],
- "homepage": "https://github.com/ZooRoyal/coding-standard-source",
- "license": "BSD-3-Clause",
- "authors": [
- {
- "name": "Sebastian Knott",
- "email": "sebastian.knott@rewe-digital.com"
- }
- ],
- "support": {
- "issues": "https://github.com/ZooRoyal/coding-standard-source/issues",
- "wiki": "https://github.com/ZooRoyal/coding-standard-source/wiki",
- "source": "https://github.com/ZooRoyal/coding-standard-source"
- },
- "require": {
- "php": "^8.2.0",
- "ext-json": "*",
- "ext-xml": "*",
- "composer-runtime-api": "^2.0",
- "bamarni/composer-bin-plugin": "^1.8",
- "composer/semver": "^3.4",
- "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
- "nette/neon": "^3.3",
- "nikic/php-parser": "^4.18",
- "php-di/php-di": "^7.0.1",
- "phpcompatibility/php-compatibility": "dev-develop#a8d67148fb990fbf5c2f6166d54bc91cc01fc655",
- "slevomat/coding-standard": "^8.10.0",
- "squizlabs/php_codesniffer": "^3.9.0",
- "symfony/console": " ^6.2.8",
- "symfony/event-dispatcher": "^6.2.2",
- "symfony/filesystem": " ^6.2.0",
- "symfony/process": " ^6.2.0",
- "thecodingmachine/safe": "^2.5",
- "webmozart/path-util": "^2.3"
- },
- "require-dev": {
- "amphp/amp": "^v2.6.2",
- "amphp/phpunit-util": "^2.0.0",
- "amphp/process": "^v1.1.4",
- "brianium/paratest": "^6.11.0",
- "infection/infection": ">=0.27.11",
- "mockery/mockery": "^1.6.7",
- "phpunit/phpunit": "^9.6.16",
- "roave/security-advisories": "dev-latest",
- "sebastianknott/hamcrest-object-accessor": "^3.0.0"
- },
- "replace": {
- "zooroyal/coding-standard": "self.version"
- },
- "autoload": {
- "psr-4": {
- "Zooroyal\\CodingStandard\\": "src/main/php/"
- }
- },
- "autoload-dev": {
- "psr-4": {
- "Zooroyal\\CodingStandard\\Tests\\": "tests/"
- },
- "files": [
- "vendor/squizlabs/php_codesniffer/autoload.php",
- "vendor/squizlabs/php_codesniffer/src/Util/Tokens.php",
- "vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php",
- "vendor/slevomat/coding-standard/autoload-bootstrap.php"
- ]
- },
- "bin": [
- "src/bin/coding-standard"
- ],
- "scripts": {
- "post-update-cmd": "npm update",
- "post-install-cmd": "npm install",
- "ci": [
- "@test-prepare",
- "@test",
- "@infection-command"
+ "name": "zooroyal/coding-standard-source",
+ "description": "This is the ZooRoyal coding standard source package.",
+ "type": "phpcodesniffer-standard",
+ "keywords": [
+ "ZooRoyal",
+ "phpcs",
+ "standards",
+ "phpcpd",
+ "lint"
],
- "test-mkdirs": "mkdir -p tmp/phpunit",
- "test-paratest-command": "paratest -p$(getconf _NPROCESSORS_ONLN)",
- "test-prepare": "mkdir -p tmp/phpunit",
- "test": [
- "@test-prepare",
- "@test-paratest-command"
+ "homepage": "https://github.com/ZooRoyal/coding-standard-source",
+ "license": "BSD-3-Clause",
+ "authors": [
+ {
+ "name": "Sebastian Knott",
+ "email": "sebastian.knott@rewe-digital.com"
+ }
],
- "infection-command": "infection -n --threads=$(getconf _NPROCESSORS_ONLN) --skip-initial-tests --coverage=tmp/phpunit --no-progress",
- "infection": [
- "@test-prepare",
- "@test --testsuite=InfectionRelevant",
- "@infection-command"
- ]
- },
- "config": {
- "optimize-autoloader": true,
- "sort-packages": true,
- "process-timeout": 600,
- "allow-plugins": {
- "dealerdirect/phpcodesniffer-composer-installer": true,
- "infection/extension-installer": true,
- "bamarni/composer-bin-plugin": true
- }
- },
- "extra": {
- "bamarni-bin": {
- "bin-links": true,
- "forward-command": true
+ "support": {
+ "issues": "https://github.com/ZooRoyal/coding-standard-source/issues",
+ "wiki": "https://github.com/ZooRoyal/coding-standard-source/wiki",
+ "source": "https://github.com/ZooRoyal/coding-standard-source"
+ },
+ "require": {
+ "php": "^8.4.0",
+ "ext-json": "*",
+ "ext-xml": "*",
+ "composer-runtime-api": "^2.0",
+ "bamarni/composer-bin-plugin": "^1.8.2",
+ "composer/semver": "^3.4.3",
+ "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
+ "nette/neon": "^3.4.4",
+ "nette/utils": "^4.0.5",
+ "nikic/php-parser": "^5.4.0",
+ "php-di/php-di": "^7.0.1",
+ "slevomat/coding-standard": "^8.16.1",
+ "squizlabs/php_codesniffer": "^3.12.0",
+ "symfony/console": " ^7.2.1",
+ "symfony/event-dispatcher": "^7.2.0",
+ "symfony/filesystem": " ^7.2.0",
+ "symfony/process": " ^7.2.4",
+ "thecodingmachine/safe": "^3.0.2",
+ "webmozart/path-util": "^2.3"
+ },
+ "require-dev": {
+ "amphp/amp": "^v2.6.2",
+ "amphp/phpunit-util": "^2.0.1",
+ "amphp/process": "^v1.1.9",
+ "brianium/paratest": "^v6.11.1",
+ "infection/infection": ">=0.29.14",
+ "mikey179/vfsstream": "^1.6.12",
+ "mockery/mockery": "1.6.11",
+ "phpunit/phpunit": "^9.6.22",
+ "roave/security-advisories": "dev-latest",
+ "sebastianknott/hamcrest-object-accessor": "^3.0.0"
+ },
+ "replace": {
+ "zooroyal/coding-standard": "self.version"
+ },
+ "autoload": {
+ "psr-4": {
+ "Zooroyal\\CodingStandard\\": "src/main/php/"
+ }
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Zooroyal\\CodingStandard\\Tests\\": "tests/"
+ },
+ "files": [
+ "vendor/squizlabs/php_codesniffer/autoload.php",
+ "vendor/squizlabs/php_codesniffer/src/Util/Tokens.php",
+ "vendor/squizlabs/php_codesniffer/src/Sniffs/Sniff.php",
+ "vendor/slevomat/coding-standard/autoload-bootstrap.php"
+ ]
+ },
+ "bin": [
+ "src/bin/coding-standard"
+ ],
+ "scripts": {
+ "post-update-cmd": "npm update",
+ "post-install-cmd": "npm install",
+ "ci": [
+ "@test-prepare",
+ "@test",
+ "@infection-command"
+ ],
+ "test-mkdirs": "mkdir -p tmp/phpunit",
+ "test-paratest-command": "paratest -p$(getconf _NPROCESSORS_ONLN)",
+ "test-prepare": "mkdir -p tmp/phpunit",
+ "test": [
+ "@test-prepare",
+ "@test-paratest-command"
+ ],
+ "infection-command": "infection -n --threads=$(getconf _NPROCESSORS_ONLN) --skip-initial-tests --coverage=tmp/phpunit --no-progress",
+ "infection": [
+ "@test-prepare",
+ "@test-paratest-command --testsuite=InfectionRelevant",
+ "@infection-command"
+ ]
+ },
+ "config": {
+ "optimize-autoloader": true,
+ "sort-packages": true,
+ "process-timeout": 600,
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true,
+ "infection/extension-installer": true,
+ "bamarni/composer-bin-plugin": true
+ }
+ },
+ "extra": {
+ "bamarni-bin": {
+ "bin-links": true,
+ "forward-command": true
+ }
}
- }
}
diff --git a/config/phpcs/ZooRoyal/ruleset.xml b/config/phpcs/ZooRoyal/ruleset.xml
index 5b493b8..c0a5639 100755
--- a/config/phpcs/ZooRoyal/ruleset.xml
+++ b/config/phpcs/ZooRoyal/ruleset.xml
@@ -12,13 +12,8 @@
-
-
-
-
-
-
+
@@ -78,15 +73,17 @@
+
+
@@ -121,6 +118,11 @@
+
+
+
+
+
@@ -147,6 +149,11 @@
+
+
+
+
+
@@ -192,7 +199,12 @@
-
+
+
+
+
+
+
@@ -231,13 +243,15 @@
-
+
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/config/phpstan/phpstan.neon b/config/phpstan/phpstan.neon
index bcca6f6..5c1bd01 100755
--- a/config/phpstan/phpstan.neon
+++ b/config/phpstan/phpstan.neon
@@ -10,6 +10,10 @@ parameters:
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- '#Function \S+ invoked with [0-9]+ parameters?, [0-9]+ required.#'
+ - '#Call to static method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) .+ always evaluate to true\.#'
+ - '#Parameter.*of method.*expects \(?callable.*array.*given\.$#'
+ - '#Call to an undefined method Mockery\\ExpectationInterface\|Mockery\\ExpectsHigherOrderMessage#'
exceptions:
check:
tooWideThrowType: true
+ treatPhpDocTypesAsCertain: false
diff --git a/doc/howto/HowToAddANewTool.md b/doc/howto/HowToAddANewTool.md
index 81b3199..0c2764e 100644
--- a/doc/howto/HowToAddANewTool.md
+++ b/doc/howto/HowToAddANewTool.md
@@ -4,7 +4,7 @@
First of all you need to gather some information about your new tool.
-1. Is the tool able to only work on files you provide by a command-line
+1. Is the tool able to only work on files you provide by a command-line
parameter? \
For example Parallel Lint is able to only work on certain files.
```bash
@@ -20,7 +20,7 @@ First of all you need to gather some information about your new tool.
Let's say you want to add your new tool 'SuperCoolTool' to the coding-standard
-1. Create a new namespace
+1. Create a new namespace
`Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\SuperCoolTool`.
2. Create two new Classes in your new namespace: `SuperCoolToolCommand` and `TerminalCommand`.
3. Register your new command.
@@ -29,7 +29,7 @@ The next paragraphs will guid you through that process.
### Implement SuperCoolToolCommand
-This class stores some vital information about the SuperCoolTool. The
+This class stores some vital information about the SuperCoolTool. The
coding-standard will use this information to integrate your tool in its cli.
For now it's best to just have a look at this example implementation.
@@ -44,10 +44,10 @@ your tool you want to expose to the user.
We are going to assume a FixingToolCommand for our SuperCoolTool - its SuperCool after all!
```php
-class SuperCoolToolCommand extends FixingToolCommand
+class SuperCoolToolCommand extends FixingToolCommand
{
// What file makes your tool ignore a directory
- protected string $exclusionListToken = '.dontBeSuperCool';
+ protected string $exclusionListToken = '.dontBeSuperCool';
// Do you only want to check for certain file Types? If not leave empty
protected array $allowedFileEndings = ['sc'];
@@ -86,7 +86,7 @@ class SuperCoolToolCommand extends FixingToolCommand
*/
public function injectDependenciesCommand(Container $container): void
{
- // Create an instance of your TerminalCommand and store it in this property.
+ // Create an instance of your TerminalCommand and store it in this property.
// You may use the container like so but it really doesn't matter as long as
// an instance of your TerminalCommand will be stored in this property
$this->terminalCommand = $container->make(TerminalCommand::class);
@@ -97,9 +97,9 @@ class SuperCoolToolCommand extends FixingToolCommand
### Implement your TerminalCommand
-The coding-standard will inject your TerminalCommand with important
+The coding-standard will inject your TerminalCommand with important
information about the user input and context of the system, but you have to tell it what information you would like to get. For this reason we are using interfaces. \
-In case of your SuperCoolTool we will get information about the files it
+In case of your SuperCoolTool we will get information about the files it
should be checking and the fixing mode.
Let's see...
@@ -110,19 +110,19 @@ Let's see...
// It is a FixingTerminalCommand and TargetableTerminalCommand
class TerminalCommand extends AbstractTerminalCommand implements FixingTerminalCommand, TargetableTerminalCommand
{
- // So you don't need to hassle with setters and such, simply use the
+ // So you don't need to hassle with setters and such, simply use the
// provided traits. The coding-standard provides a trait for every
- // TerminalCommand interface.
+ // TerminalCommand interface.
use TargetableTrait, FixingTrait;
- // The TargetableTrait will create a field named $targetedFiles. The
- // FixingTrait will create a field named $fixingMode. They will be set
+ // The TargetableTrait will create a field named $targetedFiles. The
+ // FixingTrait will create a field named $fixingMode. They will be set
// by higher magic.
- // For more information about available traits and interfaces you may
+ // For more information about available traits and interfaces you may
// need to read their respectivsource code
-
+
/**
- * This method must implement the compilation of the command. Technically it has
+ * This method must implement the compilation of the command. Technically it has
* one shot in setting the protected fields $command and $commandParts.
*/
protected function compile(): void
@@ -159,7 +159,6 @@ class ApplicationFactory
PHPCodeSnifferCommand::class,
PHPCopyPasteDetectorCommand::class,
PHPParallelLintCommand::class,
- PHPMessDetectorCommand::class,
PHPStanCommand::class,
JSESLintCommand::class,
JSStyleLintCommand::class,
@@ -171,7 +170,7 @@ class ApplicationFactory
```
BAM! It's done! Now you can call your tool from command-line
-```bash
+```bash
src/bin/coding-standard sca:supercool # from your dev environment
vendor/bin/coding-standard sca:supercool # if installed as a library
```
diff --git a/infection.json.dist b/infection.json.dist
index ed27bea..8947edc 100644
--- a/infection.json.dist
+++ b/infection.json.dist
@@ -1,6 +1,6 @@
{
"timeout": 20,
- "minMsi": 87,
+ "minMsi": 86,
"minCoveredMsi": 94,
"source": {
"directories": [
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 7d0d690..8858051 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -3,7 +3,7 @@
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true" bootstrap="vendor/autoload.php"
enforceTimeLimit="true"
- executionOrder="random"
+ executionOrder="depends"
resolveDependencies="true"
stopOnRisky="true"
timeoutForSmallTests="2"
diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php
index cf53840..862e575 100644
--- a/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php
+++ b/src/main/php/CommandLine/ApplicationLifeCycle/ApplicationFactory.php
@@ -13,7 +13,6 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint\JSStyleLintCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\PHPCodeSnifferCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\PHPCopyPasteDetectorCommand;
-use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector\PHPMessDetectorCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\PHPParallelLintCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand;
@@ -26,14 +25,13 @@
class ApplicationFactory
{
/** @var array */
- private const COMMANDS
+ private const array COMMANDS
= [
AllToolsCommand::class,
FindFilesToCheckCommand::class,
PHPCodeSnifferCommand::class,
PHPCopyPasteDetectorCommand::class,
PHPParallelLintCommand::class,
- PHPMessDetectorCommand::class,
PHPStanCommand::class,
JSESLintCommand::class,
JSStyleLintCommand::class,
diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php
index 50b3127..d281433 100644
--- a/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php
+++ b/src/main/php/CommandLine/ApplicationLifeCycle/ContainerFactory.php
@@ -24,7 +24,7 @@ private function __construct()
*/
public static function getContainerInstance(): Container
{
- if (self::$container === null) {
+ if (!self::$container instanceof Container) {
self::$container = self::getUnboundContainerInstance();
}
diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php b/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php
index 443f4b7..13a7cf8 100644
--- a/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php
+++ b/src/main/php/CommandLine/ApplicationLifeCycle/EventDispatcherFactory.php
@@ -23,7 +23,7 @@
class EventDispatcherFactory
{
/** @var array */
- private const SUBSCRIBERS
+ private const array SUBSCRIBERS
= [
GitCommandPreconditionChecker::class,
TerminalCommandPreconditionChecker::class,
diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php b/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php
index f0cdd97..30be6c7 100644
--- a/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php
+++ b/src/main/php/CommandLine/ApplicationLifeCycle/GitCommandPreconditionChecker.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle;
+use Override;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -18,7 +19,7 @@
*/
class GitCommandPreconditionChecker implements EventSubscriberInterface
{
- private const COMMAND = 'git rev-parse --git-dir';
+ private const string COMMAND = 'git rev-parse --git-dir';
private ?int $exitCode = null;
@@ -34,6 +35,7 @@ public function __construct(private readonly ProcessRunner $processRunner)
*
* @return array>
*/
+ #[Override]
public static function getSubscribedEvents(): array
{
return [ConsoleEvents::COMMAND => ['checkForGit', 50]];
diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php b/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php
index 79dd994..d924027 100644
--- a/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php
+++ b/src/main/php/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionChecker.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle;
+use Override;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -19,7 +20,7 @@
class TerminalCommandPreconditionChecker implements EventSubscriberInterface
{
/** @var array */
- private const COMMANDS = ['git', 'find'];
+ private const array COMMANDS = ['git', 'find'];
/** @var array */
private array $results = [];
@@ -36,6 +37,7 @@ public function __construct(private readonly ProcessRunner $processRunner)
*
* @return array>
*/
+ #[Override]
public static function getSubscribedEvents(): array
{
return [ConsoleEvents::COMMAND => ['checkForTerminalCommands', 100]];
diff --git a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php
index 232a3e7..9d2ae6f 100644
--- a/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php
+++ b/src/main/php/CommandLine/ApplicationLifeCycle/phpdi.php
@@ -5,6 +5,7 @@
use DI\Container;
use PhpParser\Parser;
use PhpParser\ParserFactory;
+use PhpParser\PhpVersion;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
@@ -20,6 +21,7 @@
use Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders\TokenExcluder;
use Zooroyal\CodingStandard\CommandLine\FileSearch\FastCachedFileSearch;
use Zooroyal\CodingStandard\CommandLine\FileSearch\FileSearchInterface;
+use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter;
use function DI\factory;
use function DI\get;
@@ -30,9 +32,12 @@
FileSearchInterface::class => get(FastCachedFileSearch::class),
InputInterface::class => get(ArgvInput::class),
OutputInterface::class => get(ConsoleOutput::class),
- Parser::class => factory(static function (ContainerInterface $container) {
- return $container->get(ParserFactory::class)->create(ParserFactory::PREFER_PHP7);
- }),
+ Parser::class => factory(
+ static function (ContainerInterface $container, ComposerInterpreter $composerInterpreter) {
+ $phpversion = PhpVersion::fromString($composerInterpreter->getMinimalViablePhpVersion());
+ return $container->get(ParserFactory::class)->createForVersion($phpversion);
+ }
+ ),
'excluders' => factory(
static function (Container $container) {
diff --git a/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php b/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php
index 520fd44..253464f 100644
--- a/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php
+++ b/src/main/php/CommandLine/EnhancedFileInfo/EnhancedFileInfoFactory.php
@@ -14,7 +14,7 @@ class EnhancedFileInfoFactory
{
/** @var array */
private array $filePool = [];
- private string $rootDirectory;
+ private readonly string $rootDirectory;
public function __construct(ProcessRunner $processRunner)
{
diff --git a/src/main/php/CommandLine/Environment/Environment.php b/src/main/php/CommandLine/Environment/Environment.php
index 2c2fd61..94bcd2c 100644
--- a/src/main/php/CommandLine/Environment/Environment.php
+++ b/src/main/php/CommandLine/Environment/Environment.php
@@ -18,7 +18,7 @@
class Environment
{
/** @var string */
- private const GIT = 'git';
+ private const string GIT = 'git';
public function __construct(
private readonly ProcessRunner $processRunner,
diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php
index c014f68..b3755d4 100644
--- a/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php
+++ b/src/main/php/CommandLine/ExclusionList/Excluders/GitIgnoresExcluder.php
@@ -4,13 +4,14 @@
namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
class GitIgnoresExcluder implements ExcluderInterface
{
- private const GIT_LS_FILES_COMMAND = 'git ls-files -io --exclude-standard --directory';
+ private const string GIT_LS_FILES_COMMAND = 'git ls-files -io --exclude-standard --directory';
/** @var array */
private array $cache = [];
@@ -32,15 +33,16 @@ public function __construct(
*
* @return array
*/
+ #[Override]
public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array
{
- if (!empty($this->cache)) {
+ if ($this->cache !== []) {
return $this->cache;
}
$rawIgnoredFoldersAndFilesString = $this->processRunner->runAsProcess(self::GIT_LS_FILES_COMMAND);
- if (empty($rawIgnoredFoldersAndFilesString)) {
+ if ($rawIgnoredFoldersAndFilesString === '' || $rawIgnoredFoldersAndFilesString === '0') {
return [];
}
$rawIgnoredFoldersAndFiles = explode("\n", $rawIgnoredFoldersAndFilesString);
diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php
index eac46bf..c38bbb2 100644
--- a/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php
+++ b/src/main/php/CommandLine/ExclusionList/Excluders/GitPathsExcluder.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -33,6 +34,7 @@ public function __construct(
*
* @return array
*/
+ #[Override]
public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array
{
$cacheKey = $this->cacheKeyGenerator->generateCacheKey($alreadyExcludedPaths);
diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php
index 6d9fb6e..1eb088e 100644
--- a/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php
+++ b/src/main/php/CommandLine/ExclusionList/Excluders/StaticExcluder.php
@@ -4,13 +4,14 @@
namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
class StaticExcluder implements ExcluderInterface
{
/** @var array */
- private const PATHS_TO_EXCLUDE
+ private const array PATHS_TO_EXCLUDE
= [
'.git',
'.idea',
@@ -41,9 +42,10 @@ public function __construct(
*
* @return array
*/
+ #[Override]
public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array
{
- if (!empty($this->cache)) {
+ if ($this->cache !== []) {
return $this->cache;
}
diff --git a/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php b/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php
index 8dcc395..b4c6302 100644
--- a/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php
+++ b/src/main/php/CommandLine/ExclusionList/Excluders/TokenExcluder.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -34,6 +35,7 @@ public function __construct(
*
* @return array
*/
+ #[Override]
public function getPathsToExclude(array $alreadyExcludedPaths, array $config = []): array
{
if (!isset($config['token'])) {
diff --git a/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php b/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php
index 67a1621..bddf6ac 100644
--- a/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php
+++ b/src/main/php/CommandLine/ExclusionList/ExclusionListFactory.php
@@ -48,7 +48,7 @@ public function build(string $token = '', bool $deDuped = true): array
$excludedPaths = [...$excludedPaths, ...$newlyFoundExclusionPaths];
}
- $filteredArray = $deDuped === true
+ $filteredArray = $deDuped
? $this->exclusionListSanitizer->sanitizeExclusionList($excludedPaths)
: $excludedPaths;
diff --git a/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php b/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php
index 4eb0be1..c54d49d 100644
--- a/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php
+++ b/src/main/php/CommandLine/ExclusionList/ExclusionListSanitizer.php
@@ -37,7 +37,7 @@ static function ($value, $key) use ($item, $i): bool {
if ($key === $i) {
return true;
}
- return !($value->isSubdirectoryOf($item) || $value->getPathname() === $item->getPathname());
+ return !$value->isSubdirectoryOf($item) && $value->getPathname() !== $item->getPathname();
},
ARRAY_FILTER_USE_BOTH,
);
diff --git a/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php b/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php
index bf074c2..b62b497 100644
--- a/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php
+++ b/src/main/php/CommandLine/FileFinder/AdaptableFileFinder.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\FileFinder;
+use Override;
use Symfony\Component\Console\Exception\InvalidArgumentException;
/**
@@ -27,6 +28,7 @@ public function __construct(
*
* @throws InvalidArgumentException
*/
+ #[Override]
public function findFiles(
array $allowedFileEndings = [],
string $exclusionListToken = '',
diff --git a/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php b/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php
index 1e141ea..5dbea23 100644
--- a/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php
+++ b/src/main/php/CommandLine/FileFinder/AllCheckableFileFinder.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\FileFinder;
+use Override;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
class AllCheckableFileFinder implements FileFinderInterface
@@ -23,6 +24,7 @@ public function __construct(
*
* @param array $allowedFileEndings
*/
+ #[Override]
public function findFiles(
array $allowedFileEndings = [],
string $exclusionListToken = '',
diff --git a/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php b/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php
index 9b41cf2..c42a69a 100644
--- a/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php
+++ b/src/main/php/CommandLine/FileFinder/DiffCheckableFileFinder.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\FileFinder;
+use Override;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
@@ -26,6 +27,7 @@ public function __construct(
*
* @throws InvalidArgumentException
*/
+ #[Override]
public function findFiles(
array $allowedFileEndings = [],
string $exclusionListToken = '',
diff --git a/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php b/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php
index 11e8a83..e871fc8 100644
--- a/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php
+++ b/src/main/php/CommandLine/FileFinder/GitChangeSetFilter.php
@@ -61,7 +61,7 @@ private function mergeLists(
array $exclusionList,
array $inclusionlist,
): SplObjectStorage {
- if (count(array_intersect($exclusionList, $inclusionlist)) !== 0) {
+ if (array_intersect($exclusionList, $inclusionlist) !== []) {
throw new LogicException('Directories can\'t be black- and inclusionlisted at the same time', 1553780055);
}
$result = new SplObjectStorage();
@@ -101,7 +101,7 @@ private function applyFilters(array $allowedFileEndings, array $files, SplObject
*/
private function filterByAllowedFileEndings(array &$result, array $allowedFileEndings): void
{
- if (!empty($allowedFileEndings)) {
+ if ($allowedFileEndings !== []) {
$result = array_filter(
$result,
static function ($file) use ($allowedFileEndings): bool {
diff --git a/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php b/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php
index 68f77fa..382fec6 100644
--- a/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php
+++ b/src/main/php/CommandLine/FileSearch/FastCachedFileSearch.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\FileSearch;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -21,6 +22,7 @@ public function __construct(private readonly EnhancedFileInfoFactory $enhancedFi
/**
* {@inheritDoc}
*/
+ #[Override]
public function listFolderFiles(
string $fileName,
EnhancedFileInfo $path,
diff --git a/src/main/php/CommandLine/Process/ProcessRunner.php b/src/main/php/CommandLine/Process/ProcessRunner.php
index 535d44f..5b0e048 100644
--- a/src/main/php/CommandLine/Process/ProcessRunner.php
+++ b/src/main/php/CommandLine/Process/ProcessRunner.php
@@ -36,7 +36,7 @@ public function runAsProcess(string $command, string ...$arguments): string
$output = $process->getOutput();
$errorOutput = $process->getErrorOutput();
- $result = empty($errorOutput)
+ $result = $errorOutput === '' || $errorOutput === '0'
? $output
: $output . PHP_EOL . $errorOutput;
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php
index 0ebaf23..278b778 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/AllToolsCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis;
+use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
@@ -15,7 +16,7 @@
class AllToolsCommand extends Command
{
/** @var array */
- private array $injectedOptions;
+ private readonly array $injectedOptions;
public function __construct(
FixableInputFacet $fixableFacet,
@@ -29,6 +30,7 @@ public function __construct(
parent::__construct($name);
}
+ #[Override]
protected function configure(): void
{
$this->setName('sca:all');
@@ -43,6 +45,7 @@ protected function configure(): void
/**
* {@inheritdoc}
*/
+ #[Override]
public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('All SCA-Commands will be executed.', OutputInterface::OUTPUT_NORMAL);
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php
index c93270e..6458440 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis;
+use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
@@ -27,6 +28,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
+ #[Override]
public function configure(): void
{
$this->setName('find-files');
@@ -37,9 +39,8 @@ public function configure(): void
/**
* Builds InputDefinition for Command
- *
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
private function buildInputDefinition(): InputDefinition
{
return new InputDefinition(
@@ -94,6 +95,7 @@ private function buildInputDefinition(): InputDefinition
/**
* {@inheritdoc}
*/
+ #[Override]
public function execute(InputInterface $input, OutputInterface $output): int
{
$exclusionListInput = $input->getOption('exclusionList');
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php
index 0eefe2e..daeab34 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use Exception;
+use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
@@ -31,7 +32,8 @@ abstract class AbstractToolCommand extends Command
*
* @throws RuntimeException
*/
- public function execute(InputInterface $input, OutputInterface $output): ?int
+ #[Override]
+ public function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln(PHP_EOL . 'Running ' . $this->terminalCommandName . '');
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php
index 796c9cc..5d414c0 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEvent.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic;
+use Override;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleEvent;
use Symfony\Component\Console\Input\InputInterface;
@@ -26,16 +27,19 @@ public function __construct(
}
/** @return array */
+ #[Override]
public function getAllowedFileEndings(): array
{
return $this->allowedFileEndings;
}
+ #[Override]
public function getExclusionListToken(): string
{
return $this->exclusionListToken;
}
+ #[Override]
public function getTerminalCommand(): TerminalCommand
{
return $this->terminalCommand;
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php
index 30a5bb6..d809736 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\FixableInputFacet;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\TargetableInputFacet;
@@ -17,6 +18,7 @@ public function __construct(
parent::__construct($targetableFacet, $name);
}
+ #[Override]
protected function configure(): void
{
parent::configure();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php
index 2ab9d23..1d25337 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\TargetableInputFacet;
abstract class TargetableToolsCommand extends AbstractToolCommand
@@ -13,6 +14,7 @@ public function __construct(private readonly TargetableInputFacet $targetableFac
parent::__construct($name);
}
+ #[Override]
protected function configure(): void
{
$this->setDefinition($this->targetableFacet->getInputDefinition());
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php
index f70abd9..87b6b3d 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use Exception;
+use Override;
use Stringable;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Output\OutputInterface;
@@ -25,6 +26,7 @@ abstract class AbstractTerminalCommand implements TerminalCommand, Stringable
*
* @return array
*/
+ #[Override]
public function toArray(): array
{
if (!$this->compiled) {
@@ -85,6 +87,7 @@ private function runCompilation(): void
* Returns the command as sting. This string is supposed to work as input to a
* *NIX terminal.
*/
+ #[Override]
public function __toString(): string
{
if (!$this->compiled) {
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php
index cd38d2e..108d5b1 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Exclusion;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\ExclusionList\ExclusionListFactory;
@@ -20,6 +21,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php
index 74cb3e6..8a96568 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/FileExtensionDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Extension;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator;
@@ -13,6 +14,7 @@ class FileExtensionDecorator extends TerminalCommandDecorator
/**
* {@inheritDoc}
*/
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php
index 4c7b5f5..27c763b 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Fix;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet\FixableInputFacet;
@@ -13,6 +14,7 @@ class FixDecorator extends TerminalCommandDecorator
/**
* {@inheritDoc}
*/
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php
index 1168917..283a89b 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Multiprocess;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
@@ -17,6 +18,7 @@ public function __construct(private readonly ProcessRunner $processRunner)
{
}
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php
index c8434cb..c3759b3 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreter.php
@@ -12,8 +12,8 @@
class ComposerInterpreter
{
- private const SEARCH_DEPTH_MIN = 1;
- private const SEARCH_DEPTH_MAX = 4;
+ private const int SEARCH_DEPTH_MIN = 1;
+ private const int SEARCH_DEPTH_MAX = 4;
private ?string $cachedMinimalViablePhpVersion = null;
private string $cachedMinimalRootPackagePhpVersion;
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php
index 5a52090..359f71b 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverter.php
@@ -20,6 +20,8 @@ public function __construct()
'8.0.' => '30',
'8.1.' => '28',
'8.2.' => '19',
+ '8.3.' => '16',
+ '8.4.' => '3',
];
foreach ($phpVersionRanges as $phpVersionString => $phpMaxPatchVersion) {
@@ -36,7 +38,7 @@ public function __construct()
*/
public function extractActualPhpVersion(string $phpVersionConstraint): string
{
- if (preg_match('/^(\d+)(\.\d+)?(\.\d+)?$/', $phpVersionConstraint, $matches)) {
+ if (preg_match('/^(\d+)(\.\d+)?(\.\d+)?$/', $phpVersionConstraint, $matches) !== 0) {
return $matches[1] . ($matches[2] ?? '.0') . ($matches[3] ?? '.0');
}
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php
index c18c52c..587f613 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator;
@@ -14,6 +15,7 @@ public function __construct(private readonly ComposerInterpreter $composerInterp
{
}
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php
index bd6a3a4..d4c5f44 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator;
@@ -15,6 +16,7 @@ public function __construct(
) {
}
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php
index a15c558..675badd 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesser.php
@@ -9,7 +9,7 @@
class ParentBranchGuesser
{
/** @var string */
- private const GIT = 'git';
+ private const string GIT = 'git';
public function __construct(
private readonly ProcessRunner $processRunner,
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php
index a9e36bb..8c4f161 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\FileFinder\AdaptableFileFinder;
@@ -23,6 +24,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php
index b179c6c..3cc343f 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand;
+use Override;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
abstract class TerminalCommandDecorator implements EventSubscriberInterface
@@ -21,6 +22,7 @@ abstract public function decorate(DecorateEvent $event): void;
*
* @return array>
*/
+ #[Override]
final public static function getSubscribedEvents(): array
{
return [self::EVENT_DECORATE_TERMINAL_COMMAND => ['decorate', 50]];
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php
index e7edcf0..d24e52c 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunner.php
@@ -21,10 +21,10 @@ public function run(TerminalCommand $terminalCommand): ?int
static function () use ($process, $output): void {
$errorIncrement = $process->getIncrementalErrorOutput();
$outputIncrement = $process->getIncrementalOutput();
- if (!empty($errorIncrement)) {
+ if ($errorIncrement !== '' && $errorIncrement !== '0') {
$output->write($errorIncrement, false, OutputInterface::OUTPUT_RAW);
}
- if (!empty($outputIncrement)) {
+ if ($outputIncrement !== '' && $outputIncrement !== '0') {
$output->write($outputIncrement, false, OutputInterface::OUTPUT_RAW);
}
},
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php
index 9bbfb51..e242c7f 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecorator.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\TerminalCommandDecorator;
@@ -13,6 +14,7 @@ class VerboseDecorator extends TerminalCommandDecorator
/**
* {@inheritDoc}
*/
+ #[Override]
public function decorate(DecorateEvent $event): void
{
$terminalCommand = $event->getTerminalCommand();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php
index 374156a..1566833 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/FixableInputFacet.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet;
+use Override;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
@@ -14,6 +15,7 @@ class FixableInputFacet implements ToolCommandInputFacet
/**
* This method returns the input definition needed to know if the user wants something to be fixed.
*/
+ #[Override]
public function getInputDefinition(): InputDefinition
{
return new InputDefinition(
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php
index e04ebec..f5d3823 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/Generic/ToolCommandFacet/TargetableInputFacet.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\ToolCommandFacet;
+use Override;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
@@ -18,6 +19,7 @@ class TargetableInputFacet implements ToolCommandInputFacet
* This method returns the input definition needed to know if the user wants the command to be focused on changed
* files.
*/
+ #[Override]
public function getInputDefinition(): InputDefinition
{
return new InputDefinition(
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php
index bdbf2f2..cda919d 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use DI\Container;
+use Override;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommand;
@@ -23,6 +24,7 @@ class JSESLintCommand extends FixingToolCommand
/**
* {@inheritDoc}
*/
+ #[Override]
protected function configure(): void
{
parent::configure();
@@ -38,7 +40,8 @@ protected function configure(): void
/**
* {@inheritDoc}
*/
- public function execute(InputInterface $input, OutputInterface $output): ?int
+ #[Override]
+ public function execute(InputInterface $input, OutputInterface $output): int
{
try {
$this->terminalCommandFinder->findTerminalCommand('eslint');
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php
index 6df43ee..474349f 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSESLint;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -19,6 +20,7 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TerminalCommand extends AbstractTerminalCommand implements
FixTerminalCommand,
TargetTerminalCommand,
@@ -32,7 +34,7 @@ class TerminalCommand extends AbstractTerminalCommand implements
use FileExtensionTrait;
use VerboseTrait;
- private const TEMPLATE
+ private const string TEMPLATE
= 'npx %8$s--no-install eslint %6$s%7$s--no-error-on-unmatched-pattern --no-eslintrc --config %1$s %3$s'
. '--ignore-path %2$s %4$s%5$s';
@@ -43,6 +45,7 @@ public function __construct(private readonly Environment $environment)
/**
* {@inheritDoc}
*/
+ #[Override]
protected function compile(): void
{
$this->validateTargets();
@@ -133,7 +136,7 @@ private function buildTargetingString(): string
private function buildFixingString(): string
{
$fixingString = '';
- if ($this->fixingMode === true) {
+ if ($this->fixingMode) {
$fixingString = '--fix ';
}
return $fixingString;
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php
index ef8063a..aef2b43 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use DI\Container;
+use Override;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommand;
@@ -23,6 +24,7 @@ class JSStyleLintCommand extends FixingToolCommand
/**
* {@inheritDoc}
*/
+ #[Override]
protected function configure(): void
{
parent::configure();
@@ -38,7 +40,8 @@ protected function configure(): void
/**
* {@inheritDoc}
*/
- public function execute(InputInterface $input, OutputInterface $output): ?int
+ #[Override]
+ public function execute(InputInterface $input, OutputInterface $output): int
{
try {
$this->terminalCommandFinder->findTerminalCommand('stylelint');
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php
index a946ff0..63d6b63 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -19,6 +20,7 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TerminalCommand extends AbstractTerminalCommand implements
TargetTerminalCommand,
FixTerminalCommand,
@@ -32,7 +34,8 @@ class TerminalCommand extends AbstractTerminalCommand implements
use FileExtensionTrait;
use VerboseTrait;
- private const TEMPLATE = 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s';
+ private const string TEMPLATE
+ = 'npx %6$s--no-install stylelint %3$s %4$s%5$s--allow-empty-input --config-basedir --config=%1$s%2$s';
/**
* TerminalCommand constructor.
@@ -44,6 +47,7 @@ public function __construct(private readonly Environment $environment)
/**
* {@inheritDoc}
*/
+ #[Override]
protected function compile(): void
{
$this->validateTargets();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php
index c97d60f..6728ebd 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use DI\Container;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommand;
class PHPCodeSnifferCommand extends FixingToolCommand
@@ -15,6 +16,7 @@ class PHPCodeSnifferCommand extends FixingToolCommand
/** @var array */
protected array $allowedFileEndings = ['php'];
+ #[Override]
protected function configure(): void
{
parent::configure();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php
index 4a79636..e1ba79c 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -25,6 +26,7 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TerminalCommand extends AbstractTerminalCommand implements
FixTerminalCommand,
TargetTerminalCommand,
@@ -42,7 +44,7 @@ class TerminalCommand extends AbstractTerminalCommand implements
use MultiprocessTrait;
use MinimalVersionDependentTrait;
- private const TEMPLATE = 'php %1$s %5$s%6$s--parallel=%7$d -p --standard=%2$s%3$s%8$s%4$s';
+ private const string TEMPLATE = 'php %1$s %5$s%6$s--parallel=%7$d -p --standard=%2$s%3$s%8$s%4$s';
public function __construct(
private readonly Environment $environment,
@@ -53,6 +55,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
+ #[Override]
protected function compile(): void
{
$this->validateTargets();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php
index 28b7363..e736944 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use DI\Container;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\AbstractToolCommand;
class PHPCopyPasteDetectorCommand extends AbstractToolCommand
@@ -19,6 +20,7 @@ class PHPCopyPasteDetectorCommand extends AbstractToolCommand
/**
* {@inheritDoc}
*/
+ #[Override]
protected function configure(): void
{
$this->setName('sca:copy-paste-detect');
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php
index a432ace..317cb78 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
@@ -15,6 +16,7 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TerminalCommand extends AbstractTerminalCommand implements
ExclusionTerminalCommand,
FileExtensionTerminalCommand,
@@ -24,8 +26,8 @@ class TerminalCommand extends AbstractTerminalCommand implements
use FileExtensionTrait;
use TargetTrait;
- private const TEMPLATE = 'php %1$s --fuzzy %3$s%2$s%4$s';
- private const STATIC_EXCLUDES
+ private const string TEMPLATE = 'php %1$s --fuzzy %3$s%2$s%4$s';
+ private const array STATIC_EXCLUDES
= [
'custom/plugins/ZRBannerSlider/ZRBannerSlider.php',
'custom/plugins/ZRPreventShipping/ZRPreventShipping.php',
@@ -38,6 +40,7 @@ public function __construct(private readonly Environment $environment, private r
/**
* {@inheritDoc}
*/
+ #[Override]
protected function compile(): void
{
$vendorPath = $this->environment->getVendorDirectory()->getRealPath();
@@ -80,7 +83,7 @@ private function buildExcludingString(): string
$finderResult = $this->processRunner->runAsProcess(...$command);
- if (!empty($finderResult)) {
+ if ($finderResult !== '' && $finderResult !== '0') {
$finderResultLines = explode(PHP_EOL, trim($finderResult));
}
@@ -140,7 +143,7 @@ private function buildTargetingString(): string
private function useExclusions(): bool
{
- return empty($this->targetedFiles);
+ return $this->targetedFiles === null || $this->targetedFiles === [];
}
/**
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php
deleted file mode 100644
index 9be3807..0000000
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommand.php
+++ /dev/null
@@ -1,45 +0,0 @@
- */
- protected array $allowedFileEndings = ['php'];
-
- /**
- * {@inheritDoc}
- */
- protected function configure(): void
- {
- parent::configure();
- $this->setName('sca:mess-detect');
- $this->setDescription('Run PHP-MD on PHP files.');
- $this->setHelp(
- 'This tool executes PHP-MD on a certain set of PHP files of this project. It ignores files which are in '
- . 'directories with a .dontMessDetectPHP file. Subdirectories are ignored too.',
- );
- $this->terminalCommandName = 'PHP Mess Detector';
- }
-
- /**
- * This method accepts all dependencies needed to use this class properly.
- * It's annotated for use with PHP-DI.
- *
- * @see http://php-di.org/doc/annotations.html
- */
- #[Inject]
- public function injectDependenciesCommand(Container $container): void
- {
- $this->terminalCommand = $container->make(TerminalCommand::class);
- }
-}
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php
deleted file mode 100644
index 50ed08f..0000000
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommand.php
+++ /dev/null
@@ -1,101 +0,0 @@
-validateTargets();
-
- $vendorPath = $this->environment->getVendorDirectory()->getRealPath();
- $phpMessDetectorConfig = $this->environment->getPackageDirectory()->getRealPath()
- . '/config/phpmd/phpmd.xml';
-
- $terminalApplication = $vendorPath . '/bin/phpmd';
-
- $sprintfCommand = sprintf(
- self::TEMPLATE,
- $terminalApplication,
- $this->buildTargetingString(),
- $phpMessDetectorConfig,
- $this->buildExcludingString(),
- $this->buildExtensionString(),
- );
-
- $this->command = $sprintfCommand;
- $this->commandParts = explode(' ', $sprintfCommand);
- }
-
- /**
- * This method returns the string representation of the excluded files list.
- */
- private function buildExcludingString(): string
- {
- $excludingString = '';
- if ($this->excludesFiles !== []) {
- $excludingString = ' --exclude ';
- $excludesFilePaths = array_map(
- static fn(EnhancedFileInfo $item) => $item->getRealPath(),
- $this->excludesFiles,
- );
- $excludingString .= implode(',', $excludesFilePaths);
- }
- return $excludingString;
- }
-
- /**
- * This method returns the string representation of the targeted files list.
- */
- private function buildTargetingString(): string
- {
- if ($this->targetedFiles !== null) {
- $targetedFilePaths = array_map(
- static fn(EnhancedFileInfo $item) => $item->getRealPath(),
- $this->targetedFiles,
- );
- $targetingString = implode(',', $targetedFilePaths);
- } else {
- $targetingString = $this->environment->getRootDirectory()->getRealPath();
- }
- return $targetingString;
- }
-
- private function buildExtensionString(): string
- {
- $extensionString = '';
- if ($this->fileExtensions !== []) {
- $extensionString = ' --suffixes ';
- $extensionString .= implode(',', $this->fileExtensions);
- }
- return $extensionString;
- }
-}
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php
index caabcb9..316b0a6 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use DI\Container;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommand;
class PHPParallelLintCommand extends TargetableToolsCommand
@@ -18,6 +19,7 @@ class PHPParallelLintCommand extends TargetableToolsCommand
/**
* {@inheritDoc}
*/
+ #[Override]
protected function configure(): void
{
parent::configure();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php
index 5609093..bd3f7e4 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint;
+use Override;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\AbstractTerminalCommand;
@@ -16,6 +17,7 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTerminalCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\TargetTrait;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TerminalCommand extends AbstractTerminalCommand implements
TargetTerminalCommand,
ExclusionTerminalCommand,
@@ -27,7 +29,7 @@ class TerminalCommand extends AbstractTerminalCommand implements
use FileExtensionTrait;
use MultiprocessTrait;
- private const TEMPLATE = 'php %1$s -j %5$d%2$s%3$s%4$s';
+ private const string TEMPLATE = 'php %1$s -j %5$d%2$s%3$s%4$s';
public function __construct(private readonly Environment $environment)
{
@@ -36,6 +38,7 @@ public function __construct(private readonly Environment $environment)
/**
* {@inheritDoc}
*/
+ #[Override]
protected function compile(): void
{
$this->validateTargets();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php
index b7e2672..ddd50ad 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommand.php
@@ -6,6 +6,7 @@
use DI\Attribute\Inject;
use DI\Container;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommand;
class PHPStanCommand extends TargetableToolsCommand
@@ -20,6 +21,7 @@ class PHPStanCommand extends TargetableToolsCommand
/**
* {@inheritDoc}
*/
+ #[Override]
protected function configure(): void
{
parent::configure();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php
index 922d5ab..c1c3013 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGenerator.php
@@ -14,14 +14,14 @@
class PHPStanConfigGenerator
{
- private const TOOL_FUNCTIONS_FILE_MAPPING
+ private const array TOOL_FUNCTIONS_FILE_MAPPING
= [
'deployer/deployer' => ['/src/functions.php'],
'hamcrest/hamcrest-php' => ['/hamcrest/Hamcrest.php'],
'mockery/mockery' => ['/library/helpers.php'],
'sebastianknott/hamcrest-object-accessor' => ['/src/functions.php'],
];
- private const STATIC_DIRECTORIES_TO_SCAN
+ private const array STATIC_DIRECTORIES_TO_SCAN
= [
'/Plugins',
'/custom/plugins',
@@ -29,8 +29,8 @@ class PHPStanConfigGenerator
'/vendor',
'/vendor-bin',
];
- private const MAX_TMP_RANDOM = 1000000;
- private const MIN_TMP_RANDOM = 0;
+ private const int MAX_TMP_RANDOM = 1000000;
+ private const int MIN_TMP_RANDOM = 0;
public function __construct(
private readonly Filesystem $filesystem,
@@ -45,9 +45,9 @@ public function __construct(
/**
* This method adds dynamic config values to the given config array. This is needed for the PHPStan config drop-in.
*
- * @param array|string>|string> $configValues
+ * @param array|string>|string> $configValues
*
- * @return array|string>|string>
+ * @return array|string>|string>
*/
public function addDynamicConfigValues(array $configValues): array
{
@@ -88,9 +88,9 @@ private function addFunctionsFiles(array $configValues): array
/**
* Adds the list of files to be excluded to the config.
*
- * @param array>> $configValues
+ * @param array>> $configValues
*
- * @return array>>
+ * @return array|string>|string>>
*/
private function addExcludedFiles(array $configValues): array
{
@@ -129,7 +129,7 @@ private function addStaticDirectoriesToScan(array $configValues): array
*
* @param array>> $configValues
*
- * @return array>>
+ * @return array|int|string>>
*/
private function addPhpVersion(array $configValues): array
{
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php
index f01a5c7..af1223a 100644
--- a/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php
+++ b/src/main/php/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommand.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan;
+use Override;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -15,6 +16,7 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTerminalCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseTrait;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TerminalCommand extends AbstractTerminalCommand implements
TargetTerminalCommand,
VerboseTerminalCommand,
@@ -24,7 +26,7 @@ class TerminalCommand extends AbstractTerminalCommand implements
use VerboseTrait;
use VersionDependentTrait;
- private const TEMPLATE = 'php %1$s analyse %4$s--no-progress --error-format=github -c %2$s %3$s';
+ private const string TEMPLATE = 'php %1$s analyse %4$s--no-progress --error-format=github -c %2$s %3$s';
public function __construct(
private readonly Environment $environment,
@@ -34,6 +36,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
+ #[Override]
protected function compile(): void
{
$this->validateTargets();
diff --git a/src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/.dontCopyPasteDetectPHP b/src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP
similarity index 100%
rename from src/main/php/CommandLine/StaticCodeAnalysis/PHPMessDetector/.dontCopyPasteDetectPHP
rename to src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP
diff --git a/src/main/php/Sniffs/ObjectCalisthenics/.dontStanPHP b/src/main/php/Sniffs/ObjectCalisthenics/.dontStanPHP
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php
new file mode 100644
index 0000000..57766e5
--- /dev/null
+++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Exception/NonClassTypeTokenTypeException.php
@@ -0,0 +1,11 @@
+ */
+ private static array $propertyList = [];
+
+ public static function getClassMethodCount(File $file, int $position): int
+ {
+ $methodCount = 0;
+ $pointer = $position;
+
+ while (($next = $file->findNext(T_FUNCTION, $pointer + self::ONE)) !== false) {
+ ++$methodCount;
+
+ $pointer = $next;
+ }
+
+ return $methodCount;
+ }
+
+ public static function getClassPropertiesCount(File $file, int $position): int
+ {
+ return count(self::getClassProperties($file, $position));
+ }
+
+ /**
+ * @return array
+ */
+ public static function getClassProperties(File $file, int $position): array
+ {
+ $tokens = $file->getTokens();
+ $token = $tokens[$position];
+ $pointer = $token['scope_opener'];
+
+ self::$propertyList = [];
+
+ while (($pointer = $file->findNext(T_VARIABLE, ($pointer + self::ONE), $token['scope_closer'])) !== false) {
+ self::extractPropertyIfFound($file, $pointer);
+ }
+
+ return self::$propertyList;
+ }
+
+ private static function extractPropertyIfFound(File $file, int $position): void
+ {
+ if (PropertyHelper::isProperty($file, $position)) {
+ self::$propertyList[] = $position;
+ }
+ }
+
+
+}
diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php
new file mode 100644
index 0000000..51c174a
--- /dev/null
+++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Helper/NamingHelper.php
@@ -0,0 +1,55 @@
+
+ */
+ private const CODE_TO_TYPE_NAME_MAP = [
+ T_CONST => 'Constant',
+ T_CLASS => 'Class',
+ T_FUNCTION => 'Function',
+ T_TRAIT => 'Trait',
+ T_INTERFACE => 'Interface',
+ ];
+
+ public static function getTypeName(File $file, int $position): string
+ {
+ $token = $file->getTokens()[$position];
+ $tokenCode = $token['code'];
+ if (isset(self::CODE_TO_TYPE_NAME_MAP[$tokenCode])) {
+ return self::CODE_TO_TYPE_NAME_MAP[$tokenCode];
+ }
+
+ if ($token['code'] === T_VARIABLE) {
+ if (PropertyHelper::isProperty($file, $position)) {
+ return 'Property';
+ }
+
+ return 'Variable';
+ }
+
+ return '';
+ }
+
+ public static function getElementName(File $file, int $position): string
+ {
+ $name = $file->getTokens()[$position]['content'];
+
+ if (Strings::startsWith($name, '$')) {
+ return trim($name, '$');
+ }
+
+ $namePosition = $file->findNext(T_STRING, $position, $position + 3);
+
+ return $file->getTokens()[$namePosition]['content'];
+ }
+}
diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php
new file mode 100644
index 0000000..222357f
--- /dev/null
+++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimitSniff.php
@@ -0,0 +1,40 @@
+
+ */
+ public function register(): array
+ {
+ return [T_CLASS, T_INTERFACE, T_TRAIT];
+ }
+
+ public function process(File $file, $position)
+ {
+ $methodCount = ClassAnalyzer::getClassMethodCount($file, $position);
+
+ if ($methodCount > $this->maxCount) {
+ $typeName = NamingHelper::getTypeName($file, $position);
+ $message = sprintf(self::ERROR_MESSAGE, $typeName, $methodCount, $this->maxCount);
+
+ $file->addError($message, $position, 'MethodPerClassLimit');
+ }
+ }
+}
diff --git a/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php
new file mode 100644
index 0000000..90d8514
--- /dev/null
+++ b/src/main/php/Sniffs/ObjectCalisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimitSniff.php
@@ -0,0 +1,39 @@
+
+ */
+ public function register(): array
+ {
+ return [T_CLASS, T_TRAIT];
+ }
+
+ public function process(File $file, $position)
+ {
+ $propertiesCount = ClassAnalyzer::getClassPropertiesCount($file, $position);
+
+ if ($propertiesCount > $this->maxCount) {
+ $tokenType = $file->getTokens()[$position]['content'];
+
+ $message = sprintf(self::ERROR_MESSAGE, $tokenType, $propertiesCount, $this->maxCount);
+ $file->addError($message, $position, 'PropertyPerClassLimit');
+ }
+ }
+}
diff --git a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php
index 208dda1..1e54925 100644
--- a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php
+++ b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentAlignmentSniff.php
@@ -30,7 +30,6 @@
*
* This version ignores OpenAPI (OA) comments that may be deeply nested.
*
- * @SuppressWarnings(PHPMD)
*/
class DocCommentAlignmentSniff implements Sniff
{
diff --git a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php
index 6e8e3c7..9ad03b6 100644
--- a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php
+++ b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/DocCommentSniff.php
@@ -69,7 +69,6 @@ public function register()
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
- * @SuppressWarnings(PHPMD)
*
* @return void
*/
diff --git a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php
index aa0010e..2eb3bfb 100644
--- a/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php
+++ b/src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniff.php
@@ -36,7 +36,6 @@ public function register()
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
- * @SuppressWarnings(PHPMD)
*
* @return void
*/
diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php
new file mode 100644
index 0000000..7408db0
--- /dev/null
+++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniff.php
@@ -0,0 +1,72 @@
+getTokens();
+ $token = $tokens[$stackPtr]['content'];
+
+ $name = match ($token) {
+ 'function' => FunctionHelper::getName($phpcsFile, $stackPtr),
+ 'class', 'trait', 'interface' => ClassHelper::getName($phpcsFile, $stackPtr),
+ default => $this->getName($tokens[$stackPtr]['content']),
+ };
+
+ if (strlen($name) > $this->maximumLength) {
+ $error = 'Name "%s" is greater than %s characters long';
+ $data = [$name, $this->maximumLength];
+ $phpcsFile->addError($error, $stackPtr, 'NameTooLong', $data);
+ }
+
+ if (strlen($name) < $this->minimumLength) {
+ $error = 'Name "%s" is less than %s characters long';
+ $data = [$name, $this->minimumLength];
+ $phpcsFile->addError($error, $stackPtr, 'NameTooShort', $data);
+ }
+ }
+
+
+ private function getName(string $content): string
+ {
+ // Add exclusion for variable $i so you cant use it in for loops.
+ if ($content === '$i') {
+ return str_pad($content, $this->maximumLength, 'i');
+ }
+
+ return ltrim($content, '$');
+ }
+}
diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php
index f7d8962..b09d1cb 100644
--- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php
+++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniff.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe;
+use Override;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PhpParser\Node;
@@ -13,26 +14,44 @@
use SlevomatCodingStandard\Helpers\TokenHelper;
use SlevomatCodingStandard\Helpers\UseStatement;
use SlevomatCodingStandard\Helpers\UseStatementHelper;
+use Symfony\Component\Filesystem\Filesystem;
use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
+use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter;
use function Safe\file_get_contents;
use function Safe\scandir;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class CheckSafeFunctionUsageSniff implements Sniff
{
/** @var array */
- private array $functionNames;
+ private readonly array $functionNames;
public function __construct()
{
$container = ContainerFactory::getContainerInstance();
+ $composerInterpreter = $container->get(ComposerInterpreter::class);
+
+ $phpversion = $composerInterpreter->getMinimalViablePhpVersion();
+
+ list($major, $minor) = explode('.', $phpversion);
+
$environment = $container->get(Environment::class);
- $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/';
+ $fileSystem = $container->get(Filesystem::class);
+ $path = $environment->getRootDirectory()->getRealPath() . '/vendor/thecodingmachine/safe/generated/'
+ . $major . '.' . $minor . '/';
+
+ if (!$fileSystem->exists($path)) {
+ $this->functionNames = [];
+ return;
+ }
+
try {
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
$filesUnfiltered = @scandir($path);
} catch (DirException) {
+ $this->functionNames = [];
return;
}
@@ -58,11 +77,12 @@ public function __construct()
/**
* Description is in the inherited doc.
*
- * @{inheritDoc}
+ * {@inheritDoc}
*
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification We must
* stay compatible with the interface even if we don't like it.
*/
+ #[Override]
public function register(): array
{
return [
@@ -73,29 +93,30 @@ public function register(): array
/**
* Description is in the inherited doc.
*
- * @{inheritDoc}
+ * {@inheritDoc}
*
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint We must
* stay compatible with the interface even if we don't like it.
*
* @throws AssertionException
*/
+ #[Override]
public function process(File $phpcsFile, $stackPtr): void
{
- if (!isset($this->functionNames)) {
+ if ($this->functionNames === []) {
throw new AssertionException(
- 'No function names found! Did you forget to install thecodingmachine/Safe?',
+ 'No function names found! Did you forget to install thecodingmachine/Safe ^v3?',
1684240278,
);
}
$tokens = $phpcsFile->getTokens();
- $functionName = strtolower(ltrim($tokens[$stackPtr]['content'], '\\'));
+ $functionName = strtolower($tokens[$stackPtr]['content']);
try {
$this->assertNextTokenParenthesisOpener($phpcsFile, $stackPtr);
$this->assertGlobalFunctionCall($phpcsFile, $stackPtr);
- $this->assertFunctionProvidedBySafe($tokens[$stackPtr]['content']);
+ $this->assertFunctionProvidedBySafe($functionName);
$this->assertFunctionUnused($phpcsFile, $functionName);
} catch (AssertionException) {
// If this is the case we found no Safe function. Continue...
@@ -113,20 +134,13 @@ private function assertNextTokenParenthesisOpener(File $phpcsFile, int $stackPtr
}
}
- private function assertFunctionProvidedBySafe(string $functionName): void
- {
- if (!in_array($functionName, $this->functionNames, true)) {
- throw new AssertionException('Function ' . $functionName . ' not found in Safe!', 1684230170);
- }
- }
-
private function assertGlobalFunctionCall(File $phpcsFile, int $stackPtr): void
{
$previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $stackPtr - 1);
if (
in_array(
$phpcsFile->getTokens()[$previousPointer]['code'],
- [T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION],
+ [T_OBJECT_OPERATOR, T_DOUBLE_COLON, T_FUNCTION, T_NEW],
true,
)
) {
@@ -134,6 +148,13 @@ private function assertGlobalFunctionCall(File $phpcsFile, int $stackPtr): void
}
}
+ private function assertFunctionProvidedBySafe(string $functionName): void
+ {
+ if (!in_array($functionName, $this->functionNames, true)) {
+ throw new AssertionException('Function ' . $functionName . ' not found in Safe!', 1684230170);
+ }
+ }
+
private function assertFunctionUnused(File $phpcsFile, string $functionName): void
{
$usesSearchResult = UseStatementHelper::getFileUseStatements($phpcsFile);
diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php
index e41f333..698e570 100644
--- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php
+++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniff.php
@@ -15,10 +15,10 @@
class DisallowMixedParameterTypeHintSniff
{
- private const NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint';
- private const ERROR_CODE = 'MixedParameterTypeHintUsed';
- private const INVALID_TYPE_HINT = 'mixed';
- private const ERROR_MESSAGE_FUNCTION
+ private const string NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint';
+ private const string ERROR_CODE = 'MixedParameterTypeHintUsed';
+ private const string INVALID_TYPE_HINT = 'mixed';
+ private const string ERROR_MESSAGE_FUNCTION
= 'uses "' . self::INVALID_TYPE_HINT . '" type hint for parameter %s, which is disallowed';
public function process(File $phpcsFile, int $functionPointer): void
@@ -30,7 +30,7 @@ public function process(File $phpcsFile, int $functionPointer): void
return;
}
$parametersTypeHints = FunctionHelper::getParametersTypeHints($phpcsFile, $functionPointer);
- if (empty($parametersTypeHints)) {
+ if ($parametersTypeHints === []) {
return;
}
/** @var array $token */
@@ -55,7 +55,7 @@ public function register(): array
/**
* Check the parameter type hints
*
- * @param array $parametersTypeHints
+ * @param array $parametersTypeHints
*/
private function checkTypeHints(
File $phpcsFile,
diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php
index 7b0658a..5f97264 100644
--- a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php
+++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniff.php
@@ -14,11 +14,11 @@
class DisallowMixedReturnTypeHintSniff
{
- private const NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint';
+ private const string NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint';
- private const ERROR_CODE = 'MixedParameterTypeHintUsed';
+ private const string ERROR_CODE = 'MixedParameterTypeHintUsed';
- private const INVALID_TYPE_HINT = 'mixed';
+ private const string INVALID_TYPE_HINT = 'mixed';
/** @return array */
public function register(): array
@@ -38,7 +38,7 @@ public function process(File $phpcsFile, int $pointer): void
/** @var int|string $tokenCode */
$tokenCode = $token['code'];
$returnTypeHint = $this->getReturnTypeHintByTokenCode($phpcsFile, $pointer, $tokenCode);
- if ($returnTypeHint === null) {
+ if (!$returnTypeHint instanceof TypeHint) {
return;
}
if ($tokenCode === T_FUNCTION) {
diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php
new file mode 100644
index 0000000..1dcafad
--- /dev/null
+++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniff.php
@@ -0,0 +1,39 @@
+ $this->maximumArguments) {
+ $error = 'Method has too many parameters. Maximum allowed is %s, but found %s.';
+ $data = [$this->maximumArguments, count($parameterNames)];
+ $phpcsFile->addError($error, $stackPtr, 'TooManyArguments', $data);
+ }
+ }
+}
diff --git a/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php
new file mode 100644
index 0000000..92f12c1
--- /dev/null
+++ b/src/main/php/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniff.php
@@ -0,0 +1,50 @@
+ $this->maximumUseStatements) {
+ $error = 'Too many use statements. Maximum allowed is %s, but found %s.';
+ $data = [$this->maximumUseStatements, count($usePointers[11])];
+ $phpcsFile->addError($error, $stackPtr, 'TooManyUseStatements', $data);
+ }
+ }
+}
diff --git a/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php b/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php
index 948485c..f916481 100644
--- a/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php
+++ b/tests/Functional/CommandLine/ExclusionList/Excluders/ExclusionListSanitizerTest.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\Tests\Functional\CommandLine\ExclusionList\Excluders;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\ExclusionList\ExclusionListSanitizer;
@@ -12,6 +13,7 @@ class ExclusionListSanitizerTest extends TestCase
{
private ExclusionListSanitizer $subject;
+ #[Override]
protected function setUp(): void
{
$this->subject = new ExclusionListSanitizer();
diff --git a/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php b/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php
index b7d8d14..d5a9bbf 100644
--- a/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php
+++ b/tests/Functional/CommandLine/Factories/EnhancedFileInfoFactoryTest.php
@@ -8,6 +8,7 @@
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers as H;
use InvalidArgumentException;
+use Override;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use SebastianKnott\HamcrestObjectAccessor\HasProperty;
@@ -25,6 +26,7 @@ class EnhancedFileInfoFactoryTest extends TestCase
private string $relativeFilePath2;
private string $rootDirectory;
+ #[Override]
public function setUp(): void
{
$container = ContainerFactory::getContainerInstance();
diff --git a/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php b/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php
index 56d7cb1..1e6dd0c 100644
--- a/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php
+++ b/tests/Functional/CommandLine/Factories/ExclusionListFactoryTest.php
@@ -6,6 +6,7 @@
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers as H;
+use Override;
use PHPUnit\Framework\TestCase;
use SebastianKnott\HamcrestObjectAccessor\HasProperty;
use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory;
@@ -18,6 +19,7 @@ class ExclusionListFactoryTest extends TestCase
{
private ExclusionListFactory $subject;
+ #[Override]
protected function setUp(): void
{
$forgedGitPath = __DIR__ . '/Fixtures/gitExclude/.git';
@@ -29,6 +31,7 @@ protected function setUp(): void
$this->subject = $container->get(ExclusionListFactory::class);
}
+ #[Override]
protected function tearDown(): void
{
rmdir(__DIR__ . '/Fixtures/gitExclude/.git');
diff --git a/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php b/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php
index 6c5ffb5..c05b68f 100644
--- a/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php
+++ b/tests/Functional/CommandLine/FileFinders/DiffCheckableFileFinderTest.php
@@ -8,6 +8,7 @@
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers as H;
use Mockery;
+use Override;
use PHPUnit\Framework\TestCase;
use SebastianKnott\HamcrestObjectAccessor\HasProperty;
use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory;
@@ -21,6 +22,7 @@ class DiffCheckableFileFinderTest extends TestCase
private array $forgedFileSet;
private string $forgedRawDiffUnfilteredString;
+ #[Override]
protected function setUp(): void
{
parent::setUp();
@@ -38,6 +40,7 @@ protected function setUp(): void
. 'topFolder/folder/.dontChangeFiles';
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php b/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php
index 4a81096..34b3124 100644
--- a/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php
+++ b/tests/Functional/CommandLine/FileSearch/FastCachedFileSearchTest.php
@@ -7,6 +7,7 @@
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\Timer\Timer;
use SebastianKnott\HamcrestObjectAccessor\HasProperty;
@@ -21,6 +22,7 @@ class FastCachedFileSearchTest extends TestCase
private EnhancedFileInfoFactory $enhancedFileInfoFactory;
private EnhancedFileInfo $forgedPath;
+ #[Override]
public function setUp(): void
{
$container = ContainerFactory::getUnboundContainerInstance();
@@ -45,6 +47,7 @@ public function searchForFiles(): void
Matchers::allOf(
Matchers::containsInAnyOrder([
'src/main/php/Sniffs/PHPCodeSniffer/.dontSniffPHP',
+ 'src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP',
'tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/Fixtures/.dontSniffPHP',
'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/.dontSniffPHP',
'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/.dontSniffPHP',
@@ -71,6 +74,7 @@ public function searchForFilesIgnoringExcludedDirs(): void
Matchers::allOf(
Matchers::containsInAnyOrder([
'src/main/php/Sniffs/PHPCodeSniffer/.dontSniffPHP',
+ 'src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP',
]),
Matchers::not(
Matchers::containsInAnyOrder([
@@ -106,6 +110,7 @@ public function searchForFilesIgnoringBelowMinDepth(): void
MatcherAssert::assertThat(
$resultPaths,
Matchers::containsInAnyOrder(
+ 'src/main/php/Sniffs/ObjectCalisthenics/.dontSniffPHP',
'tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/Fixtures/.dontSniffPHP',
'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/.dontSniffPHP',
'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/.dontSniffPHP',
diff --git a/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php b/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php
index ba0bba9..f26838a 100644
--- a/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php
+++ b/tests/Functional/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/TerminalCommandRunnerTest.php
@@ -7,6 +7,7 @@
use Hamcrest\Matchers;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
@@ -23,6 +24,7 @@ class TerminalCommandRunnerTest extends TestCase
private OutputInterface $mockedOutput;
private ProcessRunner $processRunner;
+ #[Override]
protected function setUp(): void
{
$this->mockedOutput = Mockery::mock(OutputInterface::class);
@@ -31,6 +33,7 @@ protected function setUp(): void
$this->subject = new TerminalCommandRunner($this->processRunner, $this->mockedOutput);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php
new file mode 100644
index 0000000..37eec1b
--- /dev/null
+++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/MethodPerClassLimitSniffTest.php
@@ -0,0 +1,77 @@
+ */
+ private array $commandPrefix;
+
+ #[Override]
+ public static function setUpBeforeClass(): void
+ {
+ parent::setUpBeforeClass();
+ $reflection = new ReflectionClass(ClassLoader::class);
+ self::$vendorDir = dirname($reflection->getFileName(), 2);
+
+ require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
+ }
+
+ #[Override]
+ protected function setUp(): void
+ {
+ $this->commandPrefix = [
+ 'vendor/bin/phpcs',
+ '--sniffs=' . self::SNIFF_NAME,
+ '--standard=ZooRoyal',
+ '-s',
+ ];
+ }
+
+ /**
+ * @test
+ * @medium
+ * @covers \Zooroyal\CodingStandard\Sniffs\ObjectCalisthenics\Standards\ZooRoyal\Sniffs\Metrics\MethodPerClassLimitSniff
+ */
+ public function itShouldReportNoErrors(): void
+ {
+ $this->commandPrefix[] = __FILE__;
+ $subject = new Process($this->commandPrefix, self::$vendorDir . '/../');
+ $subject->mustRun();
+ $subject->wait();
+ self::assertSame(0, $subject->getExitCode());
+ }
+
+ /**
+ * @test
+ * @medium
+ * @covers \Zooroyal\CodingStandard\Sniffs\ObjectCalisthenics\Standards\ZooRoyal\Sniffs\Metrics\MethodPerClassLimitSniff
+ */
+ public function itShouldReportErrorsForExistingMixedTypes(): void
+ {
+ $this->commandPrefix[] = self::FIXTURE_DIRECTORY;
+ $subject = new Process($this->commandPrefix, self::$vendorDir . '/../');
+ $subject->run();
+ $subject->wait();
+ $output = $subject->getOutput();
+ self::assertMatchesRegularExpression('/Trait has too many methods: 26\. Can be up to 25 methods\./', $output);
+ self::assertMatchesRegularExpression('/Class has too many methods: 26\. Can be up to 25 methods\./', $output);
+ self::assertMatchesRegularExpression('/Interface has too many methods: 26\. Can be up to 25 methods\./', $output);
+ }
+}
diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc
new file mode 100644
index 0000000..1462670
--- /dev/null
+++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/MethodPerClassLimit/wrong/wrong.php.inc
@@ -0,0 +1,138 @@
+ */
+ private array $commandPrefix;
+
+ #[Override]
+ public static function setUpBeforeClass(): void
+ {
+ parent::setUpBeforeClass();
+ $reflection = new ReflectionClass(ClassLoader::class);
+ self::$vendorDir = dirname($reflection->getFileName(), 2);
+
+ require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
+ }
+
+ #[Override]
+ protected function setUp(): void
+ {
+ $this->commandPrefix = [
+ 'vendor/bin/phpcs',
+ '--sniffs=' . self::SNIFF_NAME,
+ '--standard=ZooRoyal',
+ '-s',
+ ];
+ }
+
+ /**
+ * @test
+ * @medium
+ */
+ public function itShouldReportNoErrors(): void
+ {
+ $this->commandPrefix[] = self::FIXTURE_DIRECTORY_CORRECT;
+ $subject = new Process($this->commandPrefix, self::$vendorDir . '/../');
+ $subject->mustRun();
+ $subject->wait();
+ self::assertSame(0, $subject->getExitCode());
+ }
+
+ /**
+ * @test
+ * @medium
+ */
+ public function itShouldReportErrorsForExistingMixedTypes(): void
+ {
+ $this->commandPrefix[] = self::FIXTURE_DIRECTORY_WRONG;
+ $subject = new Process($this->commandPrefix, self::$vendorDir . '/../');
+ $subject->run();
+ $subject->wait();
+ $output = $subject->getOutput();
+ self::assertMatchesRegularExpression('/"class" has too many properties: 26\. Can be up to 25/', $output);
+ }
+}
diff --git a/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc
new file mode 100644
index 0000000..50d10ae
--- /dev/null
+++ b/tests/Functional/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Sniffs/Metrics/PropertyPerClassLimit/correct/correct.php.inc
@@ -0,0 +1,14 @@
+ */
private array $commandPrefix;
+ #[Override]
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
@@ -24,6 +26,7 @@ public static function setUpBeforeClass(): void
require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
}
+ #[Override]
protected function setUp(): void
{
$this->commandPrefix = explode(' ', 'php ' . self::$vendorDir . '/bin/phpcs '
diff --git a/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php b/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php
index 0a43d66..600af15 100644
--- a/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php
+++ b/tests/Functional/Sniffs/PHPCodesniffer/Standards/ZooRoyal/Sniffs/Commenting/FunctionCommentThrowTagSniffTest.php
@@ -5,6 +5,7 @@
namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\PHPCodesniffer\Standards\ZooRoyal\Sniffs\Commenting;
use Composer\Autoload\ClassLoader;
+use Override;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\Process\Process;
@@ -15,6 +16,7 @@ class FunctionCommentThrowTagSniffTest extends TestCase
/** @var array */
private array $commandPrefix;
+ #[Override]
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
@@ -24,6 +26,7 @@ public static function setUpBeforeClass(): void
require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
}
+ #[Override]
protected function setUp(): void
{
$this->commandPrefix = explode(' ', 'vendor/bin/phpcs '
diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
index 4977a8b..9f4850e 100644
--- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
+++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
@@ -5,19 +5,21 @@
namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe;
use Composer\Autoload\ClassLoader;
+use Override;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\Process\Process;
class CheckSafeFunctionUsageSniffTest extends TestCase
{
- private const SNIFF_NAME = 'ZooRoyal.Safe.CheckSafeFunctionUsage';
- private const FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/fixtures/';
+ private const string SNIFF_NAME = 'ZooRoyal.Safe.CheckSafeFunctionUsage';
+ private const string FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/fixtures/';
private static string $vendorDir;
/** @var array */
private array $commandPrefix = [];
+ #[Override]
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
@@ -27,6 +29,7 @@ public static function setUpBeforeClass(): void
require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
}
+ #[Override]
protected function setUp(): void
{
$this->commandPrefix = [
diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php
index 81355df..ad8afa4 100644
--- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php
+++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php
@@ -5,20 +5,23 @@
namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints;
use Composer\Autoload\ClassLoader;
+use Override;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\Process\Process;
class DisallowMixedParameterTypeHintSniffTest extends TestCase
{
- private const SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint';
+ private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint';
- private const FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/';
+ private const string FIXTURE_DIRECTORY
+ = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/Parameter/';
private static string $vendorDir;
/** @var array */
private array $commandPrefix;
+ #[Override]
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
@@ -28,6 +31,7 @@ public static function setUpBeforeClass(): void
require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
}
+ #[Override]
protected function setUp(): void
{
$this->commandPrefix = [
diff --git a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php
index 90f80f5..19c02d9 100644
--- a/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php
+++ b/tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php
@@ -5,20 +5,23 @@
namespace Zooroyal\CodingStandard\Tests\Functional\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints;
use Composer\Autoload\ClassLoader;
+use Override;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\Process\Process;
class DisallowMixedReturnTypeHintSniffTest extends TestCase
{
- private const SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint';
+ private const string SNIFF_NAME = 'Zooroyal.TypeHints.DisallowMixedReturnTypeHint';
- private const FIXTURE_DIRECTORY = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/';
+ private const string FIXTURE_DIRECTORY
+ = 'tests/Functional/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/Fixtures/ReturnType/';
private static string $vendorDir;
/** @var array */
private array $commandPrefix;
+ #[Override]
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
@@ -28,6 +31,7 @@ public static function setUpBeforeClass(): void
require_once self::$vendorDir . '/squizlabs/php_codesniffer/autoload.php';
}
+ #[Override]
protected function setUp(): void
{
$this->commandPrefix = [
diff --git a/tests/System/Complete/GlobalSystemTest.php b/tests/System/Complete/GlobalSystemTest.php
index 90d7f8d..46c31e2 100644
--- a/tests/System/Complete/GlobalSystemTest.php
+++ b/tests/System/Complete/GlobalSystemTest.php
@@ -6,6 +6,7 @@
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers as H;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
@@ -15,6 +16,7 @@ class GlobalSystemTest extends TestCase
{
private Filesystem $filesystem;
+ #[Override]
public static function setUpBeforeClass(): void
{
$dockerCheckProcess = new Process(['docker', 'info']);
@@ -24,12 +26,14 @@ public static function setUpBeforeClass(): void
}
}
+ #[Override]
protected function setUp(): void
{
parent::setUp();
$this->filesystem = new Filesystem();
}
+ #[Override]
public static function tearDownAfterClass(): void
{
TestEnvironmentInstallation::getInstance()->removeInstallation();
@@ -50,7 +54,6 @@ public function dontFilesMakeAllGood(): void
$dotFiles = [
'.dontSniffPHP',
- '.dontMessDetectPHP',
'.dontCopyPasteDetectPHP',
'.dontLintPHP',
'.dontSniffLESS',
@@ -108,7 +111,6 @@ private function runTools(string $environmentDirectory, bool $errorsAreGood = fa
{
$tools = [
'sca:sniff',
- 'sca:mess',
'sca:para',
'sca:copy',
'sca:stan',
diff --git a/tests/System/Eslint/RunEslintWithConfigTest.php b/tests/System/Eslint/RunEslintWithConfigTest.php
index 6d931f4..b9e8174 100644
--- a/tests/System/Eslint/RunEslintWithConfigTest.php
+++ b/tests/System/Eslint/RunEslintWithConfigTest.php
@@ -9,6 +9,7 @@
use Amp\Promise;
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers as H;
+use Override;
use Symfony\Component\Filesystem\Filesystem;
use Zooroyal\CodingStandard\Tests\Tools\TestEnvironmentInstallation;
@@ -16,19 +17,21 @@
class RunEslintWithConfigTest extends AsyncTestCase
{
- private const EXPECTED_TS_PROBLEMS = '183 problems';
- private const EXPECTED_JS_PROBLEMS = '183 problems';
- private const ESLINT_COMMAND = 'npx --no-install eslint --config ';
- private const ESLINT_CONFIG_FILE = 'vendor/zooroyal/coding-standard-source/config/eslint/eslint.config.js ';
+ private const string EXPECTED_TS_PROBLEMS = '183 problems';
+ private const string EXPECTED_JS_PROBLEMS = '183 problems';
+ private const string ESLINT_COMMAND = 'npx --no-install eslint --config ';
+ private const string ESLINT_CONFIG_FILE = 'vendor/zooroyal/coding-standard-source/config/eslint/eslint.config.js ';
private Filesystem $filesystem;
+ #[Override]
protected function setUp(): void
{
parent::setUp();
$this->filesystem = new Filesystem();
}
+ #[Override]
public static function tearDownAfterClass(): void
{
TestEnvironmentInstallation::getInstance()->removeInstallation();
@@ -47,7 +50,6 @@ public function runEslintForJSInCleanInstall(): iterable
$command = $this->getEslintCommand(
'vendor/zooroyal/coding-standard-source/tests/System/fixtures/eslint/BadCode.js',
- $testInstancePath,
);
$commandArray = explode(' ', $command);
$process = new Process($commandArray, $testInstancePath);
@@ -76,7 +78,6 @@ public function runEslintForTSInCleanInstall(): iterable
$command = $this->getEslintCommand(
'vendor/zooroyal/coding-standard-source/tests/System/fixtures/eslint/BadCode.ts',
- $testInstancePath,
);
$commandArray = explode(' ', $command);
$process = new Process($commandArray, $testInstancePath);
@@ -134,7 +135,7 @@ private function prepareInstallationDirectory(): string
return $envInstallationPath;
}
- private function getEslintCommand(string $fileToCheck, string $testInstancePath): string
+ private function getEslintCommand(string $fileToCheck): string
{
return self::ESLINT_COMMAND
. self::ESLINT_CONFIG_FILE
diff --git a/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
index 492f437..3282db4 100644
--- a/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
+++ b/tests/System/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\Tests\System\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
@@ -15,12 +16,14 @@ class CheckSafeFunctionUsageSniffTest extends TestCase
{
private Filesystem $filesystem;
+ #[Override]
protected function setUp(): void
{
parent::setUp();
$this->filesystem = new Filesystem();
}
+ #[Override]
public static function tearDownAfterClass(): void
{
TestEnvironmentInstallation::getInstance()->removeInstallation();
@@ -58,7 +61,10 @@ public function nagIfSafeIsNotInstalled(): void
$output = $processCodingStandard->getOutput();
self::assertMatchesRegularExpression('/No.*function.*names.*found!/ms', $output);
- self::assertMatchesRegularExpression('/Did.*you.*forget.*to.*install.*thecodingmachine\/Safe\?/ms', $output);
+ self::assertMatchesRegularExpression(
+ '/Did.*you.*forget.*to.*install.*thecodingmachine\/Safe \^v3\?/ms',
+ $output
+ );
}
private function prepareInstallationDirectory(): string
diff --git a/tests/Tools/TerminalCommandTestData.php b/tests/Tools/TerminalCommandTestData.php
index f86dabe..09b391c 100644
--- a/tests/Tools/TerminalCommandTestData.php
+++ b/tests/Tools/TerminalCommandTestData.php
@@ -12,7 +12,7 @@
*/
class TerminalCommandTestData
{
- private string $expectedCommand;
+ private readonly string $expectedCommand;
/** @var array|null */
private ?array $targets = null;
private bool $fixingMode = false;
diff --git a/tests/Tools/TestEnvironmentInstallation.php b/tests/Tools/TestEnvironmentInstallation.php
index 118fbae..c79edb1 100644
--- a/tests/Tools/TestEnvironmentInstallation.php
+++ b/tests/Tools/TestEnvironmentInstallation.php
@@ -17,10 +17,10 @@
class TestEnvironmentInstallation
{
private static TestEnvironmentInstallation $instance;
- private Filesystem $filesystem;
- private string $installationPath;
+ private readonly Filesystem $filesystem;
+ private readonly string $installationPath;
private string $composerJsonPath = '';
- private string $composerPath;
+ private readonly string $composerPath;
private bool $isInstalled = false;
/**
diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php
index fb214bc..c2c5246 100644
--- a/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php
+++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ApplicationFactoryTest.php
@@ -8,6 +8,7 @@
use Hamcrest\Matchers;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
@@ -19,11 +20,14 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint\JSStyleLintCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\PHPCodeSnifferCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\PHPCopyPasteDetectorCommand;
-use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPMessDetector\PHPMessDetectorCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\PHPParallelLintCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand;
use Zooroyal\CodingStandard\Tests\Tools\SubjectFactory;
+/**
+ * Class ApplicationFactoryTest
+ */
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class ApplicationFactoryTest extends TestCase
{
private ApplicationFactory $subject;
@@ -36,7 +40,6 @@ class ApplicationFactoryTest extends TestCase
PHPCodeSnifferCommand::class,
PHPStanCommand::class,
FindFilesToCheckCommand::class,
- PHPMessDetectorCommand::class,
PHPCopyPasteDetectorCommand::class,
JSESLintCommand::class,
JSStyleLintCommand::class,
@@ -67,6 +70,7 @@ public function build(): void
self::assertSame($result->mockery_getName(), $mockedApplication->mockery_getName());
}
+ #[Override]
public function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -77,6 +81,7 @@ public function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php
index 99e1321..89d495e 100644
--- a/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php
+++ b/tests/Unit/CommandLine/ApplicationLifeCycle/ContainerFactoryTest.php
@@ -8,6 +8,7 @@
use DI\ContainerBuilder;
use Hamcrest\Matchers;
use Mockery;
+use Override;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Symfony\Component\Console\Output\OutputInterface;
@@ -15,6 +16,7 @@
class ContainerFactoryTest extends TestCase
{
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php
index 7d6c148..9aaa584 100644
--- a/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php
+++ b/tests/Unit/CommandLine/ApplicationLifeCycle/EventDispatcherFactoryTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\EventDispatcherFactory;
@@ -22,6 +23,10 @@
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Verbose\VerboseDecorator;
use Zooroyal\CodingStandard\Tests\Tools\SubjectFactory;
+/**
+ * Class EventDispatcherFactoryTest
+ */
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class EventDispatcherFactoryTest extends TestCase
{
private EventDispatcherFactory $subject;
@@ -65,6 +70,7 @@ public function build(): void
self::assertSame($result->mockery_getName(), $mockedEventDispatcher->mockery_getName());
}
+ #[Override]
public function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -73,6 +79,7 @@ public function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php
index 520cb20..b73cdcd 100644
--- a/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php
+++ b/tests/Unit/CommandLine/ApplicationLifeCycle/GitCommandPreconditionCheckerTest.php
@@ -8,6 +8,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Exception\RuntimeException;
@@ -22,6 +23,7 @@ class GitCommandPreconditionCheckerTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
public function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -30,6 +32,7 @@ public function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php b/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php
index b0db1c7..aef278b 100644
--- a/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php
+++ b/tests/Unit/CommandLine/ApplicationLifeCycle/TerminalCommandPreconditionCheckerTest.php
@@ -8,6 +8,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Exception\RuntimeException;
@@ -24,6 +25,7 @@ class TerminalCommandPreconditionCheckerTest extends TestCase
/** @var array */
private array $commandsToCheck = ['git', 'find'];
+ #[Override]
public function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -32,6 +34,7 @@ public function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/Environment/EnvironmentTest.php b/tests/Unit/CommandLine/Environment/EnvironmentTest.php
index ba682b7..ff27f7d 100644
--- a/tests/Unit/CommandLine/Environment/EnvironmentTest.php
+++ b/tests/Unit/CommandLine/Environment/EnvironmentTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -22,6 +23,7 @@ class EnvironmentTest extends TestCase
private array $subjectParameters;
private MockInterface|EnhancedFileInfo $mockedEnhancedFileInfo;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnhancedFileInfo = Mockery::mock(EnhancedFileInfo::class);
@@ -32,6 +34,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php
index edfa4a2..8c09d6c 100644
--- a/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php
+++ b/tests/Unit/CommandLine/ExclusionList/Excluders/CacheKeyGeneratorTest.php
@@ -5,6 +5,7 @@
namespace Zooroyal\CodingStandard\Tests\Unit\CommandLine\ExclusionList\Excluders;
use Mockery;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders\CacheKeyGenerator;
@@ -13,6 +14,7 @@ class CacheKeyGeneratorTest extends TestCase
{
private CacheKeyGenerator $subject;
+ #[Override]
protected function setUp(): void
{
$this->subject = new CacheKeyGenerator();
diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php
index fcf729a..e63ccff 100644
--- a/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php
+++ b/tests/Unit/CommandLine/ExclusionList/Excluders/GitIgnoresExcluderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -20,6 +21,7 @@ class GitIgnoresExcluderTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -29,6 +31,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php
index 41ba411..a2cb27b 100644
--- a/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php
+++ b/tests/Unit/CommandLine/ExclusionList/Excluders/GitPathsExcluderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -22,6 +23,7 @@ class GitPathsExcluderTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -35,6 +37,7 @@ protected function setUp(): void
->withNoArgs()->andReturn($this->forgedRootDirectory);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php
index e421136..b70e55f 100644
--- a/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php
+++ b/tests/Unit/CommandLine/ExclusionList/Excluders/StaticExcluderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -18,6 +19,7 @@ class StaticExcluderTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -26,6 +28,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php b/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php
index e393de0..0f95a2d 100644
--- a/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php
+++ b/tests/Unit/CommandLine/ExclusionList/Excluders/TokenExcluderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -22,6 +23,7 @@ class TokenExcluderTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -35,6 +37,7 @@ protected function setUp(): void
->withNoArgs()->andReturn($this->forgedRootDirectory);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php b/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php
index 314563d..d0d2d6c 100644
--- a/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php
+++ b/tests/Unit/CommandLine/ExclusionList/ExclusionListFactoryTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\ExclusionList\Excluders\ExcluderInterface;
@@ -21,6 +22,7 @@ class ExclusionListFactoryTest extends TestCase
private array $mockedExcluders;
private MockInterface|ExclusionListSanitizer $mockedExclusionListSanitizer;
+ #[Override]
protected function setUp(): void
{
$this->mockedExcluder1 = Mockery::mock(ExcluderInterface::class);
@@ -32,6 +34,7 @@ protected function setUp(): void
$this->subject = new ExclusionListFactory($this->mockedExcluders, $this->mockedExclusionListSanitizer);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php b/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php
index 47f57f1..0978a38 100644
--- a/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php
+++ b/tests/Unit/CommandLine/FileFinder/AdaptableFileFinderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Zooroyal\CodingStandard\CommandLine\FileFinder\AdaptableFileFinder;
@@ -22,6 +23,7 @@ class AdaptableFileFinderTest extends TestCase
private array $subjectParameters;
private AdaptableFileFinder $subject;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -30,6 +32,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php b/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php
index a47053a..1324136 100644
--- a/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php
+++ b/tests/Unit/CommandLine/FileFinder/AllCheckableFileFinderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\FileFinder\AllCheckableFileFinder;
use Zooroyal\CodingStandard\CommandLine\FileFinder\GitChangeSet;
@@ -20,6 +21,7 @@ class AllCheckableFileFinderTest extends TestCase
private array $subjectParameters;
private AllCheckableFileFinder $subject;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -28,6 +30,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php b/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php
index 0843003..2bb0ffd 100644
--- a/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php
+++ b/tests/Unit/CommandLine/FileFinder/CommitishComparatorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\FileFinder\CommitishComparator;
use Zooroyal\CodingStandard\CommandLine\FileFinder\GitInputValidator;
@@ -18,6 +19,7 @@ class CommitishComparatorTest extends TestCase
/** @var array|array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -28,6 +30,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php b/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php
index d6e745e..a0c9e2b 100644
--- a/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php
+++ b/tests/Unit/CommandLine/FileFinder/DiffCheckableFileFinderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Zooroyal\CodingStandard\CommandLine\FileFinder\DiffCheckableFileFinder;
@@ -21,6 +22,7 @@ class DiffCheckableFileFinderTest extends TestCase
private array $subjectParameters;
private DiffCheckableFileFinder $subject;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -29,6 +31,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php b/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php
index baafe93..00c51c4 100644
--- a/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php
+++ b/tests/Unit/CommandLine/FileFinder/GitChangeSetFactoryTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfoFactory;
@@ -18,6 +19,7 @@ class GitChangeSetFactoryTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
diff --git a/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php b/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php
index 988797b..06e0229 100644
--- a/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php
+++ b/tests/Unit/CommandLine/FileFinder/GitChangeSetFilterTest.php
@@ -8,6 +8,7 @@
use Hamcrest\Matchers;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Exception\LogicException;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -25,6 +26,7 @@ class GitChangeSetFilterTest extends TestCase
private string $exclusionlistedDirectory = 'blub';
private string $mockedRootDirectory = '/my/root/directory';
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -34,6 +36,7 @@ protected function setUp(): void
$this->subject = $buildFragments['subject'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php b/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php
index 3fcc6e0..6e6c1f6 100644
--- a/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php
+++ b/tests/Unit/CommandLine/FileFinder/GitInputValidatorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Zooroyal\CodingStandard\CommandLine\FileFinder\GitInputValidator;
@@ -18,6 +19,7 @@ class GitInputValidatorTest extends TestCase
private array $subjectParameters;
private GitInputValidator $subject;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -26,6 +28,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/Process/ProcessRunnerTest.php b/tests/Unit/CommandLine/Process/ProcessRunnerTest.php
index f0fb35e..84ca9a8 100644
--- a/tests/Unit/CommandLine/Process/ProcessRunnerTest.php
+++ b/tests/Unit/CommandLine/Process/ProcessRunnerTest.php
@@ -7,6 +7,7 @@
use Hamcrest\MatcherAssert;
use Hamcrest\Matchers;
use Mockery;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
@@ -18,11 +19,13 @@ class ProcessRunnerTest extends TestCase
{
private ProcessRunner $subject;
+ #[Override]
protected function setUp(): void
{
$this->subject = new ProcessRunner();
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
@@ -79,13 +82,13 @@ public function runAsProcessReturningProcessObjectWithArgumentsInjection(): void
/**
* @test
+ * @doesNotPerformAssertions
*/
public function runProcessWithArguments(): void
{
$result = $this->subject->runAsProcess('git', 'version');
MatcherAssert::assertThat($result, Matchers::startsWith('git version'));
- self::assertTrue(true);
}
/**
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php
index 81753ef..64b1551 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/AllToolsCommandTest.php
@@ -9,6 +9,7 @@
use Mockery;
use Mockery\Matcher\Closure;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
@@ -23,9 +24,8 @@
/**
* Class AllToolsCommandTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class AllToolsCommandTest extends TestCase
{
private AllToolsCommand $subject;
@@ -43,6 +43,7 @@ class AllToolsCommandTest extends TestCase
private Application $mockedApplication;
private MockInterface|Command $mockedCommand;
+ #[Override]
protected function setUp(): void
{
$this->mockedInput = Mockery::mock(InputInterface::class);
@@ -64,6 +65,7 @@ protected function setUp(): void
$this->subject->setApplication($this->mockedApplication);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
@@ -107,9 +109,7 @@ public function executeCallsAllCommands(
->andReturn($optionsAndValues);
$this->mockedInput->shouldReceive('getOption')
->andReturnUsing(
- static function ($parameter) use ($optionsAndValues) {
- return $optionsAndValues[$parameter];
- },
+ static fn($parameter) => $optionsAndValues[$parameter],
);
$this->mockedOutput->shouldReceive('writeln')->once()
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php
index 97f51d4..cf1bdd0 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/FindFilesToCheckCommandTest.php
@@ -8,6 +8,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
@@ -23,9 +24,8 @@
/**
* Class FindFilesToCheckCommandTest
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class FindFilesToCheckCommandTest extends TestCase
{
/** @var array|array */
@@ -38,6 +38,38 @@ class FindFilesToCheckCommandTest extends TestCase
private string $expectedResult1 = 'phpunit.xml.dist';
private string $expectedResult2 = 'composer.json';
+ private static function assertSetDefinitionParams(InputDefinition $value): bool
+ {
+ MatcherAssert::assertThat($value, H::anInstanceOf(InputDefinition::class));
+ $options = $value->getOptions();
+ MatcherAssert::assertThat(
+ $options,
+ H::allOf(
+ H::arrayWithSize(6),
+ H::everyItem(
+ H::anInstanceOf(InputOption::class),
+ ),
+ ),
+ );
+ MatcherAssert::assertThat(
+ $value->getOption('target')->getDescription(),
+ H::equalTo('Finds files which have changed since the current branch parted from the target branch '
+ . 'only. The Value has to be a commit-ish.')
+ );
+ MatcherAssert::assertThat(
+ $value->getOption('auto-target')->getDescription(),
+ H::equalTo('Finds Files which have changed since the current branch parted from the parent branch '
+ . 'only. It tries to find the parent branch by automagic.')
+ );
+ MatcherAssert::assertThat(
+ $value->getOption('allowed-file-endings')->getDescription(),
+ H::equalTo('Only list files with appropriate file endings. For example .php for PHP-Files. '
+ . 'You may give multiple')
+ );
+ return true;
+ }
+
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -55,6 +87,7 @@ protected function setUp(): void
->withNoArgs()->andReturn($this->expectedResult2);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
@@ -87,19 +120,7 @@ public function configure(): void
->with(
Mockery::on(
static function ($value): bool {
- MatcherAssert::assertThat($value, H::anInstanceOf(InputDefinition::class));
- /** @var InputDefinition $value */
- $options = $value->getOptions();
- MatcherAssert::assertThat(
- $options,
- H::allOf(
- H::arrayWithSize(6),
- H::everyItem(
- H::anInstanceOf(InputOption::class),
- ),
- ),
- );
- return true;
+ return self::assertSetDefinitionParams($value);
},
),
)->andReturnSelf();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php
index e8c6902..237a069 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/AbstractToolCommandTest.php
@@ -8,6 +8,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use SebastianKnott\HamcrestObjectAccessor\HasProperty;
use Symfony\Component\Console\Input\InputInterface;
@@ -37,6 +38,7 @@ abstract class AbstractToolCommandTest extends TestCase
protected array $allowedFileEndings;
protected TerminalCommand $mockedTerminalCommand;
+ #[Override]
protected function setUp(): void
{
$this->mockedInput = Mockery::mock(InputInterface::class);
@@ -46,6 +48,7 @@ protected function setUp(): void
$this->mockedEventDispatcher = Mockery::mock(EventDispatcherInterface::class);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php
index 353e5de..a2d3a22 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/CodingStandardCommandEventTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleEvent;
@@ -25,6 +26,7 @@ class CodingStandardCommandEventTest extends TestCase
private array $forgedallowedFileEndings;
private MockInterface|TerminalCommand $mockedterminalCommand;
+ #[Override]
protected function setUp(): void
{
$this->mockedCommand = Mockery::mock(Command::class);
@@ -43,6 +45,7 @@ protected function setUp(): void
);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php
index 8fc950b..de2cdde 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/FixingToolCommandTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
@@ -24,6 +25,7 @@ abstract class FixingToolCommandTest extends TargetableToolsCommandTest
/** @var array */
protected array $mockedFixingArguments = [];
+ #[Override]
protected function setUp(): void
{
parent::setUp();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php
index 6e0282c..8ef3d81 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/NpmAppFinder/NpmCommandFinderTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Process;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
@@ -20,6 +21,7 @@ class NpmCommandFinderTest extends TestCase
/** @var array */
private array $subjectParameters;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -30,6 +32,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php
index ed75bbb..6560307 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TargetableToolsCommandTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
@@ -24,6 +25,7 @@ abstract class TargetableToolsCommandTest extends AbstractToolCommandTest
/** @var array */
protected array $mockedTargetingOptions;
+ #[Override]
protected function setUp(): void
{
parent::setUp();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php
index 12e3280..17105a9 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/AbstractTerminalCommandTest.php
@@ -7,6 +7,7 @@
use Exception;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Output\OutputInterface;
@@ -17,6 +18,7 @@ class AbstractTerminalCommandTest extends TestCase
private MockInterface|AbstractTerminalCommand $subject;
private MockInterface|OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedOutput = Mockery::mock(OutputInterface::class);
@@ -26,6 +28,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php
index ccf9b71..bc47203 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Exclusion/ExclusionDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -32,6 +33,7 @@ class ExclusionDecoratorTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -50,6 +52,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php
index 3abe195..c2ae61f 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Extension/ExtensionDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
@@ -24,6 +25,7 @@ class ExtensionDecoratorTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -35,6 +37,7 @@ protected function setUp(): void
$this->subject = new FileExtensionDecorator();
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php
index d3fb760..cd7af38 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Fix/FixDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -28,6 +29,7 @@ class FixDecoratorTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -41,6 +43,7 @@ protected function setUp(): void
$this->subject = new FixDecorator();
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php
index 29a6ba0..5e67167 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Multiprocess/MultiprocessDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
@@ -27,6 +28,7 @@ class MultiprocessDecoratorTest extends TestCase
private ProcessRunner $mockedProcessRunner;
private MultiprocessDecorator $subject;
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -40,6 +42,7 @@ protected function setUp(): void
$this->subject = new MultiprocessDecorator($this->mockedProcessRunner);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php
index ab17262..11ff818 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ComposerInterpreterTest.php
@@ -7,6 +7,7 @@
use JsonException;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -25,6 +26,7 @@ class ComposerInterpreterTest extends TestCase
private ComposerInterpreter $subject;
private FileSearchInterface $mockedFileSearchInterface;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -39,6 +41,7 @@ protected function setUp(): void
);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php
index 7aeeead..d06f8f6 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/ConstraintToVersionConverterTest.php
@@ -5,6 +5,7 @@
namespace Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion;
use Mockery;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ConstraintToVersionConverter;
@@ -12,11 +13,13 @@ class ConstraintToVersionConverterTest extends TestCase
{
private ConstraintToVersionConverter $subject;
+ #[Override]
protected function setUp(): void
{
$this->subject = new ConstraintToVersionConverter();
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php
index 98022aa..527f592 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/MinimalVersionDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
@@ -24,6 +25,7 @@ class MinimalVersionDecoratorTest extends TestCase
private MockInterface&OutputInterface $mockedOutput;
private MinimalVersionDecorator $subject;
+ #[Override]
protected function setUp(): void
{
$this->mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class);
@@ -36,6 +38,7 @@ protected function setUp(): void
$this->subject = new MinimalVersionDecorator($this->mockedComposerInterpreter);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php
index a6769a3..09852aa 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/PhpVersionConverterTest.php
@@ -5,6 +5,7 @@
namespace Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion;
use Mockery;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\PhpVersionConverter;
@@ -12,11 +13,13 @@ class PhpVersionConverterTest extends TestCase
{
private PhpVersionConverter $subject;
+ #[Override]
public function tearDown(): void
{
Mockery::close();
}
+ #[Override]
public function setUp(): void
{
$this->subject = new PhpVersionConverter();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php
index 601ddf4..1c6b6ff 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/PhpVersion/VersionDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\DecorateEvent;
@@ -23,6 +24,7 @@ class VersionDecoratorTest extends TestCase
private MockInterface&OutputInterface $mockedOutput;
private VersionDecorator $subject;
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -37,6 +39,7 @@ protected function setUp(): void
);
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php
index 0c06396..93aa23d 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/ParentBranchGuesserTest.php
@@ -7,6 +7,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\CommandLine\Process\ProcessRunner;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\Target\ParentBranchGuesser;
@@ -18,6 +19,7 @@ class ParentBranchGuesserTest extends TestCase
/** @var array|null */
private ?array $subjectParameters = null;
+ #[Override]
protected function setUp(): void
{
$subjectFactory = new SubjectFactory();
@@ -28,6 +30,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php
index c9a6e51..54a0a7e 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Target/TargetDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -23,9 +24,8 @@
/**
* This is a very busy test and needs all the objects ;/
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class TargetDecoratorTest extends TestCase
{
private TargetDecorator $subject;
@@ -43,6 +43,7 @@ class TargetDecoratorTest extends TestCase
private array $forgedAllowedFileEndings = ['asd', 'qwe'];
private string $forgedExclusionListToken = 'uptiwubti';
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -63,6 +64,7 @@ protected function setUp(): void
$this->subjectParameters = $buildFragments['parameters'];
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php
index 5cebe16..2af7189 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/Generic/TerminalCommand/Verbose/VerboseDecoratorTest.php
@@ -6,6 +6,7 @@
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -27,6 +28,7 @@ class VerboseDecoratorTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEvent = Mockery::mock(DecorateEvent::class);
@@ -40,6 +42,7 @@ protected function setUp(): void
$this->subject = new VerboseDecorator();
}
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php
index e85c83b..3db4c64 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/JSESLintCommandTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandFinder;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandNotFoundException;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSESLint\JSESLintCommand;
@@ -18,6 +19,7 @@ class JSESLintCommandTest extends FixingToolCommandTest
private Container|MockInterface $mockedContainer;
private NpmCommandFinder|MockInterface $mockedTerminalCommandFinder;
+ #[Override]
protected function setUp(): void
{
$this->terminalCommandName = 'EsLint';
@@ -59,6 +61,7 @@ public function configureSetsCorrectAttributes(): void
/**
* @test
*/
+ #[Override]
public function executeRunsTerminalCommand(): void
{
$this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once()
@@ -85,6 +88,7 @@ public function executeSkipsCommandIfNotFound(): void
/**
* @test
*/
+ #[Override]
public function executeWrappsException(): void
{
$this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once()
@@ -95,6 +99,7 @@ public function executeWrappsException(): void
/**
* @test
*/
+ #[Override]
public function executeWarnsAboutNoUsefulFilesToSniff(): void
{
$this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once()
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php
index a308fe3..30ed30c 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSESLint/TerminalCommandTest.php
@@ -8,6 +8,7 @@
use InvalidArgumentException;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -18,16 +19,17 @@
class TerminalCommandTest extends TestCase
{
- private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
- private const FORGED_RELATIV_ROOT = '.';
- private const FORGED_ABSOLUTE_ROOT = '/RootDirectory';
- private const FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor';
+ private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
+ private const string FORGED_RELATIV_ROOT = '.';
+ private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory';
+ private const string FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor';
private TerminalCommand $subject;
private MockInterface|Environment $mockedEnvironment;
private MockInterface|OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -44,6 +46,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
@@ -99,10 +102,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
/**
* This data provider needs to be long because it contains all testing data.
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return array>
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
public function terminalCommandCompilationDataProvider(): array
{
return [
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php
index f1593c6..a2871ef 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/JSStyleLintCommandTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandFinder;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\NpmAppFinder\NpmCommandNotFoundException;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\JSStyleLint\JSStyleLintCommand;
@@ -20,6 +21,7 @@ class JSStyleLintCommandTest extends FixingToolCommandTest
/** @var NpmCommandFinder|MockInterface */
private NpmCommandFinder $mockedTerminalCommandFinder;
+ #[Override]
protected function setUp(): void
{
$this->terminalCommandName = 'StyleLint';
@@ -47,6 +49,7 @@ protected function setUp(): void
/**
* @test
*/
+ #[Override]
public function executeRunsTerminalCommand(): void
{
$this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once()
@@ -57,6 +60,7 @@ public function executeRunsTerminalCommand(): void
/**
* @test
*/
+ #[Override]
public function executeWrappsException(): void
{
$this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once()
@@ -97,6 +101,7 @@ public function executeSkipsCommandIfNotFound(): void
/**
* @test
*/
+ #[Override]
public function executeWarnsAboutNoUsefulFilesToSniff(): void
{
$this->mockedTerminalCommandFinder->shouldReceive('findTerminalCommand')->once()
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php
index 5e07a0d..2e4813b 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/JSStyleLint/TerminalCommandTest.php
@@ -8,6 +8,7 @@
use InvalidArgumentException;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -18,10 +19,10 @@
class TerminalCommandTest extends TestCase
{
- private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
- private const FORGED_RELATIV_ROOT = '.';
- private const FORGED_ABSOLUTE_ROOT = '/RootDirectory';
- private const FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor';
+ private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
+ private const string FORGED_RELATIV_ROOT = '.';
+ private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory';
+ private const string FORGED_ABSOLUTE_VENDOR = '/RootDirectory/vendor';
private TerminalCommand $subject;
/** @var MockInterface|\Zooroyal\CodingStandard\CommandLine\Environment\Environment */
@@ -29,6 +30,7 @@ class TerminalCommandTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -45,6 +47,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
@@ -94,10 +97,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
/**
* This data provider needs to be long because it contains all testing data.
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return array>
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
public function terminalCommandCompilationDataProvider(): array
{
return [
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php
index d287069..0ef99f8 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/PHPCodeSnifferCommandTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\PHPCodeSnifferCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCodeSniffer\TerminalCommand;
use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\FixingToolCommandTest;
@@ -16,6 +17,7 @@ class PHPCodeSnifferCommandTest extends FixingToolCommandTest
/** @var Container|MockInterface */
private Container $mockedContainer;
+ #[Override]
protected function setUp(): void
{
$this->terminalCommandName = 'PHP Code Sniffer';
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php
index 6037c01..9aa14e9 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCodeSniffer/TerminalCommandTest.php
@@ -8,6 +8,7 @@
use InvalidArgumentException;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -19,15 +20,16 @@
class TerminalCommandTest extends TestCase
{
- private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
- private const FORGED_RELATIV_ROOT = '.';
- private const FORGED_ABSOLUTE_VENDOR = '/vendor';
+ private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
+ private const string FORGED_RELATIV_ROOT = '.';
+ private const string FORGED_ABSOLUTE_VENDOR = '/vendor';
private TerminalCommand $subject;
private MockInterface|Environment $mockedEnvironment;
private MockInterface|PhpVersionConverter $mockedPhpVersionConverter;
private MockInterface|OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -45,6 +47,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
@@ -100,10 +103,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
/**
* This data provider needs to be long because it contains all testing data.
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return array>
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
public function terminalCommandCompilationDataProvider(): array
{
$mockedEnhancedFileInfo1 = Mockery::mock(EnhancedFileInfo::class);
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php
index 6133650..65326b5 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/PHPCopyPasteDetectorCommandTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\PHPCopyPasteDetectorCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPCopyPasteDetector\TerminalCommand;
use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\AbstractToolCommandTest;
@@ -16,6 +17,7 @@ class PHPCopyPasteDetectorCommandTest extends AbstractToolCommandTest
/** @var Container|MockInterface */
private Container $mockedContainer;
+ #[Override]
protected function setUp(): void
{
$this->terminalCommandName = 'PHP Copy Paste Detector';
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php
index be89675..fa6dea3 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPCopyPasteDetector/TerminalCommandTest.php
@@ -7,6 +7,7 @@
use Hamcrest\Matchers;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -17,10 +18,10 @@
class TerminalCommandTest extends TestCase
{
- private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
- private const FORGED_RELATIV_ROOT = '.';
- private const FORGED_ABSOLUTE_ROOT = '/RootDirectory';
- private const FORGED_ABSOLUTE_VENDOR = '/vendor';
+ private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
+ private const string FORGED_RELATIV_ROOT = '.';
+ private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory';
+ private const string FORGED_ABSOLUTE_VENDOR = '/vendor';
private TerminalCommand $subject;
/** @var MockInterface|\Zooroyal\CodingStandard\CommandLine\Environment\Environment */
@@ -30,6 +31,7 @@ class TerminalCommandTest extends TestCase
/** @var MockInterface|ProcessRunner */
private ProcessRunner $mockedProcessRunner;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -49,6 +51,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
@@ -100,10 +103,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
/**
* This data provider needs to be long because it contains all testing data.
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return array>
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
public function terminalCommandCompilationDataProvider(): array
{
return [
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php
deleted file mode 100644
index 466ea04..0000000
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/PHPMessDetectorCommandTest.php
+++ /dev/null
@@ -1,55 +0,0 @@
-terminalCommandName = 'PHP Mess Detector';
- $this->terminalCommandType = TerminalCommand::class;
- $this->exclusionToken = '.dontMessDetectPHP';
- $this->allowedFileEndings = ['php'];
- $this->mockedTerminalCommand = Mockery::mock(TerminalCommand::class);
- $this->mockedContainer = Mockery::mock(Container::class);
-
- $this->mockedContainer->shouldReceive('make')->atLeast()->once()
- ->with(TerminalCommand::class)
- ->andReturn($this->mockedTerminalCommand);
-
- parent::setUp();
-
- $this->subject = new PHPMessDetectorCommand($this->mockedTargetableInputFacet);
- $this->subject->injectDependenciesToolCommand(
- $this->mockedTerminalCommandRunner,
- $this->mockedEventDispatcher,
- );
- $this->subject->injectDependenciesCommand($this->mockedContainer);
- }
-
- /**
- * @test
- */
- public function configureSetsCorrectAttributes(): void
- {
- self::assertSame('sca:mess-detect', $this->subject->getName());
- self::assertSame('Run PHP-MD on PHP files.', $this->subject->getDescription());
- self::assertSame(
- 'This tool executes PHP-MD on a certain set of PHP files of this project. It ignores files which are in '
- . 'directories with a .dontMessDetectPHP file. Subdirectories are ignored too.',
- $this->subject->getHelp(),
- );
- }
-}
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php
deleted file mode 100644
index e89d7ae..0000000
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPMessDetector/TerminalCommandTest.php
+++ /dev/null
@@ -1,171 +0,0 @@
-mockedEnvironment = Mockery::mock(Environment::class);
- $this->mockedOutput = Mockery::mock(OutputInterface::class);
-
- $this->mockedEnvironment->shouldReceive('getPackageDirectory->getRealPath')
- ->andReturn(self::FORGED_PACKAGE_DIRECTORY);
- $this->mockedEnvironment->shouldReceive('getRootDirectory->getRelativePathname')
- ->andReturn(self::FORGED_RELATIV_ROOT);
- $this->mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')
- ->andReturn(self::FORGED_ABSOLUTE_ROOT);
- $this->mockedEnvironment->shouldReceive('getVendorDirectory->getRealPath')
- ->andReturn(self::FORGED_ABSOLUTE_VENDOR);
-
- $this->subject = new TerminalCommand($this->mockedEnvironment);
- $this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
- }
-
- public function tearDown(): void
- {
- Mockery::close();
- }
-
- /**
- * @test
- * @dataProvider terminalCommandCompilationDataProvider
- */
- public function terminalCommandCompilation(TerminalCommandTestData $data): void
- {
- $this->mockedOutput->shouldReceive('writeln')->once()
- ->with(
- Matchers::startsWith(
- 'Compiled TerminalCommand to following string'
- . PHP_EOL . $data->getExpectedCommand(),
- ),
- OutputInterface::VERBOSITY_VERY_VERBOSE,
- );
-
- $this->subject->addAllowedFileExtensions($data->getExtensions());
- $this->subject->addExclusions($data->getExcluded());
- if ($data->getTargets() !== null) {
- $this->subject->addTargets($data->getTargets());
- }
-
- $result = (string) $this->subject;
- $resultingArray = $this->subject->toArray();
-
- self::assertSame($data->getExpectedCommand(), $result);
- self::assertSame($result, implode(' ', $resultingArray));
- }
-
- /**
- * This data provider needs to be long because it contains all testing data.
- *
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
- * @return array>
- */
- public function terminalCommandCompilationDataProvider(): array
- {
- $mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class);
- $mockedEnhancedFileInfoExcluded1->shouldReceive('getRealPath')
- ->andReturnValues(['a', 'b']);
- $mockedEnhancedFileInfoExcluded2 = Mockery::mock(EnhancedFileInfo::class);
- $mockedEnhancedFileInfoExcluded2->shouldReceive('getRealPath')
- ->andReturnValues(['a', 'b']);
- $mockedEnhancedFileInfoTarget1 = Mockery::mock(EnhancedFileInfo::class);
- $mockedEnhancedFileInfoTarget1->shouldReceive('getRealPath')
- ->andReturnValues(['c', 'd']);
- $mockedEnhancedFileInfoTarget2 = Mockery::mock(EnhancedFileInfo::class);
- $mockedEnhancedFileInfoTarget2->shouldReceive('getRealPath')
- ->andReturnValues(['c', 'd']);
-
- return [
- 'all' => [
- new TerminalCommandTestData(
- [
- 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd c,d text '
- . self::FORGED_PACKAGE_DIRECTORY
- . '/config/phpmd/phpmd.xml --suffixes qweasd,argh --exclude a,b',
- 'excluded' => [$mockedEnhancedFileInfoExcluded1, $mockedEnhancedFileInfoExcluded1],
- 'extensions' => ['qweasd', 'argh'],
- 'targets' => [$mockedEnhancedFileInfoTarget1, $mockedEnhancedFileInfoTarget1],
- ],
- ),
- ],
- 'empty optionals' => [
- new TerminalCommandTestData(
- [
- 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd '
- . self::FORGED_ABSOLUTE_ROOT . ' text ' . self::FORGED_PACKAGE_DIRECTORY
- . '/config/phpmd/phpmd.xml',
- ],
- ),
- ],
- 'excluding' => [
- new TerminalCommandTestData(
- [
- 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd '
- . self::FORGED_ABSOLUTE_ROOT . ' text ' . self::FORGED_PACKAGE_DIRECTORY
- . '/config/phpmd/phpmd.xml --exclude a,b',
- 'excluded' => [$mockedEnhancedFileInfoExcluded2, $mockedEnhancedFileInfoExcluded2],
- ],
- ),
- ],
- 'extensions' => [
- new TerminalCommandTestData(
- [
- 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd '
- . self::FORGED_ABSOLUTE_ROOT . ' text ' . self::FORGED_PACKAGE_DIRECTORY
- . '/config/phpmd/phpmd.xml --suffixes asdqwe,qweasd',
- 'extensions' => ['asdqwe', 'qweasd'],
- ],
- ),
- ],
- 'targeted' => [
- new TerminalCommandTestData(
- [
- 'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR . '/bin/phpmd c,d text ' .
- self::FORGED_PACKAGE_DIRECTORY . '/config/phpmd/phpmd.xml',
- 'targets' => [$mockedEnhancedFileInfoTarget2, $mockedEnhancedFileInfoTarget2],
- ],
- ),
- ],
- ];
- }
-
- /**
- * @test
- */
- public function terminalCommandCompilationThrowsExceptionOnNoFilesToCheck(): void
- {
- $this->expectException(NoUsefulCommandFoundException::class);
- $this->expectExceptionCode(1620831304);
- $this->expectExceptionMessage('It makes no sense to sniff no files.');
-
- $this->subject->addTargets([]);
-
- $this->subject->__toString();
- }
-}
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php
index 297a9f8..39c67d1 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/PHPParallelLintCommandTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\PHPParallelLintCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPParallelLint\TerminalCommand;
use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommandTest;
@@ -16,6 +17,7 @@ class PHPParallelLintCommandTest extends TargetableToolsCommandTest
/** @var Container|MockInterface */
private Container $mockedContainer;
+ #[Override]
protected function setUp(): void
{
$this->terminalCommandName = 'PHP Parallel Lint';
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php
index dc67471..539c2d4 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPParallelLint/TerminalCommandTest.php
@@ -7,6 +7,7 @@
use Hamcrest\Matchers;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -17,10 +18,10 @@
class TerminalCommandTest extends TestCase
{
- private const FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
- private const FORGED_RELATIV_ROOT = '.';
- private const FORGED_ABSOLUTE_ROOT = '/RootDirectory';
- private const FORGED_ABSOLUTE_VENDOR = '/vendor';
+ private const string FORGED_PACKAGE_DIRECTORY = '/packageDirectory';
+ private const string FORGED_RELATIV_ROOT = '.';
+ private const string FORGED_ABSOLUTE_ROOT = '/RootDirectory';
+ private const string FORGED_ABSOLUTE_VENDOR = '/vendor';
private TerminalCommand $subject;
/** @var MockInterface|\Zooroyal\CodingStandard\CommandLine\Environment\Environment */
@@ -28,6 +29,7 @@ class TerminalCommandTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -46,6 +48,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
@@ -83,10 +86,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
/**
* This data provider needs to be long because it contains all testing data.
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return array>
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
public function terminalCommandCompilationDataProvider(): array
{
$mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class);
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php
index 1002e9d..42dd3b9 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanCommandTest.php
@@ -7,6 +7,7 @@
use DI\Container;
use Mockery;
use Mockery\MockInterface;
+use Override;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\PHPStanCommand;
use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\PHPStan\TerminalCommand;
use Zooroyal\CodingStandard\Tests\Unit\CommandLine\StaticCodeAnalysis\Generic\TargetableToolsCommandTest;
@@ -16,6 +17,7 @@ class PHPStanCommandTest extends TargetableToolsCommandTest
/** @var Container|MockInterface */
private Container $mockedContainer;
+ #[Override]
protected function setUp(): void
{
$this->terminalCommandName = 'PHPStan';
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php
index 4e199b5..211ea9d 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/PHPStanConfigGeneratorTest.php
@@ -9,6 +9,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
@@ -33,6 +34,7 @@ class PHPStanConfigGeneratorTest extends TestCase
/** @var array */
private array $forgedExcludedFilePaths = ['a', 'b'];
+ #[Override]
protected function setUp(): void
{
$this->mockedFilesystem = Mockery::mock(Filesystem::class);
@@ -62,6 +64,7 @@ protected function setUp(): void
);
}
+ #[Override]
protected function assertPostConditions(): void
{
Mockery::close();
diff --git a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php
index 26e01c3..feded81 100644
--- a/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php
+++ b/tests/Unit/CommandLine/StaticCodeAnalysis/PHPStan/TerminalCommandTest.php
@@ -8,6 +8,7 @@
use InvalidArgumentException;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Zooroyal\CodingStandard\CommandLine\EnhancedFileInfo\EnhancedFileInfo;
@@ -18,11 +19,11 @@
class TerminalCommandTest extends TestCase
{
- private const PACKAGE_DIRECTORY = '/packageDirectory';
- private const RELATIVE_ROOT = '.';
- private const ABSOLUTE_ROOT = '/RootDirectory';
- private const ABSOLUTE_VENDOR = '/vendor';
- private const ABSOLUTE_CONFIG = '/packageDirectory/config/phpstan/phpstan.neon';
+ private const string PACKAGE_DIRECTORY = '/packageDirectory';
+ private const string RELATIVE_ROOT = '.';
+ private const string ABSOLUTE_ROOT = '/RootDirectory';
+ private const string ABSOLUTE_VENDOR = '/vendor';
+ private const string ABSOLUTE_CONFIG = '/packageDirectory/config/phpstan/phpstan.neon';
private TerminalCommand $subject;
/** @var MockInterface|Environment */
@@ -30,6 +31,7 @@ class TerminalCommandTest extends TestCase
/** @var MockInterface|OutputInterface */
private OutputInterface $mockedOutput;
+ #[Override]
protected function setUp(): void
{
$this->mockedEnvironment = Mockery::mock(Environment::class);
@@ -48,6 +50,7 @@ protected function setUp(): void
$this->subject->injectDependenciesAbstractTerminalCommand($this->mockedOutput);
}
+ #[Override]
public function tearDown(): void
{
Mockery::close();
@@ -96,10 +99,9 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
/**
* This data provider needs to be long because it contains all testing data.
*
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- *
* @return array>
*/
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
public function terminalCommandCompilationDataProvider(): array
{
$mockedEnhancedFileInfoExcluded1 = Mockery::mock(EnhancedFileInfo::class);
diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php
new file mode 100644
index 0000000..8a2c237
--- /dev/null
+++ b/tests/Unit/Sniffs/ObjectsCallisthenics/FileFactory.php
@@ -0,0 +1,45 @@
+setContent($fileContent);
+ $file->parse();
+
+ return $file;
+ }
+}
diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc
new file mode 100644
index 0000000..a290b2d
--- /dev/null
+++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/ClassAnalyzerSource/SomeFile.php.inc
@@ -0,0 +1,21 @@
+file = $fileFactory->createFile(__DIR__ . '/ClassAnalyzerSource/SomeFile.php.inc');
+ }
+
+ public function testMethodCount(): void
+ {
+ $this->assertSame(2, ClassAnalyzer::getClassMethodCount($this->file, self::CLASS_POSITION));
+ }
+
+ public function testProperties(): void
+ {
+ $properties = ClassAnalyzer::getClassProperties($this->file, self::CLASS_POSITION);
+
+ $this->assertCount(1, $properties);
+ }
+
+ public function testPropertyCount(): void
+ {
+ $this->assertSame(1, ClassAnalyzer::getClassPropertiesCount($this->file, self::CLASS_POSITION));
+ }
+}
diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc
new file mode 100644
index 0000000..8dfbd03
--- /dev/null
+++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/NamingSource/SomeFile.php.inc
@@ -0,0 +1,10 @@
+fileFactory = new FileFactory();
+ }
+
+ public function test(): void
+ {
+ $file = $this->fileFactory->createFile(__DIR__ . '/NamingSource/SomeFile.php.inc');
+
+ $name = NamingHelper::getElementName($file, self::CLASS_POSITION);
+ $this->assertSame('SomeClass', $name);
+
+ $name = NamingHelper::getElementName($file, self::CONSTANT_POSITION);
+ $this->assertSame('SOME_CONSTANT', $name);
+
+ $name = NamingHelper::getElementName($file, self::PROPERTY_POSITION);
+ $this->assertSame('someProperty', $name);
+ }
+}
diff --git a/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc
new file mode 100644
index 0000000..c2046d9
--- /dev/null
+++ b/tests/Unit/Sniffs/ObjectsCallisthenics/Standards/ZooRoyal/Helper/PropertyHelperSource/SomeFile.php.inc
@@ -0,0 +1,12 @@
+assignment = $argument;
+ $variable = 5;
+ }
+}
diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php
new file mode 100644
index 0000000..a27a802
--- /dev/null
+++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Naming/NameLengthSniffTest.php
@@ -0,0 +1,283 @@
+subject = new NameLengthSniff();
+ }
+
+ protected function tearDown(): void
+ {
+ Mockery::close();
+ }
+
+ /**
+ * @test
+ * @dataProvider processHappyPathDataProvider
+ */
+ public function processHappyPath(string $name): void
+ {
+ $mockedFile = mock(File::class);
+ $forgedStackPointer = 0;
+ $forgedTokens = [ $forgedStackPointer => ['content' => $name]];
+
+ $mockedFile->expects()->getTokens()->andReturn($forgedTokens);
+ $mockedFile->shouldNotReceive('addError');
+
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+ /** @return array> */
+ public function processHappyPathDataProvider(): array
+ {
+ return [
+ 'Good Name' => ['name' => 'aaaaaaa'],
+ 'Almost too short name' => ['name' => 'aaa'],
+ 'Almost too long name' => ['name' => str_pad('a', 70, 'a')],
+ 'i' => ['name' => '$i'],
+ ];
+ }
+
+ /**
+ * @test
+ * @runInSeparateProcess
+ * @preserveGlobalState false
+ * @dataProvider processReportsErrorIfClassysAreBadDataProvider
+ */
+ public function processReportsErrorIfClassysAreBad(
+ string $token,
+ string $name,
+ string $errorMessage,
+ string $code,
+ int $length,
+ ): void {
+ $mockedFile = mock(File::class);
+ $mockedClassHelper = mock('overload:' . ClassHelper::class);
+
+ $forgedStackPointer = 0;
+ $forgedTokens = [ $forgedStackPointer => ['content' => $token]];
+
+ $mockedFile->expects()->getTokens()->andReturn($forgedTokens);
+ $mockedClassHelper->expects()->getName($mockedFile, $forgedStackPointer)->andReturn($name);
+
+ $mockedFile->expects()->addError(
+ $errorMessage,
+ $forgedStackPointer,
+ $code,
+ [$name, $length]
+ );
+
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+
+ /** @return array> */
+ // phpcs:ignore SlevomatCodingStandard.Functions.FunctionLength
+ public function processReportsErrorIfClassysAreBadDataProvider(): array
+ {
+ return [
+ 'class too short' => [
+ 'token' => 'class',
+ 'name' => 'aa',
+ 'errorMessage' => 'Name "%s" is less than %s characters long',
+ 'code' => 'NameTooShort',
+ 'length' => 3,
+ ],
+ 'class too long' => [
+ 'token' => 'class',
+ 'name' => str_pad('', 71, 'a'),
+ 'errorMessage' => 'Name "%s" is greater than %s characters long',
+ 'code' => 'NameTooLong',
+ 'length' => 70,
+ ],
+ 'trait too short' => [
+ 'token' => 'trait',
+ 'name' => 'aa',
+ 'errorMessage' => 'Name "%s" is less than %s characters long',
+ 'code' => 'NameTooShort',
+ 'length' => 3,
+ ],
+ 'trait too long' => [
+ 'token' => 'trait',
+ 'name' => str_pad('$', 71, 'a'),
+ 'errorMessage' => 'Name "%s" is greater than %s characters long',
+ 'code' => 'NameTooLong',
+ 'length' => 70,
+ ],
+ 'interface too short' => [
+ 'token' => 'interface',
+ 'name' => 'aa',
+ 'errorMessage' => 'Name "%s" is less than %s characters long',
+ 'code' => 'NameTooShort',
+ 'length' => 3,
+ ],
+ 'interface too long' => [
+ 'token' => 'interface',
+ 'name' => str_pad('$', 71, 'a'),
+ 'errorMessage' => 'Name "%s" is greater than %s characters long',
+ 'code' => 'NameTooLong',
+ 'length' => 70,
+ ],
+ ];
+ }
+
+ /**
+ * @test
+ * @runInSeparateProcess
+ * @preserveGlobalState false
+ * @dataProvider processReportsErrorIfFunctionIsBadDataProvider
+ */
+ public function processReportsErrorIfFunctionIsBad(
+ string $functionName,
+ string $errorMessage,
+ string $code,
+ int $length,
+ ): void {
+ $mockedFile = Mockery::mock(File::class);
+ $mockedFunctionHelper = mock('overload:' . FunctionHelper::class);
+
+ $forgedStackPointer = 0;
+ $forgedTokens = [ $forgedStackPointer => ['content' => 'function']];
+
+ $mockedFile->expects()->getTokens()->andReturn($forgedTokens);
+ $mockedFunctionHelper->expects()->getName($mockedFile, $forgedStackPointer)->andReturn($functionName);
+ $mockedFile->expects()->addError(
+ $errorMessage,
+ $forgedStackPointer,
+ $code,
+ [$functionName, $length]
+ );
+
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+ /** @return array> */
+ public function processReportsErrorIfFunctionIsBadDataProvider(): array
+ {
+ return [
+ 'too short' => [
+ 'functionName' => 'a',
+ 'errorMessage' => 'Name "%s" is less than %s characters long',
+ 'code' => 'NameTooShort',
+ 'length' => 3,
+ ],
+ 'too long' => [
+ 'functionName' => str_pad('a', 71, 'a'),
+ 'errorMessage' => 'Name "%s" is greater than %s characters long',
+ 'code' => 'NameTooLong',
+ 'length' => 70,
+ ],
+ ];
+ }
+
+ /**
+ * @test
+ *
+ * @dataProvider processReportsErrorIfVariableIsBadDataProvider
+ */
+ public function processReportsErrorIfVariableIsBad(
+ string $variable,
+ string $errorMessage,
+ string $code,
+ int $length,
+ ): void {
+ $mockedFile = mock(File::class);
+ $forgedStackPointer = 0;
+ $forgedTokens = [ $forgedStackPointer => ['content' => $variable]];
+
+ $mockedFile->expects()->getTokens()->andReturn($forgedTokens);
+ $mockedFile->expects()->addError(
+ $errorMessage,
+ $forgedStackPointer,
+ $code,
+ [ltrim($variable, '$'), $length]
+ );
+
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+ /** @return array> */
+ public function processReportsErrorIfVariableIsBadDataProvider(): array
+ {
+ return [
+ 'too short' => [
+ 'variable' => '$a',
+ 'errorMessage' => 'Name "%s" is less than %s characters long',
+ 'code' => 'NameTooShort',
+ 'length' => 3,
+ ],
+ 'too long' => [
+ 'variable' => str_pad('$', 72, 'a'),
+ 'errorMessage' => 'Name "%s" is greater than %s characters long',
+ 'code' => 'NameTooLong',
+ 'length' => 70,
+ ],
+ ];
+ }
+
+ /**
+ * @test
+ */
+ public function registerReturnsExpectedTokens(): void
+ {
+ $expected = [T_VARIABLE, T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT, T_PROPERTY];
+ $this->assertEquals($expected, $this->subject->register());
+ }
+
+ /**
+ * @test
+ */
+ public function processWithConfiguredMaximum(): void
+ {
+ $mockedFile = mock(File::class);
+ $forgedStackPointer = 0;
+ $variable = str_pad('$', 40, 'a');
+ $forgedTokens = [ $forgedStackPointer => ['content' => $variable]];
+
+ $mockedFile->expects()->getTokens()->andReturn($forgedTokens);
+ $mockedFile->expects()->addError(
+ 'Name "%s" is greater than %s characters long',
+ $forgedStackPointer,
+ 'NameTooLong',
+ [ltrim($variable, '$'), 30]
+ );
+
+ $this->subject->maximumLength = 30;
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+ /**
+ * @test
+ */
+ public function processWithConfiguredMinimum(): void
+ {
+ $mockedFile = mock(File::class);
+ $forgedStackPointer = 0;
+ $variable = str_pad('$', 29, 'a');
+ $forgedTokens = [ $forgedStackPointer => ['content' => $variable]];
+
+ $mockedFile->expects()->getTokens()->andReturn($forgedTokens);
+ $mockedFile->expects()->addError(
+ 'Name "%s" is less than %s characters long',
+ $forgedStackPointer,
+ 'NameTooShort',
+ [ltrim($variable, '$'), 30]
+ );
+
+ $this->subject->minimumLength = 30;
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+}
diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
index c06382b..7d07a5a 100644
--- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
+++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/Safe/CheckSafeFunctionUsageSniffTest.php
@@ -6,22 +6,50 @@
use DI\Container;
use Mockery;
+use Mockery\MockInterface;
+use org\bovigo\vfs\vfsStream;
+use org\bovigo\vfs\vfsStreamDirectory;
+use Override;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
+use PhpParser\NodeFinder;
+use PhpParser\Parser;
+use PhpParser\ParserFactory;
+use PhpParser\PhpVersion;
use PHPUnit\Framework\TestCase;
use RuntimeException;
+use SlevomatCodingStandard\Helpers\TokenHelper;
+use SlevomatCodingStandard\Helpers\UseStatement;
+use SlevomatCodingStandard\Helpers\UseStatementHelper;
+use Symfony\Component\Filesystem\Filesystem;
use Zooroyal\CodingStandard\CommandLine\ApplicationLifeCycle\ContainerFactory;
use Zooroyal\CodingStandard\CommandLine\Environment\Environment;
+use Zooroyal\CodingStandard\CommandLine\StaticCodeAnalysis\Generic\TerminalCommand\PhpVersion\ComposerInterpreter;
use Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\Safe\CheckSafeFunctionUsageSniff;
+// phpcs:ignore ZooRoyal.TypeHints.LimitUseStatement.TooManyUseStatements
class CheckSafeFunctionUsageSniffTest extends TestCase
{
+ private const string SAFE_VENDOR_PATH = '/vendor/thecodingmachine/safe/generated/8.4/';
+
+ private vfsStreamDirectory $vfsRootDirectory;
+ private vfsStreamDirectory $vfsSafeDirectory;
+
+ #[Override]
protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $this->vfsRootDirectory = vfsStream::setup('checkSafe');
+ $this->vfsSafeDirectory = vfsStream::newDirectory(self::SAFE_VENDOR_PATH, 0777);
+ $this->vfsRootDirectory->addChild($this->vfsSafeDirectory);
+ }
+
/**
* @test
*/
@@ -31,26 +59,74 @@ public function constructTheSniff(): void
self::assertInstanceOf(Sniff::class, $subject);
}
+ private function prepareMocksForAssertNextTokenParenthesisOpener(
+ MockInterface&File $mockedFile,
+ int $forgedPointer,
+ ): MockInterface&TokenHelper {
+ // Mocks for assertNextTokenParenthesisOpener
+ $mockedTokenHelper = Mockery::mock('overload:' . TokenHelper::class);
+ $mockedTokenHelper->expects()->findNextEffective($mockedFile, $forgedPointer + 1)
+ ->andReturn($forgedPointer + 1);
+ return $mockedTokenHelper;
+ }
+
+ private function prepareMocksForAssertFunctionUnused(MockInterface&File $mockedFile): void
+ {
+ // Mocks for assertFunctionUnused
+ $mockedUseStatementFunctionUninteresting = Mockery::mock(UseStatement::class);
+ $mockedUseStatement = Mockery::mock(UseStatement::class);
+ $forgedUseStatementResults = [
+ 17 => [
+ 'overwrite' => $mockedUseStatementFunctionUninteresting,
+ 'sniff' => $mockedUseStatement,
+ ],
+ ];
+ $mockedUseStatementHelper = Mockery::mock('overload:' . UseStatementHelper::class);
+ $mockedUseStatementHelper->expects()->getFileUseStatements($mockedFile)->andReturn($forgedUseStatementResults);
+ $mockedUseStatementFunctionUninteresting->expects()->getType()->andReturn('function');
+ $mockedUseStatement->expects()->getType()->andReturn('no function');
+ $mockedUseStatementFunctionUninteresting->expects()->getNameAsReferencedInFile()->andReturn('argh');
+ }
+
+ private function prepareMocksForAssertGlobalFunctionCall(
+ MockInterface&TokenHelper $mockedTokenHelper,
+ MockInterface&File $mockedFile,
+ int $forgedPointer,
+ ): void {
+ // Mocks for assertGlobalFunctionCall
+ $mockedTokenHelper->expects()->findPreviousEffective($mockedFile, $forgedPointer - 1)
+ ->andReturn($forgedPointer - 1);
+ }
+
/**
* @test
*
* @runInSeparateProcess
* @preserveGlobalState disabled
+ * @dataProvider notFoundSafeLibrarySkipsProcessDataProvider
*/
- public function notFoundSafeLibrarySkippsProcess(): void
+ public function notFoundSafeLibrarySkipsProcess(string $environmentPath, bool $dirExists): void
{
$mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class);
$mockedContainer = Mockery::mock(Container::class);
$mockedEnvironment = Mockery::mock(Environment::class);
$mockedFile = Mockery::mock(File::class);
+ $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class);
+ $mockedFilesystem = mock(Filesystem::class);
$mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer);
$mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment);
- $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn('/foo/bar');
+ $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter);
+ $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem);
+ $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn($environmentPath);
+ $mockedFilesystem->expects()->exists($environmentPath . self::SAFE_VENDOR_PATH)
+ ->andReturn($dirExists);
+
+ $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3');
$this->expectExceptionObject(
new RuntimeException(
- 'No function names found! Did you forget to install thecodingmachine/Safe?',
+ 'No function names found! Did you forget to install thecodingmachine/Safe ^v3?',
1684240278,
),
);
@@ -59,6 +135,182 @@ public function notFoundSafeLibrarySkippsProcess(): void
$subject->process($mockedFile, 0);
}
+ /** @return array> */
+ public function notFoundSafeLibrarySkipsProcessDataProvider(): array
+ {
+ return [
+ 'no Path' => ['environmentPath' => '/foo/bar', 'dirExists' => true],
+ 'scandir empty' => ['environmentPath' => __DIR__, 'dirExists' => false],
+ ];
+ }
+
+ /**
+ * @test
+ *
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function processAddsError(): void
+ {
+ $forgedPointer = 100;
+ $forgedSafeFunctionName = 'foo';
+ $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn(
+ [
+ $forgedPointer - 1 => ['code' => T_WHITESPACE],
+ $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'],
+ $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS],
+ ],
+ );
+ $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer);
+ $this->prepareMocksForAssertGlobalFunctionCall($mockedTokenHelper, $mockedFile, $forgedPointer);
+ $this->prepareMocksForAssertFunctionUnused($mockedFile);
+
+ // Finish with the key assertion
+
+ $mockedFile->expects()->addError(
+ 'Function \'' . $forgedSafeFunctionName
+ . '\' is not imported from Safe! Add \'use function Safe\foo;\' to your uses.',
+ $forgedPointer,
+ 'FunctionNotImported'
+ );
+
+ $subject = new CheckSafeFunctionUsageSniff();
+ $subject->process($mockedFile, $forgedPointer);
+ }
+
+ /**
+ * @test
+ *
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function processAddsNoErrorBecauseOfParenthesisCheck(): void
+ {
+ $forgedPointer = 100;
+ $forgedSafeFunctionName = 'foo';
+ $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn(
+ [
+ $forgedPointer - 1 => ['code' => T_OBJECT_OPERATOR],
+ $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'],
+ $forgedPointer + 1 => ['code' => T_STRING],
+ ],
+ );
+
+ $mockedTokenHelper = Mockery::mock('overload:' . TokenHelper::class);
+ $mockedTokenHelper->expects()->findNextEffective($mockedFile, $forgedPointer + 1)
+ ->andReturn($forgedPointer + 1);
+
+ $mockedFile->shouldNotReceive('addError');
+
+ $subject = new CheckSafeFunctionUsageSniff();
+ $subject->process($mockedFile, $forgedPointer);
+ }
+
+ /**
+ * @test
+ *
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function processAddsNoErrorBecauseGlobalFunction(): void
+ {
+ $forgedPointer = 100;
+ $forgedSafeFunctionName = 'foo';
+ $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn(
+ [
+ $forgedPointer - 1 => ['code' => T_FUNCTION],
+ $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'],
+ $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS],
+ ],
+ );
+
+ $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer);
+ $mockedTokenHelper->expects()->findPreviousEffective($mockedFile, $forgedPointer - 1)
+ ->andReturn($forgedPointer - 1);
+
+ $mockedFile->shouldNotReceive('addError');
+
+ $subject = new CheckSafeFunctionUsageSniff();
+ $subject->process($mockedFile, $forgedPointer);
+ }
+
+ /**
+ * @test
+ *
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function processAddsNoErrorBecauseNotSafeFunction(): void
+ {
+ $forgedPointer = 100;
+ $forgedSafeFunctionName = 'foo';
+ $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn(
+ [
+ $forgedPointer - 1 => ['code' => T_WHITESPACE],
+ $forgedPointer => ['code' => T_STRING, 'content' => 'Woo'],
+ $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS],
+ ],
+ );
+ $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer);
+ $this->prepareMocksForAssertGlobalFunctionCall($mockedTokenHelper, $mockedFile, $forgedPointer);
+
+ // Finish with the key assertion
+
+ $mockedFile->shouldNotReceive('addError');
+
+ $subject = new CheckSafeFunctionUsageSniff();
+ $subject->process($mockedFile, $forgedPointer);
+ }
+
+ /**
+ * @test
+ *
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function processAddsNoErrorBecauseFunctionUsed(): void
+ {
+ $forgedPointer = 100;
+ $forgedSafeFunctionName = 'foo';
+ $mockedFile = $this->prepareMocksForConstruction(['foo.php' => 'allows()->getTokens()->andReturn(
+ [
+ $forgedPointer - 1 => ['code' => T_WHITESPACE],
+ $forgedPointer => ['code' => T_STRING, 'content' => 'Foo'],
+ $forgedPointer + 1 => ['code' => T_OPEN_PARENTHESIS],
+ ],
+ );
+ $mockedTokenHelper = $this->prepareMocksForAssertNextTokenParenthesisOpener($mockedFile, $forgedPointer);
+ $this->prepareMocksForAssertGlobalFunctionCall($mockedTokenHelper, $mockedFile, $forgedPointer);
+
+ $mockedUseStatement = Mockery::mock(UseStatement::class);
+ $forgedUseStatementResults = [
+ 17 => [
+ 'foo' => $mockedUseStatement,
+ ],
+ ];
+ $mockedUseStatementHelper = Mockery::mock('overload:' . UseStatementHelper::class);
+ $mockedUseStatementHelper->expects()->getFileUseStatements($mockedFile)->andReturn($forgedUseStatementResults);
+ $mockedUseStatement->expects()->getType()->andReturn('function');
+ $mockedUseStatement->expects()->getNameAsReferencedInFile()->andReturn($forgedSafeFunctionName);
+
+ // Finish with the key assertion
+
+ $mockedFile->shouldNotReceive('addError');
+
+ $subject = new CheckSafeFunctionUsageSniff();
+ $subject->process($mockedFile, $forgedPointer);
+ }
+
/**
* @test
*/
@@ -69,4 +321,37 @@ public function registerReturnsCorrectTokenArray(): void
self::assertSame([T_STRING], $result);
}
+
+ /** @param array $safeFiles */
+ private function prepareMocksForConstruction(array $safeFiles): MockInterface&File
+ {
+ $environmentPath = vfsStream::url('checkSafe');
+
+ $mockedContainerFactory = Mockery::mock('overload:' . ContainerFactory::class);
+ $mockedContainer = Mockery::mock(Container::class);
+ $mockedEnvironment = Mockery::mock(Environment::class);
+ $mockedFile = Mockery::mock(File::class);
+ $mockedComposerInterpreter = Mockery::mock(ComposerInterpreter::class);
+ $mockedFilesystem = mock(Filesystem::class);
+
+ $mockedContainerFactory->expects()->getContainerInstance()->andReturn($mockedContainer);
+ $mockedComposerInterpreter->expects()->getMinimalViablePhpVersion()->andReturn('8.4.3');
+ $mockedContainer->expects()->get(Environment::class)->andReturn($mockedEnvironment);
+ $mockedContainer->expects()->get(ComposerInterpreter::class)->andReturn($mockedComposerInterpreter);
+ $mockedContainer->expects()->get(Filesystem::class)->andReturn($mockedFilesystem);
+ $mockedEnvironment->shouldReceive('getRootDirectory->getRealPath')->andReturn($environmentPath);
+ $mockedFilesystem->expects()->exists($environmentPath . self::SAFE_VENDOR_PATH)
+ ->andReturn(true);
+
+ vfsStream::create(
+ ['vendor' => ['thecodingmachine' => ['safe' => ['generated' => ['8.4' => $safeFiles]]]]],
+ $this->vfsRootDirectory
+ );
+
+ $mockedContainer->expects()->get(Parser::class)
+ ->andReturn(new ParserFactory()->createForVersion(PhpVersion::fromString('8.4')));
+ $mockedContainer->expects()->get(NodeFinder::class)->andReturn(new NodeFinder());
+
+ return $mockedFile;
+ }
}
diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php
index 62f9cab..906fd30 100644
--- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php
+++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedParameterTypeHintSniffTest.php
@@ -7,6 +7,7 @@
use Hamcrest\Matchers as H;
use Mockery;
use Mockery\MockInterface;
+use Override;
use PHP_CodeSniffer\Files\File;
use PHPUnit\Framework\TestCase;
use SlevomatCodingStandard\Helpers\DocCommentHelper;
@@ -23,11 +24,13 @@ class DisallowMixedParameterTypeHintSniffTest extends TestCase
private DisallowMixedParameterTypeHintSniff $subject;
private string $subjectName = 'Zooroyal.TypeHints.DisallowMixedParameterTypeHint';
+ #[Override]
protected function setUp(): void
{
$this->subject = new DisallowMixedParameterTypeHintSniff();
}
+ #[Override]
protected function assertPostConditions(): void
{
Mockery::close();
diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php
index 3f2893c..c5d77b7 100644
--- a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php
+++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/DisallowMixedReturnTypeHintSniffTest.php
@@ -4,6 +4,7 @@
namespace Zooroyal\CodingStandard\Tests\Unit\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints;
+use Override;
use PHPUnit\Framework\TestCase;
use Zooroyal\CodingStandard\Sniffs\Rdss\Standards\ZooRoyal\Sniffs\TypeHints\DisallowMixedReturnTypeHintSniff;
@@ -11,6 +12,7 @@ class DisallowMixedReturnTypeHintSniffTest extends TestCase
{
private DisallowMixedReturnTypeHintSniff $subject;
+ #[Override]
protected function setUp(): void
{
$this->subject = new DisallowMixedReturnTypeHintSniff();
diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php
new file mode 100644
index 0000000..20e7c7a
--- /dev/null
+++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitFunctionArgumentSniffTest.php
@@ -0,0 +1,97 @@
+subject = new LimitFunctionArgumentSniff();
+ }
+
+ protected function tearDown(): void
+ {
+ Mockery::close();
+ }
+
+ /**
+ * @test
+ * @dataProvider processHappyPathDataProvider
+ * @runInSeparateProcess
+ * @preserveGlobalState false
+ */
+ public function processHappyPath(int $numberOfElements): void
+ {
+ $forgedStackPointer = 111;
+ $mockedFile = mock(File::class);
+ $mockedFunctionHelper = mock('overload:' . FunctionHelper::class);
+
+ $mockedResult = array_pad([], $numberOfElements, 'a');
+
+ $mockedFunctionHelper->expects()->getParametersNames($mockedFile, $forgedStackPointer)
+ ->andReturn($mockedResult);
+
+ $mockedFile->shouldNotReceive('addError');
+
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+ /** @return array> */
+ public function processHappyPathDataProvider(): array
+ {
+ return [
+ 'No uses' => ['numberOfElements' => 0],
+ 'Some uses' => ['numberOfElements' => 10],
+ ];
+ }
+
+ /**
+ * @test
+ * @dataProvider processReportsErrorOnTooManyArgumentsDataProvider
+ * @runInSeparateProcess
+ * @preserveGlobalState false
+ */
+ public function processReportsErrorOnTooManyArguments(
+ int $numberOfElements,
+ int $maximumArguments,
+ ): void {
+ $forgedStackPointer = 111;
+ $mockedFile = mock(File::class);
+ $mockedFunctionHelper = mock('overload:' . FunctionHelper::class);
+
+ $mockedResult = array_pad([], $numberOfElements, 'a');
+
+ $mockedFunctionHelper->expects()->getParametersNames($mockedFile, $forgedStackPointer)
+ ->andReturn($mockedResult);
+
+ $mockedFile->expects()->addError(
+ 'Method has too many parameters. Maximum allowed is %s, but found %s.',
+ $forgedStackPointer,
+ 'TooManyArguments',
+ [$maximumArguments, $numberOfElements]
+ );
+
+ $this->subject->maximumArguments = $maximumArguments;
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+ /** @return array> */
+ public function processReportsErrorOnTooManyArgumentsDataProvider(): array
+ {
+ return [
+ 'Too many arguments' => ['numberOfElements' => 20, 'maximumArguments' => 10],
+ 'Exactly over maximum arguments' => ['numberOfElements' => 11, 'maximumArguments' => 10],
+ 'Different limit' => ['numberOfElements' => 4, 'maximumArguments' => 3],
+ ];
+ }
+}
diff --git a/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php
new file mode 100644
index 0000000..a472ab7
--- /dev/null
+++ b/tests/Unit/Sniffs/Rdss/Standards/ZooRoyal/Sniffs/TypeHints/LimitUseStatementSniffTest.php
@@ -0,0 +1,96 @@
+subject = new LimitUseStatementSniff();
+ }
+
+ protected function tearDown(): void
+ {
+ Mockery::close();
+ }
+
+ /**
+ * @test
+ * @dataProvider processHappyPathDataProvider
+ * @runInSeparateProcess
+ * @preserveGlobalState false
+ */
+ public function processHappyPath(int $numberOfElements): void
+ {
+ $mockedFile = mock(File::class);
+ $mockedUserStatementHelper = mock('overload:' . UseStatementHelper::class);
+
+ $mockedResult = array_pad([], $numberOfElements, 'a');
+
+ $mockedUserStatementHelper->expects()->getFileUseStatements($mockedFile)
+ ->andReturn([11 => $mockedResult]);
+
+ $mockedFile->shouldNotReceive('addError');
+
+ $this->subject->process($mockedFile, 10);
+ }
+
+ /** @return array> */
+ public function processHappyPathDataProvider(): array
+ {
+ return [
+ 'No uses' => ['numberOfElements' => 0],
+ 'Some uses' => ['numberOfElements' => 10],
+ ];
+ }
+
+ /**
+ * @test
+ * @dataProvider processReportsErrorOnTooManyUsesDataProvider
+ * @runInSeparateProcess
+ * @preserveGlobalState false
+ */
+ public function processReportsErrorOnTooManyUses(
+ int $numberOfElements,
+ int $maximumUseStatements,
+ ): void {
+ $forgedStackPointer = 10;
+ $mockedFile = mock(File::class);
+ $mockedUserStatementHelper = mock('overload:' . UseStatementHelper::class);
+
+ $mockedResult = array_pad([], $numberOfElements, 'a');
+
+ $mockedUserStatementHelper->expects()->getFileUseStatements($mockedFile)
+ ->andReturn([11 => $mockedResult]);
+
+ $mockedFile->expects()->addError(
+ 'Too many use statements. Maximum allowed is %s, but found %s.',
+ $forgedStackPointer,
+ 'TooManyUseStatements',
+ [$maximumUseStatements, $numberOfElements]
+ );
+
+ $this->subject->maximumUseStatements = $maximumUseStatements;
+ $this->subject->process($mockedFile, $forgedStackPointer);
+ }
+
+ /** @return array> */
+ public function processReportsErrorOnTooManyUsesDataProvider(): array
+ {
+ return [
+ 'Too many uses' => ['numberOfElements' => 20, 'maximumUseStatements' => 15 ],
+ 'Exactly over the limit' => ['numberOfElements' => 16, 'maximumUseStatements' => 15],
+ 'Different Limit' => ['numberOfElements' => 4, 'maximumUseStatements' => 3],
+ ];
+ }
+}
diff --git a/vendor-bin/phpmd/composer.json b/vendor-bin/phpmd/composer.json
deleted file mode 100644
index 721dc94..0000000
--- a/vendor-bin/phpmd/composer.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "require": {
- "phpmd/phpmd": "^2.13.0"
- }
-}
diff --git a/vendor-bin/phpstan/composer.json b/vendor-bin/phpstan/composer.json
index be01b3d..21afd57 100644
--- a/vendor-bin/phpstan/composer.json
+++ b/vendor-bin/phpstan/composer.json
@@ -1,11 +1,11 @@
{
"require": {
"phpstan/extension-installer": "^1.2",
- "phpstan/phpstan": "^1.10.13",
- "phpstan/phpstan-doctrine": "^1.3.32",
- "phpstan/phpstan-mockery": "^1.1.0",
- "phpstan/phpstan-phpunit": "^1.3.3",
- "phpstan/phpstan-symfony": "^1.2.20"
+ "phpstan/phpstan": "^2.1.2",
+ "phpstan/phpstan-doctrine": "^2.0.1",
+ "phpstan/phpstan-mockery": "^2.0.0",
+ "phpstan/phpstan-phpunit": "^2.0.4",
+ "phpstan/phpstan-symfony": "^2.0.2"
},
"config": {
"optimize-autoloader": true,