Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update devkit #348

Merged
merged 9 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/deptrac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/infection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/phpcsfixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-

Expand All @@ -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
16 changes: 12 additions & 4 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions app/Libraries/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand All @@ -267,6 +268,7 @@ protected function readPost(string $folder, string $filename)

$body[] = trim($line);
}

$post->body = implode("\n", $body);

// Convert body using Markdown
Expand Down
8 changes: 4 additions & 4 deletions app/Libraries/GitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(GitHubConfig $config, Client $client)
$this->client = $client;
}

//---------------------------------------------------------------------
// ---------------------------------------------------------------------

/**
* Interfaces with the client to execute
Expand All @@ -127,7 +127,7 @@ protected function api(array $methods, array $segments): array
return $caller->{$final}(...$segments);
}

//---------------------------------------------------------------------
// ---------------------------------------------------------------------

/**
* Retrieves releases and tags for configured repositories
Expand Down Expand Up @@ -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.
Expand All @@ -264,7 +264,7 @@ public function getRepos(): array
return $this->storage['repos'];
}

//---------------------------------------------------------------------
// ---------------------------------------------------------------------

/**
* Retrieves contributor information for a repository.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 25 additions & 8 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\CodeQuality\Rector\For_\ForToForeachRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
Expand Down Expand Up @@ -29,15 +30,23 @@
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->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/',
Expand Down Expand Up @@ -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',
],
Expand All @@ -89,7 +99,16 @@

// 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
$rectorConfig->importNames();

$rectorConfig->rule(SimplifyUselessVariableRector::class);
$rectorConfig->rule(RemoveAlwaysElseRector::class);
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
Expand All @@ -112,9 +131,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);
};
2 changes: 1 addition & 1 deletion tests/entities/ContributorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '★'],
Expand Down
Loading