Skip to content

Commit dce61b3

Browse files
authored
Merge pull request #149 from codeigniter4/devkit
2 parents 13528ba + 7874502 commit dce61b3

File tree

7 files changed

+96
-109
lines changed

7 files changed

+96
-109
lines changed
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Infection
1+
name: Psalm
22

33
on:
44
pull_request:
@@ -7,43 +7,41 @@ on:
77
paths:
88
- '**.php'
99
- 'composer.*'
10-
- 'phpunit*'
11-
- '.github/workflows/infection.yml'
10+
- 'psalm*'
11+
- '.github/workflows/psalm.yml'
1212
push:
1313
branches:
1414
- develop
1515
paths:
1616
- '**.php'
1717
- 'composer.*'
18-
- 'phpunit*'
19-
- '.github/workflows/infection.yml'
18+
- 'psalm*'
19+
- '.github/workflows/psalm.yml'
2020

2121
jobs:
22-
main:
23-
name: Mutation Testing
22+
build:
23+
name: PHP ${{ matrix.php-versions }} Psalm Analysis
2424
runs-on: ubuntu-latest
2525
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
php-versions: ['7.4', '8.0', '8.1']
2630

2731
steps:
2832
- name: Checkout
2933
uses: actions/checkout@v3
3034

31-
- name: Set up PHP
35+
- name: Setup PHP
3236
uses: shivammathur/setup-php@v2
3337
with:
34-
php-version: '8.0'
35-
tools: infection, phpunit
36-
extensions: intl, json, mbstring, gd, xml, sqlite3
37-
coverage: xdebug
38+
php-version: ${{ matrix.php-versions }}
39+
tools: phpstan, phpunit
40+
extensions: intl, json, mbstring, xml
41+
coverage: none
3842
env:
3943
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4044

41-
- name: Set up problem matchers for PHPUnit
42-
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
43-
44-
- name: Configure matchers
45-
uses: mheap/phpunit-matcher-action@v1
46-
4745
- name: Get composer cache directory
4846
id: composer-cache
4947
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
@@ -55,6 +53,16 @@ jobs:
5553
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
5654
restore-keys: ${{ runner.os }}-composer-
5755

56+
- name: Create Psalm cache directory
57+
run: mkdir -p build/psalm
58+
59+
- name: Cache Psalm results
60+
uses: actions/cache@v3
61+
with:
62+
path: build/psalm
63+
key: ${{ runner.os }}-psalm-${{ github.sha }}
64+
restore-keys: ${{ runner.os }}-psalm-
65+
5866
- name: Install dependencies
5967
run: |
6068
if [ -f composer.lock ]; then
@@ -63,10 +71,5 @@ jobs:
6371
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
6472
fi
6573
66-
- name: Test with PHPUnit
67-
run: vendor/bin/phpunit --teamcity
68-
69-
- name: Mutate with Infection
70-
run: |
71-
git fetch --depth=1 origin $GITHUB_BASE_REF
72-
infection --threads=2 --skip-initial-tests --coverage=build/phpunit --git-diff-base=origin/$GITHUB_BASE_REF --git-diff-filter=AM --logger-github --ignore-msi-with-no-mutations
74+
- name: Run Psalm analysis
75+
run: vendor/bin/psalm

