Skip to content

Commit 31ef7d8

Browse files
authored
Merge pull request #41 from tattersoftware/retool
Update Toolkit
2 parents c7ffd42 + 410f891 commit 31ef7d8

File tree

12 files changed

+161
-26
lines changed

12 files changed

+161
-26
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.github/workflows/psalm.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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: Psalm Analysis
24+
runs-on: ubuntu-latest
25+
if: "!contains(github.event.head_commit.message, '[ci skip]')"
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: '8.0'
35+
tools: phpstan, phpunit
36+
extensions: intl, json, mbstring, xml
37+
coverage: none
38+
env:
39+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Get composer cache directory
42+
id: composer-cache
43+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
44+
45+
- name: Cache composer dependencies
46+
uses: actions/cache@v3
47+
with:
48+
path: ${{ steps.composer-cache.outputs.dir }}
49+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
50+
restore-keys: ${{ runner.os }}-composer-
51+
52+
- name: Create Psalm cache directory
53+
run: mkdir -p build/psalm
54+
55+
- name: Cache Psalm results
56+
uses: actions/cache@v3
57+
with:
58+
path: build/psalm
59+
key: ${{ runner.os }}-psalm-${{ github.sha }}
60+
restore-keys: ${{ runner.os }}-psalm-
61+
62+
- name: Install dependencies
63+
run: |
64+
if [ -f composer.lock ]; then
65+
composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
66+
else
67+
composer update --no-progress --no-interaction --prefer-dist --optimize-autoloader
68+
fi
69+
70+
- name: Run Psalm analysis
71+
run: vendor/bin/psalm

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@
5151
"sort-packages": true
5252
},
5353
"scripts": {
54-
"analyze": "phpstan analyze",
54+
"analyze": [
55+
"phpstan analyze",
56+
"psalm",
57+
"rector process --dry-run"
58+
],
5559
"ci": [
5660
"Composer\\Config::disableProcessTimeout",
5761
"@deduplicate",
5862
"@analyze",
63+
"@composer normalize --dry-run",
5964
"@test",
6065
"@inspect",
61-
"rector process",
6266
"@style"
6367
],
6468
"deduplicate": "phpcpd app/ src/",

psalm.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="7"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
autoloader="psalm_autoload.php"
9+
cacheDirectory="build/psalm/"
10+
>
11+
<projectFiles>
12+
<directory name="src/" />
13+
<directory name="tests/" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
</psalm>

psalm_autoload.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require __DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php';
6+
7+
$helperDirs = [
8+
'vendor/codeigniter4/framework/system/Helpers',
9+
];
10+
11+
foreach ($helperDirs as $dir) {
12+
$dir = __DIR__ . '/' . $dir;
13+
chdir($dir);
14+
15+
foreach (glob('*_helper.php') as $filename) {
16+
$filePath = realpath($dir . '/' . $filename);
17+
18+
require_once $filePath;
19+
}
20+
}

rector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
$rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
115115
$rectorConfig
116116
->ruleWithConfiguration(TypedPropertyRector::class, [
117-
TypedPropertyRector::INLINE_PUBLIC => false,
117+
// Set to false if you use in libraries, or it does create breaking changes.
118+
TypedPropertyRector::INLINE_PUBLIC => true,
118119
]);
119120
};

src/Commands/HandlersCache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class HandlersCache extends BaseCommand
1414
protected $description = 'Discovers and caches all handlers';
1515
protected $usage = 'handlers:cache';
1616

