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/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/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 60de271..33e4a20 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -15,8 +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; @@ -134,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); } @@ -173,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); @@ -218,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) ); } } @@ -268,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'); @@ -317,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'); @@ -554,7 +559,7 @@ protected function _normalizeActions(array $actions): array */ protected function _associations(array $whitelist = []): array { - $table = $this->_table(); + $table = $this->_model(); $associationConfiguration = []; @@ -605,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); @@ -628,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()); } /** @@ -641,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 6595e1d..261302c 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -9,6 +9,7 @@ use Cake\Utility\Text; use Cake\View\Helper; use Cake\View\Helper\FormHelper; +use function Cake\Core\h; use function Cake\I18n\__d; /**