From 626927888dc6f571dd106903924587f8c59f98e7 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 8 Sep 2024 12:24:52 +0530 Subject: [PATCH] Fix stan errors --- .github/workflows/ci.yml | 2 +- src/View/Helper/CrudViewHelper.php | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ea14560..2037af0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: php-version: '8.3' extensions: mbstring, intl coverage: none - tools: vimeo/psalm:5, phpstan:1.11, cs2pr + tools: vimeo/psalm:5, phpstan:1.12, cs2pr - name: Composer Install run: composer require --dev cakephp/cakephp-codesniffer:^5.0 diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index b455940..901775b 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -217,18 +217,18 @@ public function formatDateTime(string $field, mixed $value, array $options): str } if ($value instanceof Date) { - return $value->i18nFormat($options['format'] ?? $this->getConfig('dateFormat')); + return (string)$value->i18nFormat($options['format'] ?? $this->getConfig('dateFormat')); } if ($value instanceof Time) { - return $value->i18nFormat($options['format'] ?? $this->getConfig('timeFormat')); + return (string)$value->i18nFormat($options['format'] ?? $this->getConfig('timeFormat')); } if ($value instanceof ChronosDate || $value instanceof ChronosTime) { return (string)$value; } - return $this->Time->i18nFormat($value, $options['format'] ?? $this->getConfig('dateTimeFormat'), '') + return (string)$this->Time->i18nFormat($value, $options['format'] ?? $this->getConfig('dateTimeFormat'), '') ?: $this->Html->badge(__d('crud', 'N/A'), ['class' => 'info']); } @@ -389,9 +389,12 @@ public function createRelationLink(string $alias, array $relation, array $option */ public function createViewLink(string $title, array $options = []): string { + $entity = $this->getContext()->entity(); + assert($entity instanceof EntityInterface); + return $this->Html->link( $title, - ['action' => 'view', $this->getContext()->entity()->get($this->getViewVar('primaryKey'))], + ['action' => 'view', $entity->get($this->getViewVar('primaryKey'))], $options ); }