Skip to content

Commit 1df8599

Browse files
authored
Enable rules for PHP 8.1 (#20)
* Bump PHP to 8.1 * Bump to phpunit v10.5 * Enable `modernize_strpos` * Remove restriction on cs-config * Enable `ordered_attributes` * Enable `nullable_type_declaration` * Enable `php_unit_attributes` * Enable `ordered_types` * Require PHP 8.1 in ruleset
1 parent 8b2c0de commit 1df8599

File tree

7 files changed

+45
-49
lines changed

7 files changed

+45
-49
lines changed

.github/workflows/test-coding-standards.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
php-version:
30-
- '7.4'
31-
- '8.0'
3230
- '8.1'
3331
- '8.2'
3432
- '8.3'

.github/workflows/test-phpstan.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
php-version:
30-
- '7.4'
31-
- '8.0'
3230
- '8.1'
3331
- '8.2'
3432
- '8.3'

.github/workflows/test-phpunit.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
php-version:
30-
- '7.4'
31-
- '8.0'
3230
- '8.1'
3331
- '8.2'
3432
- '8.3'

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
"slack": "https://codeigniterchat.slack.com"
2020
},
2121
"require": {
22-
"php": "^7.4 || ^8.0",
22+
"php": "^8.1",
2323
"ext-tokenizer": "*",
2424
"friendsofphp/php-cs-fixer": "^3.50",
25-
"nexusphp/cs-config": "<=3.18.0"
25+
"nexusphp/cs-config": "^3.19.0"
2626
},
2727
"require-dev": {
28-
"nexusphp/tachycardia": "^1.3",
28+
"nexusphp/tachycardia": "^2.1",
2929
"phpstan/phpstan": "^1.0",
30-
"phpunit/phpunit": "^9.5"
30+
"phpunit/phpunit": "^10.5"
3131
},
3232
"minimum-stability": "dev",
3333
"prefer-stable": true,

phpunit.xml.dist

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
cacheResultFile="build/phpunit/test-results"
65
colors="true"
7-
columns="max"
6+
executionOrder="random"
7+
beStrictAboutOutputDuringTests="true"
88
failOnRisky="true"
99
failOnWarning="true"
10-
forceCoversAnnotation="true"
11-
beStrictAboutOutputDuringTests="true"
12-
beStrictAboutTodoAnnotatedTests="true"
13-
verbose="true"
10+
cacheDirectory="build/phpunit/cache"
11+
columns="max"
12+
requireCoverageMetadata="true"
1413
>
14+
<testsuites>
15+
<testsuite name="Coding Standards Test Suite">
16+
<directory suffix="Test.php">tests/</directory>
17+
</testsuite>
18+
</testsuites>
1519

16-
<testsuites>
17-
<testsuite name="Coding Standards Test Suite">
18-
<directory suffix="Test.php">tests/</directory>
19-
</testsuite>
20-
</testsuites>
21-
22-
<coverage cacheDirectory="build/phpunit/code-coverage"
23-
ignoreDeprecatedCodeUnits="true"
24-
processUncoveredFiles="true"
25-
>
26-
<include>
27-
<directory suffix=".php">src/</directory>
28-
</include>
20+
<source>
21+
<include>
22+
<directory suffix=".php">src/</directory>
23+
</include>
24+
</source>
2925

30-
<report>
31-
<clover outputFile="build/phpunit/logs/clover.xml"/>
32-
<html outputDirectory="build/phpunit/logs/html"/>
33-
</report>
34-
</coverage>
26+
<coverage ignoreDeprecatedCodeUnits="true">
27+
<report>
28+
<clover outputFile="build/phpunit/logs/clover.xml"/>
29+
<html outputDirectory="build/phpunit/logs/html"/>
30+
</report>
31+
</coverage>
3532

36-
<extensions>
37-
<extension class="Nexus\PHPUnit\Extension\Tachycardia" />
38-
</extensions>
33+
<extensions>
34+
<bootstrap class="Nexus\PHPUnit\Tachycardia\TachycardiaExtension" />
35+
</extensions>
3936
</phpunit>

src/CodeIgniter4.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function __construct()
243243
'attribute_placement' => 'standalone',
244244
],
245245
'method_chaining_indentation' => true,
246-
'modernize_strpos' => false, // requires 8.0+
246+
'modernize_strpos' => true,
247247
'modernize_types_casting' => true,
248248
'multiline_comment_opening_closing' => true,
249249
'multiline_string_to_heredoc' => false,
@@ -344,13 +344,13 @@ public function __construct()
344344
'normalize_index_brace' => true,
345345
'not_operator_with_space' => false,
346346
'not_operator_with_successor_space' => true,
347-
'nullable_type_declaration' => false, // requires 8.0+
347+
'nullable_type_declaration' => ['syntax' => 'question_mark'],
348348
'nullable_type_declaration_for_default_null_value' => true,
349349
'numeric_literal_separator' => false,
350350
'object_operator_without_whitespace' => true,
351351
'octal_notation' => false, // requires 8.1+
352352
'operator_linebreak' => ['only_booleans' => true, 'position' => 'beginning'],
353-
'ordered_attributes' => false, // requires 8.0+
353+
'ordered_attributes' => ['order' => [], 'sort_algorithm' => 'alpha'],
354354
'ordered_class_elements' => [
355355
'order' => [
356356
'use_trait',
@@ -366,10 +366,14 @@ public function __construct()
366366
'imports_order' => ['class', 'function', 'const'],
367367
'case_sensitive' => false,
368368
],
369-
'ordered_interfaces' => false,
370-
'ordered_traits' => false,
371-
'ordered_types' => false, // requires 8.0+
372-
'php_unit_attributes' => false, // requires 8.1+
369+
'ordered_interfaces' => false,
370+
'ordered_traits' => false,
371+
'ordered_types' => [
372+
'null_adjustment' => 'always_last',
373+
'sort_algorithm' => 'alpha',
374+
'case_sensitive' => false,
375+
],
376+
'php_unit_attributes' => true,
373377
'php_unit_construct' => [
374378
'assertions' => [
375379
'assertSame',
@@ -689,7 +693,7 @@ public function __construct()
689693
],
690694
];
691695

692-
$this->requiredPHPVersion = 70400;
696+
$this->requiredPHPVersion = 80100;
693697

694698
$this->autoActivateIsRiskyAllowed = true;
695699
}

tests/CodeIgniter4Test.php

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

1414
namespace CodeIgniter\CodingStandard\Tests;
1515

16+
use CodeIgniter\CodingStandard\CodeIgniter4;
1617
use Nexus\CsConfig\Ruleset\RulesetInterface;
1718
use Nexus\CsConfig\Test\AbstractRulesetTestCase;
1819
use PhpCsFixer\Preg;
20+
use PHPUnit\Framework\Attributes\CoversClass;
1921

2022
/**
2123
* @internal
22-
*
23-
* @covers \CodeIgniter\CodingStandard\CodeIgniter4
2424
*/
25+
#[CoversClass(CodeIgniter4::class)]
2526
final class CodeIgniter4Test extends AbstractRulesetTestCase
2627
{
2728
protected static function createRuleset(): RulesetInterface
2829
{
29-
/** @phpstan-var class-string<RulesetInterface> $ruleset */
30+
/** @var class-string<RulesetInterface> $ruleset */
3031
$ruleset = Preg::replace('/^(CodeIgniter\\\\CodingStandard)\\\\Tests(\\\\\S+)Test/', '$1$2', self::class);
3132

3233
return new $ruleset();

0 commit comments

Comments
 (0)