From 8b2afe03e80c567f7801ed9c0fbccae1df3da06f Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 28 Mar 2024 19:09:18 +0530 Subject: [PATCH] Fix CS errors --- psalm-baseline.xml | 19 ++++++++----------- src/Dashboard/Module/LinkItem.php | 8 ++------ src/Listener/ViewListener.php | 4 ++-- src/Listener/ViewSearchListener.php | 7 +++++++ src/View/Cell/TablesListCell.php | 3 ++- src/View/Helper/CrudViewHelper.php | 8 ++++---- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 53d6cf0..cf4de7d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,17 +1,14 @@ - - - - $input['type'] - + + + + + - - $data['name'] - $data['templateVars'] + + + - - $data['type'] - diff --git a/src/Dashboard/Module/LinkItem.php b/src/Dashboard/Module/LinkItem.php index 767846a..6290fd3 100644 --- a/src/Dashboard/Module/LinkItem.php +++ b/src/Dashboard/Module/LinkItem.php @@ -56,7 +56,7 @@ public function __construct(string|array $title, string|array|null $url, array $ */ protected function _setTitle(string|array|null $title): string|array { - if (empty($title)) { + if ($title === null || $title === '') { throw new InvalidArgumentException('Missing title for LinkItem action'); } @@ -72,7 +72,7 @@ protected function _setTitle(string|array|null $title): string|array */ protected function _setUrl(string|array|null $url): string|array { - if ($url === null || empty($url)) { + if ($url == null || $url === '') { throw new InvalidArgumentException('Invalid url specified for LinkItem'); } @@ -87,10 +87,6 @@ protected function _setUrl(string|array|null $url): string|array */ protected function _setOptions(array $options): string|array { - if (empty($options)) { - $options = []; - } - $url = $this->get('url'); if (!is_array($url)) { $isHttp = substr($url, 0, 7) === 'http://'; diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index 46c4881..4a8731b 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -171,7 +171,7 @@ protected function _getPageTitle(): string } $primaryKeyValue = $this->_primaryKeyValue(); - if (empty($primaryKeyValue)) { + if ($primaryKeyValue === null) { return sprintf('%s %s', $actionName, $controllerName); } @@ -612,7 +612,7 @@ protected function _deriveFieldFromContext(string $field): mixed $request = $this->_request(); $value = $entity->get($field); - if ($value) { + if ($value !== null) { return $value; } diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index e82d82e..5f53be8 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -151,6 +151,7 @@ public function fields(): array $input['options'][$input['value']] = $input['value']; } + /** @psalm-suppress PossiblyInvalidOperand */ $input += [ 'data-input-type' => 'text', 'data-tags' => 'true', @@ -188,6 +189,12 @@ public function fields(): array return $fields; } + /** + * Get placeholder text for a field. + * + * @param string $field Field name. + * @return string + */ protected function getPlaceholder(string $field): string { if (str_contains($field, '.')) { diff --git a/src/View/Cell/TablesListCell.php b/src/View/Cell/TablesListCell.php index 3bd1d6d..9f5b82a 100644 --- a/src/View/Cell/TablesListCell.php +++ b/src/View/Cell/TablesListCell.php @@ -18,13 +18,14 @@ class TablesListCell extends Cell */ public function display(?array $tables = null, ?array $blacklist = null): void { - if (empty($tables)) { + if ($tables === null) { /** @var \Cake\Database\Connection $connection */ $connection = ConnectionManager::get('default'); $schema = $connection->getSchemaCollection(); $tables = $schema->listTables(); ksort($tables); + /** @psalm-suppress RiskyTruthyFalsyComparison */ if (!empty($blacklist)) { $tables = array_diff($tables, $blacklist); } diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index b0e2abb..0dbcbd0 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -159,7 +159,7 @@ public function introspect(string $field, mixed $value, array $options = []): ar return $this->formatTime($field, $value, $options); } - if (str_starts_with($type, 'enum-')) { + if ($type !== null && str_starts_with($type, 'enum-')) { return $this->formatEnum($field, $value, $options); } @@ -241,13 +241,13 @@ public function formatTime(string $field, mixed $value, array $options): string * Format an enum for display * * @param string $field Name of field. - * @param int|string|\UnitEnum|\BackedEnum $value Value of field. + * @param \UnitEnum|\BackedEnum|string|int $value Value of field. * @return string */ - public function formatEnum(string $field, int|string|UnitEnum|BackedEnum $value, array $options): string + public function formatEnum(string $field, UnitEnum|BackedEnum|string|int $value, array $options): string { if (is_scalar($value)) { - return $value; + return (string)$value; } return $value instanceof EnumLabelInterface ?