From 51765128993d318819c25ae66c9661fae395592b Mon Sep 17 00:00:00 2001 From: otsch Date: Wed, 6 Nov 2024 14:50:20 +0100 Subject: [PATCH 1/2] Run tests in CI also with PHP 8.4 Further merge running PHPStan and PHP CS Fixer in github actions workflow for better performance. And also upgrade PHP CS Fixer ruleset to PER and use parallelization. --- .github/workflows/ci.yml | 28 ++++--------------- .php-cs-fixer.dist.php | 10 +++++-- LICENSE | 2 +- composer.json | 8 +++++- src/Encoding.php | 2 +- .../InvalidRobotsTxtFileException.php | 4 +-- src/Parser.php | 2 +- src/RobotsTxt.php | 2 +- tests/UserAgentGroupTest.php | 2 +- 9 files changed, 27 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4459be..992a469 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,31 +3,12 @@ name: CI on: pull_request jobs: - cs: - name: PHP CS Fixer - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.0' - - - name: Install dependencies - run: composer install --prefer-dist --no-progress - - - name: Run PHP CS Fixer - run: composer cs - tests: name: PHPUnit tests runs-on: ubuntu-latest strategy: matrix: - php-versions: ['8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout code @@ -44,8 +25,8 @@ jobs: - name: Run tests run: composer test - stan: - name: PHPStan + stanAndCs: + name: Static Analysis (PHPStan) and Code Style (PHP CS Fixer) runs-on: ubuntu-latest steps: @@ -62,3 +43,6 @@ jobs: - name: Run PHPStan run: composer stan + + - name: Run PHP CS Fixer + run: composer cs diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 1ca9e33..de2ac50 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,15 +1,21 @@ in([__DIR__ . '/src', __DIR__ . '/tests']); $config = new PhpCsFixer\Config(); -return $config->setFinder($finder) +return (new Config()) + ->setFinder($finder) + ->setParallelConfig(ParallelConfigFactory::detect()) ->setRules([ - '@PSR12' => true, + '@PER-CS' => true, 'strict_param' => true, 'array_syntax' => ['syntax' => 'short'], + 'no_unused_imports' => true, ]) ->setRiskyAllowed(true) ->setUsingCache(true); diff --git a/LICENSE b/LICENSE index 152e00c..81fc620 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2023 Christian Olear +Copyright (c) 2024 Christian Olear Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/composer.json b/composer.json index ed02e17..f81e412 100644 --- a/composer.json +++ b/composer.json @@ -30,13 +30,19 @@ "source": "https://github.com/crwlrsoft/robots-txt", "docs": "https://www.crwlr.software/packages/robots-txt" }, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/otsch" + } + ], "require": { "php": "^8.0", "crwlr/url": "^1.0|^2.0" }, "require-dev": { "phpunit/phpunit": "^9.0", - "friendsofphp/php-cs-fixer": "^3.0", + "friendsofphp/php-cs-fixer": "^3.57", "sempro/phpunit-pretty-print": "^1.4", "mockery/mockery": "^1.4", "phpstan/phpstan": "^1.1" diff --git a/src/Encoding.php b/src/Encoding.php index fa604d2..e1a42cc 100644 --- a/src/Encoding.php +++ b/src/Encoding.php @@ -23,7 +23,7 @@ public static function decodePercentEncodedAsciiCharactersInPath(string $path): trigger_error( "Failed to Decode percent encoded ASCII characters. Preg error: \n" . preg_last_error() . ": " . preg_last_error_msg(), - E_USER_WARNING + E_USER_WARNING, ); return $path; diff --git a/src/Exceptions/InvalidRobotsTxtFileException.php b/src/Exceptions/InvalidRobotsTxtFileException.php index 6b42d6e..30e9788 100644 --- a/src/Exceptions/InvalidRobotsTxtFileException.php +++ b/src/Exceptions/InvalidRobotsTxtFileException.php @@ -4,6 +4,4 @@ use Exception; -class InvalidRobotsTxtFileException extends Exception -{ -} +class InvalidRobotsTxtFileException extends Exception {} diff --git a/src/Parser.php b/src/Parser.php index ab9e302..ac42e0b 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -45,7 +45,7 @@ private function getLine(array $lines, int $lineNumber): string { return trim( $lines[$lineNumber], - " \n\r\t\v\x00 ­  ⁠​           ⠀͏‌" + " \n\r\t\v\x00 ­  ⁠​           ⠀͏‌", ); } diff --git a/src/RobotsTxt.php b/src/RobotsTxt.php index 2e54845..4473092 100644 --- a/src/RobotsTxt.php +++ b/src/RobotsTxt.php @@ -17,7 +17,7 @@ public function __construct(private array $userAgentGroups, private array $sitem foreach ($userAgentGroups as $userAgentGroup) { if (!$userAgentGroup instanceof UserAgentGroup) { throw new InvalidArgumentException( - 'Argument $userAgentGroups must exclusively contain objects of type UserAgentGroup.' + 'Argument $userAgentGroups must exclusively contain objects of type UserAgentGroup.', ); } } diff --git a/tests/UserAgentGroupTest.php b/tests/UserAgentGroupTest.php index 1d451ce..b69109a 100644 --- a/tests/UserAgentGroupTest.php +++ b/tests/UserAgentGroupTest.php @@ -65,7 +65,7 @@ public function test_is_allowed(array $disallowedPatterns, string $allowedPatter { array_walk( $disallowedPatterns, - fn (string $pattern) => $this->userAgentGroup->addDisallowedPattern(new RulePattern($pattern)) + fn(string $pattern) => $this->userAgentGroup->addDisallowedPattern(new RulePattern($pattern)), ); $this->userAgentGroup->addAllowedPattern(new RulePattern($allowedPattern)); $this->assertTrue($this->userAgentGroup->isAllowed($uri)); From a1d8e6eaee0d04c06c2ab3e551529c99532b643e Mon Sep 17 00:00:00 2001 From: otsch Date: Wed, 6 Nov 2024 14:53:41 +0100 Subject: [PATCH 2/2] Remove forgotten variable --- .php-cs-fixer.dist.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index de2ac50..9bfd306 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -6,8 +6,6 @@ $finder = PhpCsFixer\Finder::create() ->in([__DIR__ . '/src', __DIR__ . '/tests']); -$config = new PhpCsFixer\Config(); - return (new Config()) ->setFinder($finder) ->setParallelConfig(ParallelConfigFactory::detect())