diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a9f666..5301470 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: php-version: '8.1' extensions: mbstring, intl coverage: none - tools: vimeo/psalm:5, phpstan:1.9, cs2pr + tools: vimeo/psalm:5, phpstan:1.10, cs2pr - name: Composer Install run: composer require --dev cakephp/cakephp-codesniffer:^5.0 diff --git a/.gitignore b/.gitignore index 5209c91..ad93557 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor/ composer.lock tmp .phpunit.result.cache +.phpunit.cache diff --git a/composer.json b/composer.json index 4f9bed6..786e3c7 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "require-dev": { "friendsofcake/cakephp-test-utilities": "dev-cake-5.x", "markstory/asset_compress": "5.x-dev", - "phpunit/phpunit": "^9.5.19" + "phpunit/phpunit": "^10.1" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 3b09bdc..ec34e63 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,5 +9,3 @@ parameters: - src universalObjectCratesClasses: - Crud\Event\Subject - bootstrapFiles: - - vendor/cakephp/cakephp/src/Database/Exception/DatabaseException.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 10712c9..f6a7ea0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,19 @@ - + ./tests/TestCase - - + - - - - src/ - - - + + + src/ + + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2e98c4d..53d6cf0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,10 +1,5 @@ - - - $event->getSubject()->element - - $input['type'] diff --git a/psalm.xml b/psalm.xml index c423ba4..e3b7c38 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,6 +6,9 @@ xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml" + usePhpDocMethodsWithoutMagicCall="true" + findUnusedBaselineEntry="true" + findUnusedCode="false" > diff --git a/src/Action/DashboardAction.php b/src/Action/DashboardAction.php index b8e89fd..9001fe8 100644 --- a/src/Action/DashboardAction.php +++ b/src/Action/DashboardAction.php @@ -6,6 +6,7 @@ use Crud\Action\BaseAction; use Crud\Traits\ViewTrait; use CrudView\Dashboard\Dashboard; +use function Cake\I18n\__d; class DashboardAction extends BaseAction { diff --git a/src/Dashboard/Dashboard.php b/src/Dashboard/Dashboard.php index 9afd487..68c10dc 100644 --- a/src/Dashboard/Dashboard.php +++ b/src/Dashboard/Dashboard.php @@ -6,6 +6,7 @@ use Cake\Datasource\EntityTrait; use Cake\View\Cell; use InvalidArgumentException; +use function Cake\I18n\__d; class Dashboard { diff --git a/src/Listener/Traits/FormTypeTrait.php b/src/Listener/Traits/FormTypeTrait.php index d2e84a7..e00d40a 100644 --- a/src/Listener/Traits/FormTypeTrait.php +++ b/src/Listener/Traits/FormTypeTrait.php @@ -6,6 +6,7 @@ use Cake\Controller\Controller; use Crud\Action\BaseAction; use Crud\Action\EditAction; +use function Cake\I18n\__d; trait FormTypeTrait { diff --git a/src/Listener/Traits/IndexTypeTrait.php b/src/Listener/Traits/IndexTypeTrait.php index d19dee7..d2d4f6f 100644 --- a/src/Listener/Traits/IndexTypeTrait.php +++ b/src/Listener/Traits/IndexTypeTrait.php @@ -84,7 +84,7 @@ protected function _getIndexTitleField(): string $field = $action->getConfig('scaffold.index_title_field'); if ($field === null) { - $field = $this->_table()->getDisplayField(); + $field = $this->_model()->getDisplayField(); } return $field; @@ -154,5 +154,5 @@ abstract protected function _action(?string $name = null): BaseAction; /** * @inheritDoc */ - abstract protected function _table(); + abstract protected function _model(); } diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index e2add62..33e4a20 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -15,7 +15,12 @@ use CrudView\Listener\Traits\SiteTitleTrait; use CrudView\Listener\Traits\UtilityNavigationTrait; use CrudView\Traits\CrudViewConfigTrait; +use function Cake\Core\pluginSplit; +use function Cake\I18n\__d; +/** + * @method \Cake\ORM\Table _model() + */ class ViewListener extends BaseListener { use CrudViewConfigTrait; @@ -133,6 +138,7 @@ public function beforeRender(EventInterface $event): void public function setFlash(EventInterface $event): void { unset($event->getSubject()->params['class']); + /** @psalm-suppress UndefinedPropertyAssignment */ $event->getSubject()->element = ltrim($event->getSubject()->type); } @@ -172,7 +178,7 @@ protected function _getPageTitle(): string $displayFieldValue = $this->_displayFieldValue(); if ( $displayFieldValue === null - || $this->_table()->getDisplayField() === $this->_table()->getPrimaryKey() + || $this->_model()->getDisplayField() === $this->_model()->getPrimaryKey() ) { /** @psalm-var string $primaryKeyValue */ return sprintf('%s %s #%s', $actionName, $controllerName, $primaryKeyValue); @@ -217,12 +223,12 @@ protected function _getRelatedModels(array $associationTypes = []): array if (empty($models)) { $associations = []; if (empty($associationTypes)) { - $associations = $this->_table()->associations(); + $associations = $this->_model()->associations(); } else { foreach ($associationTypes as $assocType) { $associations = array_merge( $associations, - $this->_table()->associations()->getByType($assocType) + $this->_model()->associations()->getByType($assocType) ); } } @@ -267,7 +273,7 @@ protected function _blacklist(): array */ protected function _getPageVariables(): array { - $table = $this->_table(); + $table = $this->_model(); $modelClass = $table->getAlias(); $controller = $this->_controller(); $scope = $this->_action()->getConfig('scope'); @@ -316,7 +322,7 @@ protected function _scaffoldFields(array $associations = []): array } if (empty($scaffoldFields) || $action->getConfig('scaffold.autoFields')) { - $cols = $this->_table()->getSchema()->columns(); + $cols = $this->_model()->getSchema()->columns(); $cols = Hash::normalize($cols); $scope = $action->getConfig('scope'); @@ -553,7 +559,7 @@ protected function _normalizeActions(array $actions): array */ protected function _associations(array $whitelist = []): array { - $table = $this->_table(); + $table = $this->_model(); $associationConfiguration = []; @@ -604,7 +610,7 @@ protected function _associations(array $whitelist = []): array */ protected function _primaryKeyValue(): array|string { - $fields = (array)$this->_table()->getPrimaryKey(); + $fields = (array)$this->_model()->getPrimaryKey(); $values = []; foreach ($fields as $field) { $values[] = $this->_deriveFieldFromContext($field); @@ -627,7 +633,7 @@ protected function _primaryKeyValue(): array|string protected function _displayFieldValue(): string|int|null { /** @psalm-suppress PossiblyInvalidArgument */ - return $this->_deriveFieldFromContext($this->_table()->getDisplayField()); + return $this->_deriveFieldFromContext($this->_model()->getDisplayField()); } /** @@ -640,7 +646,7 @@ protected function _displayFieldValue(): string|int|null protected function _deriveFieldFromContext(string $field): mixed { $controller = $this->_controller(); - $modelClass = $this->_table()->getAlias(); + $modelClass = $this->_model()->getAlias(); $entity = $this->_entity(); $request = $this->_request(); $value = $entity->get($field); diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index 13ce81a..c29b329 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -8,6 +8,9 @@ use Cake\Utility\Hash; use Crud\Listener\BaseListener; +/** + * @method \Cake\ORM\Table _model() + */ class ViewSearchListener extends BaseListener { /** @@ -56,7 +59,7 @@ public function implementedEvents(): array */ public function afterPaginate(EventInterface $event): void { - if (!$this->_table()->behaviors()->has('Search')) { + if (!$this->_model()->behaviors()->has('Search')) { return; } @@ -82,13 +85,13 @@ public function fields(): array $fields = $this->getConfig('fields') ?: []; $config = $this->getConfig(); - $schema = $this->_table()->getSchema(); + $schema = $this->_model()->getSchema(); $request = $this->_request(); if ($fields) { $fields = Hash::normalize($fields); } else { - $filters = $this->_table()->searchManager()->getFilters($config['collection']); + $filters = $this->_model()->searchManager()->getFilters($config['collection']); foreach ($filters as $filter) { $opts = $filter->getConfig('form'); diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index f6a9bd5..261302c 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -9,6 +9,8 @@ use Cake\Utility\Text; use Cake\View\Helper; use Cake\View\Helper\FormHelper; +use function Cake\Core\h; +use function Cake\I18n\__d; /** * @property \BootstrapUI\View\Helper\FormHelper $Form diff --git a/tests/TestCase/Dashboard/DashboardTest.php b/tests/TestCase/Dashboard/DashboardTest.php index b885b60..06dd42a 100644 --- a/tests/TestCase/Dashboard/DashboardTest.php +++ b/tests/TestCase/Dashboard/DashboardTest.php @@ -9,6 +9,7 @@ use CrudView\Dashboard\Dashboard; use CrudView\View\Cell\DashboardTableCell; use InvalidArgumentException; +use function Cake\I18n\__d; /** * DashboardTest class diff --git a/tests/TestCase/View/Widget/DateTimeWidgetTest.php b/tests/TestCase/View/Widget/DateTimeWidgetTest.php index 55c440c..8abd06d 100644 --- a/tests/TestCase/View/Widget/DateTimeWidgetTest.php +++ b/tests/TestCase/View/Widget/DateTimeWidgetTest.php @@ -55,7 +55,7 @@ public function testRenderSimple($compareFileName, $data) * * @return array */ - public function renderProvider() + public static function renderProvider() { return [ [