Skip to content
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
90 changes: 80 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,91 @@ name: CI

on:
push:
branches:
- master
- 3.next-cake5
pull_request:
branches:
- '*'

permissions:
contents: read

jobs:
testsuite:
uses: cakephp/.github/.github/workflows/testsuite-with-db.yml@5.x
secrets: inherit
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php-version: ['8.2', '8.3', '8.4']
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, pdo_sqlite
coverage: pcov

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}

- name: composer install
run: composer install --prefer-dist --no-progress

- name: Setup problem matchers for PHPUnit
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit with coverage
if: matrix.php-version == '8.2' && matrix.os == 'ubuntu-latest'
run: |
export CODECOVERAGE=1
vendor/bin/phpunit --configuration=phpunit.xml.dist --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml

- name: Run PHPUnit without coverage
if: matrix.php-version != '8.3' || matrix.os != 'ubuntu-latest'
run: vendor/bin/phpunit --configuration=phpunit.xml.dist

- name: Submit code coverage
if: matrix.php-version == '8.3' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3

cs-stan:
uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x
secrets: inherit
name: Coding Standard & Static Analysis
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, intl, pdo_sqlite
coverage: none
tools: phive

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}

- name: composer install
run: composer install --prefer-dist --no-progress

- name: Install phive
run: |
wget -O phive.phar https://phar.io/releases/phive.phar
chmod +x phive.phar
sudo mv phive.phar /usr/local/bin/phive

- name: Install PHP tools with phive
run: |
phive install --trust-gpg-keys CF1A108D0E7AE720,51C67305FFC2E5C0,12CE0F1D262429A5,99BF4D9A33D65E1E

- name: Run PHP CodeSniffer
run: composer cs-check

- name: Run phpstan
run: composer stan
6 changes: 3 additions & 3 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.67" installed="1.10.67" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.23.1" installed="5.23.1" location="./tools/psalm" copy="false"/>
</phive>
<phar name="phpstan" version="2.1.17" installed="2.1.17" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="6.12.0" installed="6.12.0" location="./tools/psalm" copy="false"/>
</phive>
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"source": "https://github.com/cakedc/enum"
},
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0.6"
"php": ">=8.2",
"cakephp/cakephp": "^5.3"
},
"require-dev": {
"phpunit/phpunit": "^10.5.20",
Expand Down Expand Up @@ -44,8 +44,7 @@
"phpstan": "tools/phpstan analyse",
"psalm": "tools/psalm --show-info=false",
"stan": [
"@phpstan",
"@psalm"
"@phpstan"
],
"stan-tests": "phpstan.phar analyze -c tests/phpstan.neon",
"stan-baseline": "phpstan.phar --generate-baseline",
Expand Down
17 changes: 13 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?xml version="1.0"?>
<ruleset name="cakedc/enum">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />
<ruleset name="AppStandard">
<description>My custom coding standard.</description>
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP">
<exclude name="CakePHP.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Generic.Files.LineEndings.InvalidEOLChar"/>
<exclude name="Generic.Files.LineLength.TooLong"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
<exclude-pattern>*/src/Controller/*</exclude-pattern>
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent.Incorrect">
<exclude-pattern>templates/*</exclude-pattern>
</rule>
</ruleset>
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
parameters:
level: 6
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src
40 changes: 20 additions & 20 deletions src/Model/Behavior/EnumBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class EnumBehavior extends Behavior
/**
* Class map.
*
* @var array
* @var array<string, class-string<\CakeDC\Enum\Model\Behavior\Strategy\StrategyInterface>>
*/
protected array $classMap = [
'lookup' => LookupStrategy::class,
Expand All @@ -92,14 +92,14 @@ class EnumBehavior extends Behavior
/**
* Stack of strategies in use.
*
* @var array
* @var array<string, \CakeDC\Enum\Model\Behavior\Strategy\StrategyInterface>
*/
protected array $strategies = [];

/**
* Initializes the behavior.
*
* @param array $config Strategy's configuration.
* @param array<string, mixed> $config Strategy's configuration.
* @return void
*/
public function initialize(array $config): void
Expand Down Expand Up @@ -181,8 +181,8 @@ protected function normalizeConfig(): void
}

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

/**
* @param string $alias List alias.
* @param array $config Config
* @return array
* @param array<string, mixed> $config Config
* @return array<string, mixed>
*/
protected function enumList(string $alias, array $config): array
{
Expand All @@ -226,7 +226,7 @@ protected function enumList(string $alias, array $config): array
$return,
function (mixed &$item, mixed $val): void {
$item = ['value' => $val, 'text' => $item];
}
},
);

