diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2f2b875..558657b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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
diff --git a/.phive/phars.xml b/.phive/phars.xml
index bf43870..4b57f47 100644
--- a/.phive/phars.xml
+++ b/.phive/phars.xml
@@ -1,5 +1,5 @@
-
-
-
+
+
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 756c7f6..6bfe945 100644
--- a/composer.json
+++ b/composer.json
@@ -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",
@@ -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",
diff --git a/phpcs.xml b/phpcs.xml
index 6c56635..d854f2a 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -1,6 +1,15 @@
-
-
-
-
+
+ My custom coding standard.
+
+
+
+
+
+
+ */src/Controller/*
+
+
+ templates/*
+
diff --git a/phpstan.neon b/phpstan.neon
index 36e2ad0..d7f8277 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,6 +1,4 @@
parameters:
level: 6
- checkMissingIterableValueType: false
- checkGenericClassInNonGenericObjectType: false
paths:
- src
diff --git a/src/Model/Behavior/EnumBehavior.php b/src/Model/Behavior/EnumBehavior.php
index ecd3426..3f1ecc8 100644
--- a/src/Model/Behavior/EnumBehavior.php
+++ b/src/Model/Behavior/EnumBehavior.php
@@ -81,7 +81,7 @@ class EnumBehavior extends Behavior
/**
* Class map.
*
- * @var array
+ * @var array>
*/
protected array $classMap = [
'lookup' => LookupStrategy::class,
@@ -92,14 +92,14 @@ class EnumBehavior extends Behavior
/**
* Stack of strategies in use.
*
- * @var array
+ * @var array
*/
protected array $strategies = [];
/**
* Initializes the behavior.
*
- * @param array $config Strategy's configuration.
+ * @param array $config Strategy's configuration.
* @return void
*/
public function initialize(array $config): void
@@ -181,8 +181,8 @@ protected function normalizeConfig(): void
}
/**
- * @param array|string|null $alias Defined list's alias/name.
- * @return array
+ * @param array|string|null $alias Defined list's alias/name.
+ * @return array
* @throws \CakeDC\Enum\Model\Behavior\Exception\MissingEnumConfigurationException
*/
public function enum(array|string|null $alias = null): array
@@ -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 $config Config
+ * @return array
*/
protected function enumList(string $alias, array $config): array
{
@@ -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);
@@ -238,22 +238,22 @@ function (mixed &$item, mixed $val): void {
/**
* Translate list values.
*
- * @param array $list List.
- * @return array
+ * @param array $list List.
+ * @return array
*/
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) {
@@ -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 $args Method's arguments.
* @return bool
* @throws \BadMethodCallException
* @throws \CakeDC\Enum\Model\Behavior\Exception\MissingEnumConfigurationException
@@ -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']};
@@ -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 $options The options for the query
* @return void
*/
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options): void
diff --git a/src/Model/Behavior/Strategy/AbstractStrategy.php b/src/Model/Behavior/Strategy/AbstractStrategy.php
index 37908a2..1f0ba05 100644
--- a/src/Model/Behavior/Strategy/AbstractStrategy.php
+++ b/src/Model/Behavior/Strategy/AbstractStrategy.php
@@ -25,7 +25,7 @@ abstract class AbstractStrategy implements StrategyInterface
/**
* Default configuration.
*
- * @var array
+ * @var array
*/
protected array $_defaultConfig = [];
@@ -56,6 +56,7 @@ public function __construct(string $alias, Table $table)
}
/**
+ * @param array $config
* @inheritDoc
*/
public function initialize(array $config): void
diff --git a/src/Model/Behavior/Strategy/ConfigStrategy.php b/src/Model/Behavior/Strategy/ConfigStrategy.php
index 76de4d2..5d67e75 100644
--- a/src/Model/Behavior/Strategy/ConfigStrategy.php
+++ b/src/Model/Behavior/Strategy/ConfigStrategy.php
@@ -22,8 +22,8 @@ class ConfigStrategy extends AbstractStrategy
/**
* {@inheritDoc}
*
- * @param array $config (unused in this case).
- * @return array
+ * @param array $config (unused in this case).
+ * @return array
*/
public function enum(array $config = []): array
{
diff --git a/src/Model/Behavior/Strategy/ConstStrategy.php b/src/Model/Behavior/Strategy/ConstStrategy.php
index eff663b..884eb44 100644
--- a/src/Model/Behavior/Strategy/ConstStrategy.php
+++ b/src/Model/Behavior/Strategy/ConstStrategy.php
@@ -30,7 +30,7 @@ class ConstStrategy extends AbstractStrategy
/**
* Constants list
*
- * @var array|null
+ * @var array|null
*/
protected ?array $constants = null;
@@ -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 $config List of callable filters to limit items generated from list.
+ * @return array
* @throws \ReflectionException
*/
public function enum(array $config = []): array
@@ -65,7 +65,7 @@ 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);
}
@@ -73,7 +73,7 @@ public function enum(array $config = []): array
/**
* Returns defined constants for the current `$_table`.
*
- * @return array
+ * @return array
* @throws \ReflectionException
*/
protected function getConstants(): array
@@ -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 $options The options for the query
* @return void
*/
public function beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options): void
@@ -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;
diff --git a/src/Model/Behavior/Strategy/LookupStrategy.php b/src/Model/Behavior/Strategy/LookupStrategy.php
index d1547a0..dc18696 100644
--- a/src/Model/Behavior/Strategy/LookupStrategy.php
+++ b/src/Model/Behavior/Strategy/LookupStrategy.php
@@ -25,8 +25,8 @@ class LookupStrategy extends AbstractStrategy
/**
* {@inheritDoc}
*
- * @param array $config (unused in this case).
- * @return array
+ * @param array $config (unused in this case).
+ * @return array
*/
public function enum(array $config = []): array
{
@@ -48,7 +48,7 @@ public function enum(array $config = []): array
/**
* {@inheritDoc}
*
- * @param array $config Strategy's configuration.
+ * @param array $config Strategy's configuration.
* @return void
*/
public function initialize(array $config): void
diff --git a/src/Model/Behavior/Strategy/StrategyInterface.php b/src/Model/Behavior/Strategy/StrategyInterface.php
index ddaf15b..575128c 100644
--- a/src/Model/Behavior/Strategy/StrategyInterface.php
+++ b/src/Model/Behavior/Strategy/StrategyInterface.php
@@ -16,13 +16,13 @@
interface StrategyInterface
{
/**
- * @param array $config Strategy's configuration.
- * @return array
+ * @param array $config Strategy's configuration.
+ * @return array
*/
public function enum(array $config = []): array;
/**
- * @param array $config Configuration.
+ * @param array $config Configuration.
* @return void
*/
public function initialize(array $config): void;
diff --git a/src/Model/Table/LookupsTable.php b/src/Model/Table/LookupsTable.php
index 7a73a68..288cba7 100644
--- a/src/Model/Table/LookupsTable.php
+++ b/src/Model/Table/LookupsTable.php
@@ -20,7 +20,7 @@ class LookupsTable extends Table
/**
* {@inheritDoc}
*
- * @param array $config Table's configuration.
+ * @param array $config Table's configuration.
* @return void
*/
public function initialize(array $config): void
diff --git a/tests/TestCase/Model/Behavior/EnumBehaviorTest.php b/tests/TestCase/Model/Behavior/EnumBehaviorTest.php
index 960f72b..b5fc4b2 100644
--- a/tests/TestCase/Model/Behavior/EnumBehaviorTest.php
+++ b/tests/TestCase/Model/Behavior/EnumBehaviorTest.php
@@ -20,7 +20,7 @@
use Cake\TestSuite\TestCase;
use CakeDC\Enum\Model\Behavior\Strategy\AbstractStrategy;
-// @codingStandardsIgnoreStart
+// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses,Squiz.Classes.ClassFileName.NoMatch
class ArticlesTable extends Table
{
public const STATUS_PUBLIC = 'Published';
@@ -69,7 +69,7 @@ public function enum(array $config = []): array
}
class EnumBehaviorTest extends TestCase
-// @codingStandardsIgnoreEnd
+// phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses,Squiz.Classes.ClassFileName.NoMatch
{
public array $fixtures = [
'plugin.CakeDC/Enum.Articles',
@@ -249,7 +249,7 @@ public static function provideBasicLookups(): array
*/
public function testBasicLookups($group, $expected)
{
- $result = $this->Articles->enum($group);
+ $result = $this->Articles->getBehavior('Enum')->enum($group);
$this->assertEquals($expected, $result);
}
@@ -305,7 +305,7 @@ public function testBuildRules($data, $expected)
public function testEnumNested()
{
$this->Articles->behaviors()->Enum->setConfig('nested', true);
- $result = $this->Articles->enum('priority');
+ $result = $this->Articles->getBehavior('Enum')->enum('priority');
$expected = [
['value' => 'URGENT', 'text' => 'Urgent'],
['value' => 'HIGH', 'text' => 'High'],
@@ -329,7 +329,7 @@ public function testAssociationsCreated()
public function testEnumMultipleAlias()
{
- $result = $this->Articles->enum();
+ $result = $this->Articles->getBehavior('Enum')->enum();
$expected = [
'priority' => [
'URGENT' => 'Urgent',
@@ -366,10 +366,10 @@ public function testEnumMultipleAlias()
];
$this->assertEquals($expected, $result);
- $result = $this->Articles->enum([]);
+ $result = $this->Articles->getBehavior('Enum')->enum([]);
$this->assertEquals($expected, $result);
- $result = $this->Articles->enum(['priority', 'status']);
+ $result = $this->Articles->getBehavior('Enum')->enum(['priority', 'status']);
$expected = [
'priority' => [
'URGENT' => 'Urgent',
@@ -388,11 +388,11 @@ public function testEnumMultipleAlias()
public function testTranslatedValues()
{
$this->Articles->behaviors()->Enum->setConfig('translate', true);
- $result = $this->Articles->enum('node_group');
+ $result = $this->Articles->getBehavior('Enum')->enum('node_group');
$this->assertEquals(['active' => 'Translated Active'], $result);
- $result = $this->Articles->enum(['node_group', 'norules']);
+ $result = $this->Articles->getBehavior('Enum')->enum(['node_group', 'norules']);
$expected = [
'node_group' => ['active' => 'Translated Active'],
@@ -427,7 +427,7 @@ public function testThirdPartyStrategy(array $config, array $expected)
$this->getTableLocator()->clear();
$Articles = $this->getTableLocator()->get('CakeDC/Enum.Articles', ['table' => 'enum_articles']);
$Articles->addBehavior('CakeDC/Enum.Enum', $config);
- $result = $Articles->enum('article_category');
+ $result = $Articles->getBehavior('Enum')->enum('article_category');
$this->assertEquals($expected, $result);
}
}
diff --git a/tests/TestCase/Model/Behavior/Strategy/ConstStrategyTest.php b/tests/TestCase/Model/Behavior/Strategy/ConstStrategyTest.php
index b6e5b49..da04687 100644
--- a/tests/TestCase/Model/Behavior/Strategy/ConstStrategyTest.php
+++ b/tests/TestCase/Model/Behavior/Strategy/ConstStrategyTest.php
@@ -18,7 +18,7 @@
use Cake\TestSuite\TestCase;
use CakeDC\Enum\Model\Behavior\Strategy\ConstStrategy;
-// @codingStandardsIgnoreStart
+// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses,Squiz.Classes.ClassFileName.NoMatch
class ArticlesTable extends Table
{
public const EXTRA_VALUE = 'Extra';
@@ -37,7 +37,7 @@ class Article extends Entity
public const STATUS_ARCHIVE = 'Archived';
}
class ConstStrategyTest extends TestCase
-// @codingStandardsIgnoreEnd
+// phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses,Squiz.Classes.ClassFileName.NoMatch
{
public ConstStrategy $StrategyTable;