Skip to content

Commit fd81f54

Browse files
authored
Merge pull request #67 from skie/3.next-cake5
cakephp 5.3 compatible
2 parents f27a8aa + 8063ecd commit fd81f54

14 files changed

Lines changed: 153 additions & 76 deletions

File tree

.github/workflows/ci.yml

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,91 @@ name: CI
22

33
on:
44
push:
5-
branches:
6-
- master
7-
- 3.next-cake5
85
pull_request:
96
branches:
107
- '*'
118

12-
permissions:
13-
contents: read
14-
159
jobs:
1610
testsuite:
17-
uses: cakephp/.github/.github/workflows/testsuite-with-db.yml@5.x
18-
secrets: inherit
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
php-version: ['8.2', '8.3', '8.4']
16+
os: [ubuntu-latest, windows-latest]
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-version }}
24+
extensions: mbstring, intl, pdo_sqlite
25+
coverage: pcov
26+
27+
- name: Cache composer dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.composer/cache
31+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
32+
33+
- name: composer install
34+
run: composer install --prefer-dist --no-progress
35+
36+
- name: Setup problem matchers for PHPUnit
37+
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
38+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
39+
40+
- name: Run PHPUnit with coverage
41+
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
42+
run: |
43+
export CODECOVERAGE=1
44+
vendor/bin/phpunit --configuration=phpunit.xml.dist --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml
45+
46+
- name: Run PHPUnit without coverage
47+
if: matrix.php-version != '8.3' || matrix.os != 'ubuntu-latest'
48+
run: vendor/bin/phpunit --configuration=phpunit.xml.dist
49+
50+
- name: Submit code coverage
51+
if: matrix.php-version == '8.3' && matrix.os == 'ubuntu-latest'
52+
uses: codecov/codecov-action@v3
1953

2054
cs-stan:
21-
uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x
22-
secrets: inherit
55+
name: Coding Standard & Static Analysis
56+
runs-on: ubuntu-latest
57+
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Setup PHP
62+
uses: shivammathur/setup-php@v2
63+
with:
64+
php-version: '8.3'
65+
extensions: mbstring, intl, pdo_sqlite
66+
coverage: none
67+
tools: phive
68+
69+
- name: Cache composer dependencies
70+
uses: actions/cache@v4
71+
with:
72+
path: ~/.composer/cache
73+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
74+
75+
- name: composer install
76+
run: composer install --prefer-dist --no-progress
77+
78+
- name: Install phive
79+
run: |
80+
wget -O phive.phar https://phar.io/releases/phive.phar
81+
chmod +x phive.phar
82+
sudo mv phive.phar /usr/local/bin/phive
83+
84+
- name: Install PHP tools with phive
85+
run: |
86+
phive install --trust-gpg-keys CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5,99BF4D9A33D65E1E
87+
88+
- name: Run PHP CodeSniffer
89+
run: composer cs-check
90+
91+
- name: Run phpstan
92+
run: composer stan

