Skip to content

Commit 2f0230d

Browse files
committed
Switch to CodeIgniter DevKit
1 parent 25778aa commit 2f0230d

File tree

5 files changed

+138
-83
lines changed

5 files changed

+138
-83
lines changed

.github/workflows/psalm.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Psalm
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
paths:
8+
- '**.php'
9+
- 'composer.*'
10+
- 'psalm*'
11+
- '.github/workflows/psalm.yml'
12+
push:
13+
branches:
14+
- develop
15+
paths:
16+
- '**.php'
17+
- 'composer.*'
18+
- 'psalm*'
19+
- '.github/workflows/psalm.yml'
20+
21+
jobs:
22+
build:
23+
name: PHP ${{ matrix.php-versions }} Psalm Analysis
24+
runs-on: ubuntu-latest
25+
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']
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v3
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php-versions }}
39+
tools: phpstan, phpunit
40+
extensions: intl, json, mbstring, xml
41+
coverage: none
42+
env:
43+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Get composer cache directory
46+
id: composer-cache
47+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
48+
49+
- name: Cache composer dependencies
50+
uses: actions/cache@v3
51+
with:
52+
path: ${{ steps.composer-cache.outputs.dir }}
53+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
54+
restore-keys: ${{ runner.os }}-composer-
55+
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+
66+
- name: Install dependencies
67+
run: |
68+
if [ -f composer.lock ]; then
69+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
70+
else
71+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
72+
fi
73+
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
}

deptrac.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ parameters:
22
paths:
33
- ./src/
44
- ./vendor/codeigniter4/framework/system/
5-
- ./vendor/codeigniter4/settings/src/
65
exclude_files:
76
- '#.*test.*#i'
87
layers:
@@ -103,7 +102,6 @@ parameters:
103102
- Vendor Entity
104103
- Vendor Model
105104
Config:
106-
- Model
107105
- Service
108106
- Vendor Config
109107
Model:

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: 36 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,
@@ -91,7 +82,6 @@
9182
// Ignore files that should not be namespaced
9283
NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [
9384
__DIR__ . '/src/Helpers',
94-
__DIR__ . '/tests/_support',
9585
],
9686

9787
// May load view files directly when detecting classes
@@ -100,33 +90,30 @@
10090
// May be uninitialized on purpose
10191
AddDefaultValueForUndefinedVariableRector::class,
10292
]);
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,
93+
$rectorConfig->rule(SimplifyUselessVariableRector::class);
94+
$rectorConfig->rule(RemoveAlwaysElseRector::class);
95+
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
96+
$rectorConfig->rule(ForToForeachRector::class);
97+
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
98+
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
99+
$rectorConfig->rule(SimplifyStrposLowerRector::class);
100+
$rectorConfig->rule(CombineIfRector::class);
101+
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
102+
$rectorConfig->rule(InlineIfToExplicitIfRector::class);
103+
$rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
104+
$rectorConfig->rule(ShortenElseIfRector::class);
105+
$rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
106+
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
107+
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
108+
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
109+
$rectorConfig->rule(AddPregQuoteDelimiterRector::class);
110+
$rectorConfig->rule(SimplifyRegexPatternRector::class);
111+
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
112+
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
113+
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
114+
$rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
115+
$rectorConfig
116+
->ruleWithConfiguration(TypedPropertyRector::class, [
117+
TypedPropertyRector::INLINE_PUBLIC => false,
131118
]);
132119
};

0 commit comments

Comments
 (0)