17+
/**
18+
* @return void
19+
*/
1720
public function run(array $params = [])
1821
{
1922
// Make sure caching is enabled

src/Commands/HandlersClear.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class HandlersClear extends BaseCommand
1212
protected $description = 'Clears cached versions of discovered handlers';
1313
protected $usage = 'handlers:clear';
1414

15+
/**
16+
* @return void
17+
*/
1518
public function run(array $params = [])
1619
{
1720
$count = cache()->deleteMatching('handlers-*');

tests/BaseFactoryTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
final class BaseFactoryTest extends TestCase
1212
{
13-
public function testNoDiscoveryReturnsEmptyArray()
13+
public function testNoDiscoveryReturnsEmptyArray(): void
1414
{
1515
$factory = new class () extends BaseFactory {
1616
public const HANDLER_PATH = 'Bananas';
@@ -19,7 +19,7 @@ public function testNoDiscoveryReturnsEmptyArray()
1919
$this->assertSame([], $factory::findAll());
2020
}
2121

22-
public function testGetHandlerClassReturnsClass()
22+
public function testGetHandlerClassReturnsClass(): void
2323
{
2424
$expected = 'Tests\Support\Cars\WidgetCar';
2525

@@ -29,36 +29,36 @@ public function testGetHandlerClassReturnsClass()
2929
$this->assertSame($expected, $result);
3030
}
3131

32-
public function testGetHandlerClassRequiresPhpExtension()
32+
public function testGetHandlerClassRequiresPhpExtension(): void
3333
{
3434
$result = CarFactory::getHandlerClass('foo', 'bar');
3535

3636
$this->assertNull($result);
3737
}
3838

39-
public function testGetHandlerClassRequiresInterfaces()
39+
public function testGetHandlerClassRequiresInterfaces(): void
4040
{
4141
$result = CarFactory::getHandlerClass(SUPPORTPATH . 'Cars/NotCar.php', 'Tests\Support');
4242

4343
$this->assertNull($result);
4444
}
4545

46-
public function testGetHandlerClassRequiresHandlerInterface()
46+
public function testGetHandlerClassRequiresHandlerInterface(): void
4747
{
4848
$result = CarFactory::getHandlerClass(SUPPORTPATH . 'Cars/BadCar.php', 'Tests\Support');
4949

5050
$this->assertNull($result);
5151
}
5252

53-
public function testGetHandlerClassFails()
53+
public function testGetHandlerClassFails(): void
5454
{
5555
$file = realpath(SUPPORTPATH . 'Cars/WidgetCar.php');
5656
$result = CarFactory::getHandlerClass($file, 'Foo\Bar');
5757

5858
$this->assertNull($result);
5959
}
6060

61-
public function testIgnoresClass()
61+
public function testIgnoresClass(): void
6262
{
6363
config('Handlers')->ignoredClasses[] = 'Tests\Support\Cars\PopCar';
6464

@@ -68,7 +68,7 @@ public function testIgnoresClass()
6868
$this->assertSame($expected, $result);
6969
}
7070

71-
public function testCollision()
71+
public function testCollision(): void
7272
{
7373
// Stop ignoring the collision clas
7474
config('Handlers')->ignoredClasses = [];
@@ -79,7 +79,7 @@ public function testCollision()
7979
CarFactory::findAll();
8080
}
8181

82-
public function testFindAll()
82+
public function testFindAll(): void
8383
{
8484
$expected = [
8585
'pop' => 'Tests\Support\Cars\PopCar',
@@ -91,7 +91,7 @@ public function testFindAll()
9191
$this->assertSame($expected, $result);
9292
}
9393

94-
public function testFind()
94+
public function testFind(): void
9595
{
9696
$expected = 'Tests\Support\Cars\PopCar';
9797

@@ -100,15 +100,15 @@ public function testFind()
100100
$this->assertSame($expected, $result);
101101
}
102102

103-
public function testFindThrows()
103+
public function testFindThrows(): void
104104
{
105105
$this->expectException('RuntimeException');
106106
$this->expectExceptionMessage('Unknown handler "banana" for ' . CarFactory::class);
107107

108108
CarFactory::find('banana');
109109
}
110110

111-
public function testResetSingle()
111+
public function testResetSingle(): void
112112
{
113113
CarFactory::findAll();
114114
FactoryFactory::findAll();
@@ -121,7 +121,7 @@ public function testResetSingle()
121121
$this->assertSame(['Factories'], array_keys($result));
122122
}
123123

124-
public function testResetAll()
124+
public function testResetAll(): void
125125
{
126126
CarFactory::findAll();
127127
FactoryFactory::findAll();

tests/CacheTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function tearDown(): void
1515
CarFactory::clearCache();
1616
}
1717

18-
public function testDiscoveryUsesCache()
18+
public function testDiscoveryUsesCache(): void
1919
{
2020
// Reenable caching
2121
config('Handlers')->cacheDuration = MINUTE;
@@ -28,7 +28,7 @@ public function testDiscoveryUsesCache()
2828
$this->assertSame($expected, $result); // @phpstan-ignore-line
2929
}
3030

31-
public function testDiscoveryCreatesCache()
31+
public function testDiscoveryCreatesCache(): void
3232
{
3333
// Reenable caching
3434
config('Handlers')->cacheDuration = MINUTE;
@@ -41,7 +41,7 @@ public function testDiscoveryCreatesCache()
4141
$this->assertSame('Tests\Support\Cars\PopCar', $result['pop']);
4242
}
4343

44-
public function testDiscoveryIgnoresCache()
44+
public function testDiscoveryIgnoresCache(): void
4545
{
4646
$expected = [
4747
'pop' => 'Tests\Support\Cars\PopCar',

0 commit comments

Comments
 (0)