.phive/phars.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpstan" version="1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/>
4-
<phar name="psalm" version="5.23.1" installed="5.23.1" location="./tools/psalm" copy="false"/>
5-
</phive>
3+
<phar name="phpstan" version="2.1.17" installed="2.1.17" location="./tools/phpstan" copy="false"/>
4+
<phar name="psalm" version="6.12.0" installed="6.12.0" location="./tools/psalm" copy="false"/>
5+
</phive>

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"source": "https://github.com/cakedc/enum"
1515
},
1616
"require": {
17-
"php": ">=8.1",
18-
"cakephp/cakephp": "^5.0.6"
17+
"php": ">=8.2",
18+
"cakephp/cakephp": "^5.3"
1919
},
2020
"require-dev": {
2121
"phpunit/phpunit": "^10.5.20",
@@ -44,8 +44,7 @@
4444
"phpstan": "tools/phpstan analyse",
4545
"psalm": "tools/psalm --show-info=false",
4646
"stan": [
47-
"@phpstan",
48-
"@psalm"
47+
"@phpstan"
4948
],
5049
"stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
5150
"stan-baseline": "phpstan.phar --generate-baseline",

phpcs.xml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?xml version="1.0"?>
2-
<ruleset name="cakedc/enum">
3-
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />
4-
5-
<rule ref="CakePHP" />
2+
<ruleset name="AppStandard">
3+
<description>My custom coding standard.</description>
4+
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP">
5+
<exclude name="CakePHP.Commenting.FunctionComment.MissingParamComment"/>
6+
<exclude name="Generic.Files.LineEndings.InvalidEOLChar"/>
7+
<exclude name="Generic.Files.LineLength.TooLong"/>
8+
</rule>
9+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
10+
<exclude-pattern>*/src/Controller/*</exclude-pattern>
11+
</rule>
12+
<rule ref="Generic.WhiteSpace.ScopeIndent.Incorrect">
13+
<exclude-pattern>templates/*</exclude-pattern>
14+
</rule>
615
</ruleset>

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
parameters:
22
level: 6
3-
checkMissingIterableValueType: false
4-
checkGenericClassInNonGenericObjectType: false
53
paths:
64
- src

src/Model/Behavior/EnumBehavior.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class EnumBehavior extends Behavior
8181
/**
8282
* Class map.
8383
*
84-
* @var array
84+
* @var array<string, class-string<\CakeDC\Enum\Model\Behavior\Strategy\StrategyInterface>>
8585
*/
8686
protected array $classMap = [
8787
'lookup' => LookupStrategy::class,
@@ -92,14 +92,14 @@ class EnumBehavior extends Behavior
9292
/**
9393
* Stack of strategies in use.
9494
*
95-
* @var array
95+
* @var array<string, \CakeDC\Enum\Model\Behavior\Strategy\StrategyInterface>
9696
*/
9797
protected array $strategies = [];
9898

9999
/**
100100
* Initializes the behavior.
101101
*
102-
* @param array $config Strategy's configuration.
102+
* @param array<string, mixed> $config Strategy's configuration.
103103
* @return void
104104
*/
105105
public function initialize(array $config): void
@@ -181,8 +181,8 @@ protected function normalizeConfig(): void
181181
}
182182

183183
/**
184-
* @param array|string|null $alias Defined list's alias/name.
185-
* @return array
184+
* @param array<int, string>|string|null $alias Defined list's alias/name.
185+
* @return array<string, mixed>
186186
* @throws \CakeDC\Enum\Model\Behavior\Exception\MissingEnumConfigurationException
187187
*/
188188
public function enum(array|string|null $alias = null): array
@@ -211,8 +211,8 @@ public function enum(array|string|null $alias = null): array
211211

212212
/**
213213
* @param string $alias List alias.
214-
* @param array $config Config
215-
* @return array
214+
* @param array<string, mixed> $config Config
215+
* @return array<string, mixed>
216216
*/
217217
protected function enumList(string $alias, array $config): array
218218
{
@@ -226,7 +226,7 @@ protected function enumList(string $alias, array $config): array
226226
$return,
227227
function (mixed &$item, mixed $val): void {
228228
$item = ['value' => $val, 'text' => $item];
229-
}
229+
},
230230
);
231231

232232
$return = array_values($return);
@@ -238,22 +238,22 @@ function (mixed &$item, mixed $val): void {
238238
/**
239239
* Translate list values.
240240
*
241-
* @param array $list List.
242-
* @return array
241+
* @param array<string, mixed> $list List.
242+
* @return array<string, mixed>
243243
*/
244244
protected function translate(array $list): array
245245
{
246246
$domain = $this->getConfig('translationDomain');
247247

248-
return array_map(fn ($value) => __d($domain, $value), $list);
248+
return array_map(fn($value) => __d($domain, $value), $list);
249249
}
250250

251251
/**
252-
* @param \Cake\Event\EventInterface $event Event.
252+
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Event.
253253
* @param \Cake\ORM\RulesChecker $rules Rules checker.
254-
* @return \Cake\ORM\RulesChecker
254+
* @return void
255255
*/
256-
public function buildRules(EventInterface $event, RulesChecker $rules): RulesChecker
256+
public function buildRules(EventInterface $event, RulesChecker $rules): void
257257
{
258258
foreach ($this->getConfig('lists') as $alias => $config) {
259259
if (Hash::get($config, 'applicationRules') === false) {
@@ -267,14 +267,14 @@ public function buildRules(EventInterface $event, RulesChecker $rules): RulesChe
267267
]);
268268
}
269269

270-
return $rules;
270+
$event->setResult($rules);
271271
}
272272

