Skip to content

Commit

Permalink
Enable rules for PHP 8.1 (#20)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
paulbalandan authored Jun 16, 2024
1 parent 8b2c0de commit 1df8599
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 49 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test-coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test-phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"slack": "https://codeigniterchat.slack.com"
},
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-tokenizer": "*",
"friendsofphp/php-cs-fixer": "^3.50",
"nexusphp/cs-config": "<=3.18.0"
"nexusphp/cs-config": "^3.19.0"
},
"require-dev": {
"nexusphp/tachycardia": "^1.3",
"nexusphp/tachycardia": "^2.1",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^10.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
53 changes: 25 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile="build/phpunit/test-results"
colors="true"
columns="max"
executionOrder="random"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
forceCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true"
cacheDirectory="build/phpunit/cache"
columns="max"
requireCoverageMetadata="true"
>
<testsuites>
<testsuite name="Coding Standards Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="Coding Standards Test Suite">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory="build/phpunit/code-coverage"
ignoreDeprecatedCodeUnits="true"
processUncoveredFiles="true"
>
<include>
<directory suffix=".php">src/</directory>
</include>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>

<report>
<clover outputFile="build/phpunit/logs/clover.xml"/>
<html outputDirectory="build/phpunit/logs/html"/>
</report>
</coverage>
<coverage ignoreDeprecatedCodeUnits="true">
<report>
<clover outputFile="build/phpunit/logs/clover.xml"/>
<html outputDirectory="build/phpunit/logs/html"/>
</report>
</coverage>

<extensions>
<extension class="Nexus\PHPUnit\Extension\Tachycardia" />
</extensions>
<extensions>
<bootstrap class="Nexus\PHPUnit\Tachycardia\TachycardiaExtension" />
</extensions>
</phpunit>
20 changes: 12 additions & 8 deletions src/CodeIgniter4.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function __construct()
'attribute_placement' => 'standalone',
],
'method_chaining_indentation' => true,
'modernize_strpos' => false, // requires 8.0+
'modernize_strpos' => true,
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
'multiline_string_to_heredoc' => false,
Expand Down Expand Up @@ -344,13 +344,13 @@ public function __construct()
'normalize_index_brace' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
'nullable_type_declaration' => false, // requires 8.0+
'nullable_type_declaration' => ['syntax' => 'question_mark'],
'nullable_type_declaration_for_default_null_value' => true,
'numeric_literal_separator' => false,
'object_operator_without_whitespace' => true,
'octal_notation' => false, // requires 8.1+
'operator_linebreak' => ['only_booleans' => true, 'position' => 'beginning'],
'ordered_attributes' => false, // requires 8.0+
'ordered_attributes' => ['order' => [], 'sort_algorithm' => 'alpha'],
'ordered_class_elements' => [
'order' => [
'use_trait',
Expand All @@ -366,10 +366,14 @@ public function __construct()
'imports_order' => ['class', 'function', 'const'],
'case_sensitive' => false,
],
'ordered_interfaces' => false,
'ordered_traits' => false,
'ordered_types' => false, // requires 8.0+
'php_unit_attributes' => false, // requires 8.1+
'ordered_interfaces' => false,
'ordered_traits' => false,
'ordered_types' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'alpha',
'case_sensitive' => false,
],
'php_unit_attributes' => true,
'php_unit_construct' => [
'assertions' => [
'assertSame',
Expand Down Expand Up @@ -689,7 +693,7 @@ public function __construct()
],
];

$this->requiredPHPVersion = 70400;
$this->requiredPHPVersion = 80100;

$this->autoActivateIsRiskyAllowed = true;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/CodeIgniter4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@

namespace CodeIgniter\CodingStandard\Tests;

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Ruleset\RulesetInterface;
use Nexus\CsConfig\Test\AbstractRulesetTestCase;
use PhpCsFixer\Preg;
use PHPUnit\Framework\Attributes\CoversClass;

/**
* @internal
*
* @covers \CodeIgniter\CodingStandard\CodeIgniter4
*/
#[CoversClass(CodeIgniter4::class)]
final class CodeIgniter4Test extends AbstractRulesetTestCase
{
protected static function createRuleset(): RulesetInterface
{
/** @phpstan-var class-string<RulesetInterface> $ruleset */
/** @var class-string<RulesetInterface> $ruleset */
$ruleset = Preg::replace('/^(CodeIgniter\\\\CodingStandard)\\\\Tests(\\\\\S+)Test/', '$1$2', self::class);

return new $ruleset();
Expand Down

0 comments on commit 1df8599

Please sign in to comment.