Skip to content

Commit 7463b82

Browse files
authored
Add PHP 8 compatibility, end PHP 7.2 support (#67)
1 parent f2ea42b commit 7463b82

6 files changed

Lines changed: 476 additions & 8 deletions

File tree

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php-versions: ['7.3', '7.4']
15+
php-versions: ['7.3', '7.4', '8.0']
1616
name: PHP ${{ matrix.php-versions }}
1717
steps:
1818
- uses: actions/checkout@v2

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "PHP_CodeSniffer tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards. Hostnet version",
55
"license": "MIT",
66
"require": {
7-
"php": ">=7.2",
7+
"php": "^7.3|^8.0",
88
"composer-plugin-api": "^2.0.0",
99
"hostnet/path-composer-plugin-lib": "^1.0.4",
1010
"slevomat/coding-standard": "^7.0.9",
@@ -13,7 +13,7 @@
1313
},
1414
"require-dev": {
1515
"composer/composer": "^2.0.2",
16-
"phpunit/phpunit": "^6.5.4"
16+
"phpunit/phpunit": "^9.5.6"
1717
},
1818
"autoload": {
1919
"psr-0": {

phpcs.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<rule ref="Hostnet"/>
44
<!-- Copied from mediawiki-codesniffer -->
55
<exclude-pattern>src/Hostnet/Sniffs/Classes/MultipleEmptyLinesSniff.php</exclude-pattern>
6+
<!-- Copied from squizlabs/php_codesniffer -->
7+
<exclude-pattern>test/Hostnet/Tests/CopiedAbstractSniffUnitTest.php</exclude-pattern>
68
</ruleset>

src/Hostnet/Sniffs/Commenting/AtCoversCounterPartSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ private function extractCoverageNamespaces(File $phpcs_file, int $close_tag_posi
9999

100100
private function getNamespaceFromFile(string $path_to_file): string
101101
{
102+
// PHP 8.0 forward compatibility @see https://www.php.net/manual/en/migration80.incompatible.php
103+
if (!defined('T_NAME_QUALIFIED')) {
104+
define('T_NAME_QUALIFIED', T_NS_SEPARATOR);
105+
}
106+
102107
$namespace = '';
103108
$class = '';
104109

@@ -118,7 +123,7 @@ private function getNamespaceFromFile(string $path_to_file): string
118123

119124
if ($getting_namespace) {
120125
// If the token is a string or the namespace separator.
121-
if (\is_array($token) && \in_array($token[0], [T_STRING, T_NS_SEPARATOR], true)) {
126+
if (\is_array($token) && \in_array($token[0], [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED], true)) {
122127
// Append the token's value to the name of the namespace.
123128
$namespace .= $token[1];
124129
} elseif ($token === ';') {

test/Hostnet/Tests/AbstractSniffUnitTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,20 @@
88

99
use PHP_CodeSniffer\Config;
1010
use PHP_CodeSniffer\Ruleset;
11-
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest as AbstractSniffUnitTestCodeSniffer;
1211
use PHP_CodeSniffer\Tests\Standards\AllSniffs;
1312

1413
/**
1514
* This class acts as a bridge between our unit-tests and the PHPCodeSniffer Unit-Testing framework.
1615
* It setup the environment; loading our 'code standard' etc.
1716
*/
18-
abstract class AbstractSniffUnitTest extends AbstractSniffUnitTestCodeSniffer
17+
abstract class AbstractSniffUnitTest extends CopiedAbstractSniffUnitTest
1918
{
2019
/**
2120
* Prepare our code standard setup, PHP Code Sniffer performs this in AllTests
2221
*
2322
* @see AbstractSniffUnitTest::setUp()
2423
*/
25-
protected function setUp()
24+
protected function setUp(): void
2625
{
2726
new AllSniffs();
2827

@@ -35,7 +34,7 @@ protected function setUp()
3534
parent::setUp();
3635
}
3736

38-
public function doesNotPerformAssertions()
37+
public function doesNotPerformAssertions(): bool
3938
{
4039
return true;
4140
}

0 commit comments

Comments
 (0)