273273
/**
274274
* Universal validation rule for lists.
275275
*
276276
* @param string $method Method name.
277-
* @param array $args Method's arguments.
277+
* @param array<int, mixed> $args Method's arguments.
278278
* @return bool
279279
* @throws \BadMethodCallException
280280
* @throws \CakeDC\Enum\Model\Behavior\Exception\MissingEnumConfigurationException
@@ -293,7 +293,7 @@ public function __call(string $method, array $args): bool
293293
throw new MissingEnumConfigurationException([$alias]);
294294
}
295295

296-
if ($entity->isEmpty($config['field']) && Hash::get($config, 'allowEmpty') === true) {
296+
if (!$entity->hasValue($config['field']) && Hash::get($config, 'allowEmpty') === true) {
297297
return true;
298298
}
299299
$value = $entity->{$config['field']};
@@ -307,9 +307,9 @@ public function __call(string $method, array $args): bool
307307
}
308308

309309
/**
310-
* @param \Cake\Event\EventInterface $event The beforeFind event that was fired.
311-
* @param \Cake\ORM\Query\SelectQuery $query Query
312-
* @param \ArrayObject $options The options for the query
310+
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event The beforeFind event that was fired.
311+
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query Query
312+
* @param \ArrayObject<string, mixed> $options The options for the query
313313
* @return void
314314
*/
315315
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options): void

src/Model/Behavior/Strategy/AbstractStrategy.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class AbstractStrategy implements StrategyInterface
2525
/**
2626
* Default configuration.
2727
*
28-
* @var array
28+
* @var array<string, mixed>
2929
*/
3030
protected array $_defaultConfig = [];
3131

@@ -56,6 +56,7 @@ public function __construct(string $alias, Table $table)
5656
}
5757

5858
/**
59+
* @param array<string, mixed> $config
5960
* @inheritDoc
6061
*/
6162
public function initialize(array $config): void

src/Model/Behavior/Strategy/ConfigStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class ConfigStrategy extends AbstractStrategy
2222
/**
2323
* {@inheritDoc}
2424
*
25-
* @param array $config (unused in this case).
26-
* @return array
25+
* @param array<string, mixed> $config (unused in this case).
26+
* @return array<string, mixed>
2727
*/
2828
public function enum(array $config = []): array
2929
{

src/Model/Behavior/Strategy/ConstStrategy.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ConstStrategy extends AbstractStrategy
3030
/**
3131
* Constants list
3232
*
33-
* @var array|null
33+
* @var array<string, mixed>|null
3434
*/
3535
protected ?array $constants = null;
3636

@@ -50,8 +50,8 @@ public function __construct(string $alias, Table $table)
5050
/**
5151
* {@inheritDoc}
5252
*
53-
* @param array $config List of callable filters to limit items generated from list.
54-
* @return array
53+
* @param array<string, mixed> $config List of callable filters to limit items generated from list.
54+
* @return array<string, mixed>
5555
* @throws \ReflectionException
5656
*/
5757
public function enum(array $config = []): array
@@ -65,15 +65,15 @@ public function enum(array $config = []): array
6565
}
6666
}
6767

68-
$values = array_map(fn ($v): mixed => $constants[$v], $keys);
68+
$values = array_map(fn($v): mixed => $constants[$v], $keys);
6969

7070
return array_combine($keys, $values);
7171
}
7272

7373
/**
7474
* Returns defined constants for the current `$_table`.
7575
*
76-
* @return array
76+
* @return array<string, mixed>
7777
* @throws \ReflectionException
7878
*/
7979
protected function getConstants(): array
@@ -103,9 +103,9 @@ protected function getConstants(): array
103103
}
104104

105105
/**
106-
* @param \Cake\Event\EventInterface $event The beforeFind event that was fired.
107-
* @param \Cake\ORM\Query\SelectQuery $query Query
108-
* @param \ArrayObject $options The options for the query
106+
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event The beforeFind event that was fired.
107+
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query Query
108+
* @param \ArrayObject<string, mixed> $options The options for the query
109109
* @return void
110110
*/
111111
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options): void
@@ -117,13 +117,13 @@ public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObjec
117117

118118
$contain = array_filter(
119119
$query->getContain(),
120-
fn ($value): bool => $value !== $assocName,
121-
ARRAY_FILTER_USE_KEY
120+
fn($value): bool => $value !== $assocName,
121+
ARRAY_FILTER_USE_KEY,
122122
);
123123

124124
$query->clearContain()->contain($contain);
125125

126-
$query->formatResults(fn (CollectionInterface $results) => $results
126+
$query->formatResults(fn(CollectionInterface $results) => $results
127127
->map(function (mixed $row): mixed {
128128
if (is_string($row) || !$row) {
129129
return $row;

0 commit comments

Comments
 (0)