Skip to content

Commit

Permalink
Add PHPCompatibility Sniff for php 7.4 Syntax checking
Browse files Browse the repository at this point in the history
  • Loading branch information
rdss-sknott committed Mar 22, 2024
1 parent 1ae6bc8 commit a7feee8
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[*.{yml,yaml,json,neon}]
[*.{yml,yaml,neon}]
indent_size = 2

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"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",
Expand Down
2 changes: 2 additions & 0 deletions config/phpcs/ZooRoyal/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule>

<rule ref="PHPCompatibility"/>

<!-- Custom Rule-->
<rule ref="../../../src/main/php/Sniffs/PHPCodeSniffer/Standards/ZooRoyal"/>
<rule ref="../../../src/main/php/Sniffs/Rdss/Standards/ZooRoyal"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ private function buildTargetingString(): string
*/
private function buildPhpVersionString(): string
{
$template = ' --runtime-set php_version %d';
$phpVersion = $this->phpVersionConverter->convertSemVerToPhpString($this->minimalPhpVersion);
$template = ' --runtime-set php_version %1$d --runtime-set testVersion %2$s';
$phpVersionPhpStyle = $this->phpVersionConverter->convertSemVerToPhpString($this->minimalPhpVersion);

$result = sprintf($template, $phpVersion);
$phpVersionLevels = explode('.', $this->minimalPhpVersion);
$phpVersionWithoutPatchLevel = implode('.', [$phpVersionLevels[0], $phpVersionLevels[1]]);

$result = sprintf($template, $phpVersionPhpStyle, $phpVersionWithoutPatchLevel . '-');

return $result;
}
Expand Down
72 changes: 37 additions & 35 deletions tests/System/fixtures/complete/composer-template.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
{
"version": "0.0.1",
"require": {
"php": "^8.1"
},
"require-dev": {
"zooroyal/coding-standard-source": "@dev"
},
"repositories": {
"localRepo": {
"type": "path",
"url": "",
"options": {
"symlink": false
}
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"process-timeout": 600,
"allow-plugins": {
"ocramius/package-versions": true,
"infection/extension-installer": true,
"mindplay/composer-locator": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"bamarni/composer-bin-plugin": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
}
}
"version": "0.0.1",
"require": {
"php": "^8.1"
},
"require-dev": {
"zooroyal/coding-standard-source": "@dev"
},
"repositories": {
"localRepo": {
"type": "path",
"url": "",
"options": {
"symlink": false
}
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"process-timeout": 600,
"allow-plugins": {
"ocramius/package-versions": true,
"infection/extension-installer": true,
"mindplay/composer-locator": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"bamarni/composer-bin-plugin": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": true,
"forward-command": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
54 changes: 28 additions & 26 deletions tests/System/fixtures/eslint/composer-template.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
{
"version": "0.0.1",
"require-dev": {
"zooroyal/coding-standard-source": "@dev"
},
"repositories": {
"localRepo": {
"type": "path",
"url": "",
"options": {
"symlink": false
}
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"process-timeout": 600,
"allow-plugins": {
"ocramius/package-versions": true,
"infection/extension-installer": true,
"mindplay/composer-locator": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"bamarni/composer-bin-plugin": true
}
}
"version": "0.0.1",
"require-dev": {
"zooroyal/coding-standard-source": "@dev"
},
"repositories": {
"localRepo": {
"type": "path",
"url": "",
"options": {
"symlink": false
}
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"process-timeout": 600,
"allow-plugins": {
"ocramius/package-versions": true,
"infection/extension-installer": true,
"mindplay/composer-locator": true,
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"bamarni/composer-bin-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion tests/Tools/TerminalCommandTestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TerminalCommandTestData
/** @var array<string> */
private array $extensions = [];
private int $processes = 1;
private string $phpVersion = '7.4';
private string $phpVersion = '7.4.0';

/**
* TerminalCommandTestData constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function terminalCommandCompilation(TerminalCommandTestData $data): void
);

$this->mockedPhpVersionConverter->shouldReceive('convertSemVerToPhpString')
->with('7.4')
->with('7.4.0')
->andReturn(70400);

$this->subject->addAllowedFileExtensions($data->getExtensions());
Expand Down Expand Up @@ -120,11 +120,12 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcbf -q --extensions=qweasd,argh --parallel=7 -p --standard='
. self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --ignore=a,b --runtime-set php_version 70400 c d',
. '/config/phpcs/ZooRoyal/ruleset.xml --ignore=a,b --runtime-set php_version 70400 '
. '--runtime-set testVersion 7.4- c d',
'excluded' => [$mockedEnhancedFileInfo1, $mockedEnhancedFileInfo1],
'extensions' => ['qweasd', 'argh'],
'fixingMode' => true,
'phpVersion' => '7.4',
'phpVersion' => '7.4.0',
'targets' => [
new EnhancedFileInfo(self::FORGED_ABSOLUTE_VENDOR . '/c', self::FORGED_ABSOLUTE_VENDOR),
new EnhancedFileInfo(self::FORGED_ABSOLUTE_VENDOR . '/d', self::FORGED_ABSOLUTE_VENDOR),
Expand All @@ -140,7 +141,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
],
),
],
Expand All @@ -150,8 +151,8 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
'phpVersion' => '7.4',
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'phpVersion' => '7.4.0',
],
),
],
Expand All @@ -161,7 +162,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --ignore=a,b --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'excluded' => [$mockedEnhancedFileInfo2, $mockedEnhancedFileInfo2],
],
),
Expand All @@ -173,7 +174,7 @@ public function terminalCommandCompilationDataProvider(): array
. '/bin/phpcs -s --extensions=asdqwe,qweasd --parallel=1 -p --standard='
. self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'extensions' => ['asdqwe', 'qweasd'],
],
),
Expand All @@ -184,7 +185,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcbf --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'fixingMode' => true,
],
),
Expand All @@ -194,7 +195,8 @@ public function terminalCommandCompilationDataProvider(): array
[
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 c d',
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. '--runtime-set testVersion 7.4- c d',
'targets' => [
new EnhancedFileInfo(self::FORGED_ABSOLUTE_VENDOR . '/c', self::FORGED_ABSOLUTE_VENDOR),
new EnhancedFileInfo(self::FORGED_ABSOLUTE_VENDOR . '/d', self::FORGED_ABSOLUTE_VENDOR),
Expand All @@ -208,7 +210,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s -q --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'verbosityLevel' => OutputInterface::VERBOSITY_QUIET,
],
),
Expand All @@ -219,7 +221,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s -v --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'verbosityLevel' => OutputInterface::VERBOSITY_VERBOSE,
],
),
Expand All @@ -230,7 +232,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s -vv --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'fixingMode' => false,
'verbosityLevel' => OutputInterface::VERBOSITY_VERY_VERBOSE,
],
Expand All @@ -242,7 +244,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s -vvv --parallel=1 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'verbosityLevel' => OutputInterface::VERBOSITY_DEBUG,
],
),
Expand All @@ -253,7 +255,7 @@ public function terminalCommandCompilationDataProvider(): array
'expectedCommand' => 'php ' . self::FORGED_ABSOLUTE_VENDOR
. '/bin/phpcs -s --parallel=28 -p --standard=' . self::FORGED_PACKAGE_DIRECTORY
. '/config/phpcs/ZooRoyal/ruleset.xml --runtime-set php_version 70400 '
. self::FORGED_RELATIV_ROOT,
. '--runtime-set testVersion 7.4- ' . self::FORGED_RELATIV_ROOT,
'processes' => 28,
],
),
Expand Down

0 comments on commit a7feee8

Please sign in to comment.