$return = array_values($return);
Expand All @@ -238,22 +238,22 @@ function (mixed &$item, mixed $val): void {
/**
* Translate list values.
*
* @param array $list List.
* @return array
* @param array<string, mixed> $list List.
* @return array<string, mixed>
*/
protected function translate(array $list): array
{
$domain = $this->getConfig('translationDomain');

return array_map(fn ($value) => __d($domain, $value), $list);
return array_map(fn($value) => __d($domain, $value), $list);
}

/**
* @param \Cake\Event\EventInterface $event Event.
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event Event.
* @param \Cake\ORM\RulesChecker $rules Rules checker.
* @return \Cake\ORM\RulesChecker
* @return void
*/
public function buildRules(EventInterface $event, RulesChecker $rules): RulesChecker
public function buildRules(EventInterface $event, RulesChecker $rules): void
{
foreach ($this->getConfig('lists') as $alias => $config) {
if (Hash::get($config, 'applicationRules') === false) {
Expand All @@ -267,14 +267,14 @@ public function buildRules(EventInterface $event, RulesChecker $rules): RulesChe
]);
}

return $rules;
$event->setResult($rules);
}

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

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

/**
* @param \Cake\Event\EventInterface $event The beforeFind event that was fired.
* @param \Cake\ORM\Query\SelectQuery $query Query
* @param \ArrayObject $options The options for the query
* @param \Cake\Event\EventInterface<\Cake\ORM\Table> $event The beforeFind event that was fired.
* @param \Cake\ORM\Query\SelectQuery<\Cake\Datasource\EntityInterface> $query Query
* @param \ArrayObject<string, mixed> $options The options for the query
* @return void
*/
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options): void
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Behavior/Strategy/AbstractStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class AbstractStrategy implements StrategyInterface
/**
* Default configuration.
*
* @var array
* @var array<string, mixed>
*/
protected array $_defaultConfig = [];

Expand Down Expand Up @@ -56,6 +56,7 @@ public function __construct(string $alias, Table $table)
}

/**
* @param array<string, mixed> $config
* @inheritDoc
*/
public function initialize(array $config): void
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Behavior/Strategy/ConfigStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ConfigStrategy extends AbstractStrategy
/**
* {@inheritDoc}
*
* @param array $config (unused in this case).
* @return array
* @param array<string, mixed> $config (unused in this case).
* @return array<string, mixed>
*/
public function enum(array $config = []): array
{
Expand Down
22 changes: 11 additions & 11 deletions src/Model/Behavior/Strategy/ConstStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConstStrategy extends AbstractStrategy
/**
* Constants list
*
* @var array|null
* @var array<string, mixed>|null
*/
protected ?array $constants = null;

Expand All @@ -50,8 +50,8 @@ public function __construct(string $alias, Table $table)
/**
* {@inheritDoc}
*
* @param array $config List of callable filters to limit items generated from list.
* @return array
* @param array<string, mixed> $config List of callable filters to limit items generated from list.
* @return array<string, mixed>
* @throws \ReflectionException
*/
public function enum(array $config = []): array
Expand All @@ -65,15 +65,15 @@ public function enum(array $config = []): array
}
}

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

return array_combine($keys, $values);
}

/**
* Returns defined constants for the current `$_table`.
*
* @return array
* @return array<string, mixed>
* @throws \ReflectionException
*/
protected function getConstants(): array
Expand Down Expand Up @@ -103,9 +103,9 @@ protected function getConstants(): array
}

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

$contain = array_filter(
$query->getContain(),
fn ($value): bool => $value !== $assocName,
ARRAY_FILTER_USE_KEY
fn($value): bool => $value !== $assocName,
ARRAY_FILTER_USE_KEY,
);

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

$query->formatResults(fn (CollectionInterface $results) => $results
$query->formatResults(fn(CollectionInterface $results) => $results
->map(function (mixed $row): mixed {
if (is_string($row) || !$row) {
return $row;
Expand Down
Loading
Loading