composer.json

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11
{
22
"name": "codeigniter4/shield",
3-
"type": "library",
43
"description": "Authentication and Authorization for CodeIgniter 4",
4+
"license": "MIT",
5+
"type": "library",
56
"keywords": [
67
"codeigniter",
78
"codeigniter4",
89
"authentication",
910
"authorization"
1011
],
11-
"homepage": "https://github.com/codeigniter4/shield",
12-
"license": "MIT",
1312
"authors": [
1413
{
1514
"name": "Lonnie Ezell",
1615
"email": "[email protected]",
1716
"role": "Developer"
1817
}
1918
],
19+
"homepage": "https://github.com/codeigniter4/shield",
2020
"require": {
2121
"php": "^7.4 || ^8.0",
2222
"codeigniter4/settings": "^2.0"
2323
},
24-
"provide": {
25-
"codeigniter4/authentication-implementation": "1.0"
26-
},
2724
"require-dev": {
28-
"codeigniter/coding-standard": "^1.1",
25+
"codeigniter4/devkit": "^1.0",
2926
"codeigniter4/framework": "^4.1",
30-
"fakerphp/faker": "^1.9",
31-
"friendsofphp/php-cs-fixer": "^3.0",
3227
"mockery/mockery": "^1.0",
33-
"nexusphp/cs-config": "^3.1",
34-
"nexusphp/tachycardia": "^1.0",
35-
"php-coveralls/php-coveralls": "^2.4",
36-
"phpstan/phpstan": "^1.0",
37-
"phpunit/phpunit": "^9.1",
3828
"vimeo/psalm": "^4.22"
3929
},
40-
"config": {
41-
"allow-plugins": {
42-
"phpstan/extension-installer": true
43-
}
30+
"provide": {
31+
"codeigniter4/authentication-implementation": "1.0"
4432
},
33+
"repositories": [
34+
{
35+
"type": "vcs",
36+
"url": "https://github.com/codeigniter4/CodeIgniter4"
37+
}
38+
],
39+
"minimum-stability": "dev",
40+
"prefer-stable": true,
4541
"autoload": {
4642
"psr-4": {
4743
"CodeIgniter\\Shield\\": "src"
@@ -56,23 +52,16 @@
5652
"Tests\\Support\\": "tests/_support"
5753
}
5854
},
59-
"repositories": [
60-
{
61-
"type": "vcs",
62-
"url": "https://github.com/codeigniter4/CodeIgniter4"
55+
"config": {
56+
"allow-plugins": {
57+
"phpstan/extension-installer": true
6358
}
64-
],
65-
"minimum-stability": "dev",
66-
"prefer-stable": true,
59+
},
6760
"scripts": {
6861
"post-update-cmd": [
6962
"bash admin/setup.sh"
7063
],
7164
"analyze": "phpstan analyze",
72-
"sa": [
73-
"@analyze",
74-
"psalm"
75-
],
7665
"ci": [
7766
"Composer\\Config::disableProcessTimeout",
7867
"@deduplicate",
@@ -82,11 +71,15 @@
8271
"rector process",
8372
"@style"
8473
],
74+
"cs-fix": "@style",
8575
"deduplicate": "phpcpd app/ src/",
8676
"inspect": "deptrac analyze --cache-file=build/deptrac.cache",
8777
"mutate": "infection --threads=2 --skip-initial-tests --coverage=build/phpunit",
88-
"style": "php-cs-fixer fix --ansi --verbose --diff",
89-
"cs-fix": "@style",
78+
"sa": [
79+
"phpstan analyze",
80+
"psalm"
81+
],
82+
"style": "php-cs-fixer fix --verbose --ansi --using-cache=no",
9083
"test": "phpunit"
9184
}
9285
}

psalm.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
xmlns="https://getpsalm.org/schema/config"
77
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
88
autoloader="psalm_autoload.php"
9+
cacheDirectory="build/psalm/"
910
>
1011
<projectFiles>
11-
<directory name="src" />
12+
<directory name="src/" />
13+
<directory name="tests/" />
1214
<ignoreFiles>
1315
<directory name="vendor" />
1416
<directory name="src/Views" />

rector.php

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Rector\Config\RectorConfig;
34
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
45
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
56
use Rector\CodeQuality\Rector\For_\ForToForeachRector;
@@ -17,7 +18,6 @@
1718
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
1819
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
1920
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
20-
use Rector\Core\Configuration\Option;
2121
use Rector\Core\ValueObject\PhpVersion;
2222
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
2323
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
@@ -34,47 +34,38 @@
3434
use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector;
3535
use Rector\Set\ValueObject\LevelSetList;
3636
use Rector\Set\ValueObject\SetList;
37-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
3837

39-
return static function (ContainerConfigurator $containerConfigurator): void {
40-
// Rule sets to apply
41-
$containerConfigurator->import(SetList::DEAD_CODE);
42-
$containerConfigurator->import(LevelSetList::UP_TO_PHP_74);
43-
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD);
44-
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_80);
45-
46-
$parameters = $containerConfigurator->parameters();
47-
48-
$parameters->set(Option::PARALLEL, true);
38+
return static function (RectorConfig $rectorConfig): void {
39+
$rectorConfig->sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitSetList::PHPUNIT_80]);
40+
$rectorConfig->parallel();
4941
// The paths to refactor (can also be supplied with CLI arguments)
50-
$parameters->set(Option::PATHS, [
42+
$rectorConfig->paths([
5143
__DIR__ . '/src/',
5244
__DIR__ . '/tests/',
5345
]);
5446

5547
// Include Composer's autoload - required for global execution, remove if running locally
56-
$parameters->set(Option::AUTOLOAD_PATHS, [
48+
$rectorConfig->autoloadPaths([
5749
__DIR__ . '/vendor/autoload.php',
5850
]);
5951

6052
// Do you need to include constants, class aliases, or a custom autoloader?
61-
$parameters->set(Option::BOOTSTRAP_FILES, [
53+
$rectorConfig->bootstrapFiles([
6254
realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php',
6355
]);
6456

6557
if (is_file(__DIR__ . '/phpstan.neon.dist')) {
66-
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__ . '/phpstan.neon.dist');
58+
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist');
6759
}
6860

6961
// Set the target version for refactoring
70-
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74);
62+
$rectorConfig->phpVersion(PhpVersion::PHP_74);
7163

7264
// Auto-import fully qualified class names
73-
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
65+
$rectorConfig->importNames();
7466

7567
// Are there files or rules you need to skip?
76-
$parameters->set(Option::SKIP, [
77-
__DIR__ . '/src/Config/Auth.php',
68+
$rectorConfig->skip([
7869
__DIR__ . '/src/Views',
7970

8071
JsonThrowOnErrorRector::class,
@@ -88,7 +79,7 @@
8879
__DIR__ . '/tests',
8980
],
9081

91-
// Ignore files that should not be namespaced
82+
// Ignore files that should not be namespaced to their folder
9283
NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [
9384
__DIR__ . '/src/Helpers',
9485
__DIR__ . '/tests/_support',
@@ -100,33 +91,30 @@
10091
// May be uninitialized on purpose
10192
AddDefaultValueForUndefinedVariableRector::class,
10293
]);
103-
104-
// Additional rules to apply
105-
$services = $containerConfigurator->services();
106-
$services->set(SimplifyUselessVariableRector::class);
107-
$services->set(RemoveAlwaysElseRector::class);
108-
$services->set(CountArrayToEmptyArrayComparisonRector::class);
109-
$services->set(ForToForeachRector::class);
110-
$services->set(ChangeNestedForeachIfsToEarlyContinueRector::class);
111-
$services->set(ChangeIfElseValueAssignToEarlyReturnRector::class);
112-
$services->set(SimplifyStrposLowerRector::class);
113-
$services->set(CombineIfRector::class);
114-
$services->set(SimplifyIfReturnBoolRector::class);
115-
$services->set(InlineIfToExplicitIfRector::class);
116-
$services->set(PreparedValueToEarlyReturnRector::class);
117-
$services->set(ShortenElseIfRector::class);
118-
$services->set(SimplifyIfElseToTernaryRector::class);
119-
$services->set(UnusedForeachValueToArrayKeysRector::class);
120-
$services->set(ChangeArrayPushToArrayAssignRector::class);
121-
$services->set(UnnecessaryTernaryExpressionRector::class);
122-
$services->set(AddPregQuoteDelimiterRector::class);
123-
$services->set(SimplifyRegexPatternRector::class);
124-
$services->set(FuncGetArgsToVariadicParamRector::class);
125-
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
126-
$services->set(SimplifyEmptyArrayCheckRector::class);
127-
$services->set(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
128-
$services->set(TypedPropertyRector::class)
129-
->configure([
130-
TypedPropertyRector::INLINE_PUBLIC => true,
94+
$rectorConfig->rule(SimplifyUselessVariableRector::class);
95+
$rectorConfig->rule(RemoveAlwaysElseRector::class);
96+
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
97+
$rectorConfig->rule(ForToForeachRector::class);
98+
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
99+
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
100+
$rectorConfig->rule(SimplifyStrposLowerRector::class);
101+
$rectorConfig->rule(CombineIfRector::class);
102+
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
103+
$rectorConfig->rule(InlineIfToExplicitIfRector::class);
104+
$rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
105+
$rectorConfig->rule(ShortenElseIfRector::class);
106+
$rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
107+
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
108+
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
109+
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
110+
$rectorConfig->rule(AddPregQuoteDelimiterRector::class);
111+
$rectorConfig->rule(SimplifyRegexPatternRector::class);
112+
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
113+
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
114+
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
115+
$rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
116+
$rectorConfig
117+
->ruleWithConfiguration(TypedPropertyRector::class, [
118+
TypedPropertyRector::INLINE_PUBLIC => false,
131119
]);
132120
};

src/Config/Auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use CodeIgniter\Shield\Authentication\Authenticators\AccessTokens;
99
use CodeIgniter\Shield\Authentication\Authenticators\Session;
1010
use CodeIgniter\Shield\Authentication\Passwords\ValidatorInterface;
11+
use CodeIgniter\Shield\Models\UserModel;
1112

1213
class Auth extends BaseConfig
1314
{
@@ -324,7 +325,6 @@ class Auth extends BaseConfig
324325
* OTHER SETTINGS
325326
* ////////////////////////////////////////////////////////////////////
326327
*/
327-
328328
/**
329329
* --------------------------------------------------------------------
330330
* User Provider
@@ -335,7 +335,7 @@ class Auth extends BaseConfig
335335
* You can change it as long as they adhere to the
336336
* CodeIgniter\Shield\Models\UserModel.
337337
*
338-
* @var class-string<\CodeIgniter\Shield\Models\UserModel>
338+
* @var class-string<UserModel>
339339
*/
340340
public string $userProvider = 'CodeIgniter\Shield\Models\UserModel';
341341

tests/Authentication/HasAccessTokensTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function testAccessTokens()
5555
['user_id' => $this->user->id, 'type' => 'access_token', 'secret' => 'secretToken2']
5656
);
5757

58+
/** @var AccessToken[] $tokens */
5859
$tokens = $this->user->accessTokens();
5960

6061
$this->assertCount(2, $tokens);

tests/Unit/UserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testLastLogin()
8787

8888
$last = $this->user->lastLogin();
8989

90-
$this->assertInstanceOf(Login::class, $last);
90+
$this->assertInstanceOf(Login::class, $last); // @phpstan-ignore-line
9191
$this->assertSame($login->id, $last->id);
9292
$this->assertInstanceOf(Time::class, $last->date);
9393
}

0 commit comments

Comments
 (0)