From 63ed9ad9de88a25a0575f3888bc2fe9f8aa7cdcd Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 09:50:51 +0900 Subject: [PATCH 1/9] chore: composer update --- composer.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.lock b/composer.lock index 2ceabe1..fa59deb 100644 --- a/composer.lock +++ b/composer.lock @@ -504,16 +504,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.1", + "version": "2.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379" + "reference": "67c26b443f348a51926030c83481b85718457d3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/69568e4293f4fa993f3b0e51c9723e1e17c41379", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", + "reference": "67c26b443f348a51926030c83481b85718457d3d", "shasum": "" }, "require": { @@ -603,7 +603,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.1" + "source": "https://github.com/guzzle/psr7/tree/2.4.3" }, "funding": [ { @@ -619,7 +619,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T14:45:39+00:00" + "time": "2022-10-26T14:07:24+00:00" }, { "name": "http-interop/http-factory-guzzle", @@ -4940,12 +4940,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "58046a3fc3555eda6567a2bdae7195be6aa9babe" + "reference": "57a3ee3eb79b9538f3012e6b66c04cdac0b551d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/58046a3fc3555eda6567a2bdae7195be6aa9babe", - "reference": "58046a3fc3555eda6567a2bdae7195be6aa9babe", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/57a3ee3eb79b9538f3012e6b66c04cdac0b551d1", + "reference": "57a3ee3eb79b9538f3012e6b66c04cdac0b551d1", "shasum": "" }, "conflict": { @@ -5000,7 +5000,7 @@ "cesnet/simplesamlphp-module-proxystatistics": "<3.1", "codeception/codeception": "<3.1.3|>=4,<4.1.22", "codeigniter/framework": "<=3.0.6", - "codeigniter4/framework": "<4.2.7", + "codeigniter4/framework": "<4.2.11", "codeigniter4/shield": "= 1.0.0-beta", "codiad/codiad": "<=2.8.4", "composer/composer": "<1.10.26|>=2-alpha.1,<2.2.12|>=2.3,<2.3.5", @@ -5479,7 +5479,7 @@ "type": "tidelift" } ], - "time": "2022-12-21T06:05:00+00:00" + "time": "2022-12-22T20:04:36+00:00" }, { "name": "sebastian/cli-parser", From bedf121fd9c2d0e5d1c889e7f9e4ab9a5ca2e2cf Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 09:51:18 +0900 Subject: [PATCH 2/9] style: run php-cs-fixer --- app/Config/App.php | 1 + app/Libraries/Blog.php | 4 ++-- app/Libraries/GitHub.php | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Config/App.php b/app/Config/App.php index 8009881..2917e40 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -437,6 +437,7 @@ class App extends BaseConfig * Defaults to `Lax` as recommended in this link: * * @see https://portswigger.net/web-security/csrf/samesite-cookies + * * @deprecated `Config\Cookie` $samesite property is used. * * @var string diff --git a/app/Libraries/Blog.php b/app/Libraries/Blog.php index 1c251b3..6cababa 100644 --- a/app/Libraries/Blog.php +++ b/app/Libraries/Blog.php @@ -34,9 +34,9 @@ public function __construct() * If $category is present, will locate within a * subfolder of that name. * - * @throws BlogException - * * @return Post[] + * + * @throws BlogException */ public function getRecentPosts(int $limit = 5, int $offset = 0, ?string $category = null) { diff --git a/app/Libraries/GitHub.php b/app/Libraries/GitHub.php index 797c6f8..773f707 100644 --- a/app/Libraries/GitHub.php +++ b/app/Libraries/GitHub.php @@ -100,7 +100,7 @@ public function __construct(GitHubConfig $config, Client $client) $this->client = $client; } - //--------------------------------------------------------------------- + // --------------------------------------------------------------------- /** * Interfaces with the client to execute @@ -127,7 +127,7 @@ protected function api(array $methods, array $segments): array return $caller->{$final}(...$segments); } - //--------------------------------------------------------------------- + // --------------------------------------------------------------------- /** * Retrieves releases and tags for configured repositories @@ -244,7 +244,7 @@ public function getCommit(array $segments): array return $this->api(['repo', 'commits', 'show'], $segments); } - //--------------------------------------------------------------------- + // --------------------------------------------------------------------- /** * Retrieves repo details for each configured repository as a Repo. @@ -264,7 +264,7 @@ public function getRepos(): array return $this->storage['repos']; } - //--------------------------------------------------------------------- + // --------------------------------------------------------------------- /** * Retrieves contributor information for a repository. From 776d5670da0b3085c9326440f2035df512d87386 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 09:57:10 +0900 Subject: [PATCH 3/9] chore: update php-cs-fixer commands in composer.json --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 68699b7..ba8d75f 100644 --- a/composer.json +++ b/composer.json @@ -66,10 +66,12 @@ "@inspect", "@style" ], + "cs": "php-cs-fixer fix --ansi --verbose --dry-run --diff", + "cs-fix": "php-cs-fixer fix --ansi --verbose --diff", + "style": "@cs-fix", "deduplicate": "phpcpd app/ src/", "inspect": "deptrac analyze --cache-file=build/deptrac.cache", "mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit", - "style": "php-cs-fixer fix --verbose --ansi --using-cache=no", "test": "phpunit" } } From 120584f138cef91ff6a6c84d6f90a3b4b99ac0a6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 09:57:34 +0900 Subject: [PATCH 4/9] chore: update .php-cs-fixer.dist.php --- .php-cs-fixer.dist.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index dbf0468..8fc31b3 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,11 +10,19 @@ __DIR__ . '/app/', __DIR__ . '/tests/', ]) - ->exclude('build') - ->exclude('Views/errors') - ->append([__FILE__]); + ->exclude([ + 'build', + 'Views', + ]) + ->append([ + __FILE__, + __DIR__ . '/rector.php', + ]); -$overrides = []; +$overrides = [ + // 'declare_strict_types' => true, + // 'void_return' => true, +]; $options = [ 'finder' => $finder, From ad5bccbcc5b3971c72fbaeb482b131102169b365 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 09:57:55 +0900 Subject: [PATCH 5/9] chore: update rector.php --- rector.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/rector.php b/rector.php index 06c75be..d81b002 100644 --- a/rector.php +++ b/rector.php @@ -1,6 +1,7 @@ sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitSetList::PHPUNIT_80]); + $rectorConfig->sets([ + SetList::DEAD_CODE, + LevelSetList::UP_TO_PHP_74, + PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, + PHPUnitSetList::PHPUNIT_100, + ]); + $rectorConfig->parallel(); + // The paths to refactor (can also be supplied with CLI arguments) $rectorConfig->paths([ __DIR__ . '/app/', @@ -73,13 +82,14 @@ // Note: requires php 8 RemoveUnusedPromotedPropertyRector::class, + AnnotationWithValueToAttributeRector::class, // Ignore tests that might make calls without a result RemoveEmptyMethodCallRector::class => [ __DIR__ . '/tests', ], - // Ignore files that should not be namespaced + // Ignore files that should not be namespaced to their folder NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [ __DIR__ . '/app/Helpers', ], @@ -90,6 +100,10 @@ // May be uninitialized on purpose AddDefaultValueForUndefinedVariableRector::class, ]); + + // auto import fully qualified class names + $rectorConfig->importNames(); + $rectorConfig->rule(SimplifyUselessVariableRector::class); $rectorConfig->rule(RemoveAlwaysElseRector::class); $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); @@ -112,9 +126,7 @@ $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); - $rectorConfig - ->ruleWithConfiguration(TypedPropertyRector::class, [ - // Set to false if you use in libraries, or it does create breaking changes. - TypedPropertyRector::INLINE_PUBLIC => false, - ]); + $rectorConfig->rule(StringClassNameToClassConstantRector::class); + $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); + $rectorConfig->rule(CompleteDynamicPropertiesRector::class); }; From 277316d41031894042bd58b1f0726031f63480b9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 10:11:26 +0900 Subject: [PATCH 6/9] test: refactor by rector --- tests/entities/ContributorTest.php | 2 +- tests/entities/PostTest.php | 2 +- tests/libaries/BlogLibraryTest.php | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/entities/ContributorTest.php b/tests/entities/ContributorTest.php index 08f9432..83e73d0 100644 --- a/tests/entities/ContributorTest.php +++ b/tests/entities/ContributorTest.php @@ -18,7 +18,7 @@ public function testStars(int $contributions, string $expected) $this->assertSame($expected, $contributor->stars); } - public function contributionsProvider(): array + public static function contributionsProvider(): array { return [ [0, '★'], diff --git a/tests/entities/PostTest.php b/tests/entities/PostTest.php index 4fa55f5..8853787 100644 --- a/tests/entities/PostTest.php +++ b/tests/entities/PostTest.php @@ -8,7 +8,7 @@ */ final class PostTest extends ProjectTestCase { - protected Post $post; + private Post $post; protected function setUp(): void { diff --git a/tests/libaries/BlogLibraryTest.php b/tests/libaries/BlogLibraryTest.php index 15bb749..40f95dc 100644 --- a/tests/libaries/BlogLibraryTest.php +++ b/tests/libaries/BlogLibraryTest.php @@ -4,7 +4,6 @@ use App\Libraries\Blog; use CodeIgniter\Config\Factories; use Config\Blog as BlogConfig; -use org\bovigo\vfs\vfsStream; use Tests\Support\ProjectTestCase; /** @@ -12,12 +11,7 @@ */ final class BlogLibraryTest extends ProjectTestCase { - /** - * Our fake filesystem - */ - protected vfsStream $root; - - protected Blog $blog; + private Blog $blog; protected function setUp(): void { From 4164f4c1e8c9a3d5edd88b9b8b1072e6583d92df Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 10:23:57 +0900 Subject: [PATCH 7/9] refactor: workaround for PHPStan errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------ ------------------------------------------------------------------------------------- Line app/Libraries/Blog.php ------ ------------------------------------------------------------------------------------- 253 Negated boolean expression is always true. 💡 Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your phpstan.neon.dist. 255 Negated boolean expression is always false. 262 Negated boolean expression is always true. 269 Unreachable statement - code above always terminates. ------ ------------------------------------------------------------------------------------- --- app/Libraries/Blog.php | 4 +++- rector.php | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Libraries/Blog.php b/app/Libraries/Blog.php index 6cababa..39f424e 100644 --- a/app/Libraries/Blog.php +++ b/app/Libraries/Blog.php @@ -250,7 +250,8 @@ protected function readPost(string $folder, string $filename) foreach ($contents as $line) { if (trim($line) === '---') { - $inFrontMatter = ! $inFrontMatter; + $inFrontMatter = $inFrontMatter ? false : true; + if (! $inFrontMatter) { $inBody = true; } @@ -267,6 +268,7 @@ protected function readPost(string $folder, string $filename) $body[] = trim($line); } + $post->body = implode("\n", $body); // Convert body using Markdown diff --git a/rector.php b/rector.php index d81b002..fa02e9e 100644 --- a/rector.php +++ b/rector.php @@ -99,6 +99,11 @@ // May be uninitialized on purpose AddDefaultValueForUndefinedVariableRector::class, + + // PHPStan will report false positive errors + UnnecessaryTernaryExpressionRector::class => [ + __DIR__ . '/app/Libraries/Blog.php', + ], ]); // auto import fully qualified class names From 250a5d048bcdf374f344b6368d366cdb01da7945 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 10:37:53 +0900 Subject: [PATCH 8/9] chore: update github/workflows --- .github/workflows/deptrac.yml | 5 ++--- .github/workflows/infection.yml | 7 ++----- .github/workflows/phpcsfixer.yml | 5 ++--- .github/workflows/phpstan.yml | 5 ++--- .github/workflows/phpunit.yml | 6 ++---- .github/workflows/psalm.yml | 5 ++--- .github/workflows/rector.yml | 7 +++---- 7 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.github/workflows/deptrac.yml b/.github/workflows/deptrac.yml index c077f72..ca471f0 100644 --- a/.github/workflows/deptrac.yml +++ b/.github/workflows/deptrac.yml @@ -39,13 +39,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/infection.yml b/.github/workflows/infection.yml index 7f0f21b..8d2c1dc 100644 --- a/.github/workflows/infection.yml +++ b/.github/workflows/infection.yml @@ -45,13 +45,12 @@ jobs: uses: mheap/phpunit-matcher-action@v1 - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- @@ -65,8 +64,6 @@ jobs: - name: Test with PHPUnit run: vendor/bin/phpunit --teamcity - env: - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Mutate with Infection run: | diff --git a/.github/workflows/phpcsfixer.yml b/.github/workflows/phpcsfixer.yml index 3b1265e..6e9c639 100644 --- a/.github/workflows/phpcsfixer.yml +++ b/.github/workflows/phpcsfixer.yml @@ -34,13 +34,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 6bdd00f..26a6e20 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -43,13 +43,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index c867c20..c8caa4a 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -42,13 +42,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- @@ -65,7 +64,6 @@ jobs: env: TERM: xterm-256color TACHYCARDIA_MONITOR_GA: enabled - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: matrix.php-versions == '8.0' name: Run Coveralls diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 5e6ccf6..274b154 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -39,13 +39,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index c09365d..d91db3c 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -43,13 +43,12 @@ jobs: COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV - name: Cache composer dependencies uses: actions/cache@v3 with: - path: ${{ steps.composer-cache.outputs.dir }} + path: ${{ env.COMPOSER_CACHE_FILES_DIR }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- @@ -63,5 +62,5 @@ jobs: - name: Analyze for refactoring run: | - composer global require --dev rector/rector:^0.14 + composer global require --dev rector/rector:^0.15.1 rector process --dry-run --no-progress-bar From 450972561ad5c60aafe44b047ddcbcfcaac3d770 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Dec 2022 10:42:14 +0900 Subject: [PATCH 9/9] chore: add GITHUB_ACCESS_TOKEN --- .github/workflows/infection.yml | 2 ++ .github/workflows/phpunit.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/infection.yml b/.github/workflows/infection.yml index 8d2c1dc..82f75dd 100644 --- a/.github/workflows/infection.yml +++ b/.github/workflows/infection.yml @@ -64,6 +64,8 @@ jobs: - name: Test with PHPUnit run: vendor/bin/phpunit --teamcity + env: + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Mutate with Infection run: | diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index c8caa4a..c02ded2 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -64,6 +64,7 @@ jobs: env: TERM: xterm-256color TACHYCARDIA_MONITOR_GA: enabled + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - if: matrix.php-versions == '8.0' name: Run Coveralls