Skip to content

Commit

Permalink
Fix CS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Mar 28, 2024
1 parent 1d7a708 commit 8b2afe0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
19 changes: 8 additions & 11 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@">
<file src="src/Listener/ViewSearchListener.php">
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$input['type']</code>
</PossiblyUndefinedArrayOffset>
<files psalm-version="5.23.1@8471a896ccea3526b26d082f4461eeea467f10a4">
<file src="src/Dashboard/Module/LinkItem.php">
<TypeDoesNotContainType>
<code><![CDATA[$url === '']]></code>
</TypeDoesNotContainType>
</file>
<file src="src/View/Widget/DateTimeWidget.php">
<PossiblyNullArrayAccess occurrences="2">
<code>$data['name']</code>
<code>$data['templateVars']</code>
<PossiblyNullArrayAccess>
<code><![CDATA[$data['name']]]></code>
<code><![CDATA[$data['templateVars']]]></code>
</PossiblyNullArrayAccess>
<PossiblyUndefinedArrayOffset occurrences="1">
<code>$data['type']</code>
</PossiblyUndefinedArrayOffset>
</file>
</files>
8 changes: 2 additions & 6 deletions src/Dashboard/Module/LinkItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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 === '') {

Check failure on line 75 in src/Dashboard/Module/LinkItem.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Strict comparison using === between non-empty-array|non-falsy-string and '' will always evaluate to false.

Check failure on line 75 in src/Dashboard/Module/LinkItem.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Strict comparison using === between non-empty-array|non-falsy-string and '' will always evaluate to false.
throw new InvalidArgumentException('Invalid url specified for LinkItem');
}

Expand All @@ -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://';
Expand Down
4 changes: 2 additions & 2 deletions src/Listener/ViewListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function _getPageTitle(): string
}

$primaryKeyValue = $this->_primaryKeyValue();
if (empty($primaryKeyValue)) {
if ($primaryKeyValue === null) {

Check warning on line 174 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L174

Added line #L174 was not covered by tests
return sprintf('%s %s', $actionName, $controllerName);
}

Expand Down Expand Up @@ -612,7 +612,7 @@ protected function _deriveFieldFromContext(string $field): mixed
$request = $this->_request();
$value = $entity->get($field);

if ($value) {
if ($value !== null) {

Check warning on line 615 in src/Listener/ViewListener.php

View check run for this annotation

Codecov / codecov/patch

src/Listener/ViewListener.php#L615

Added line #L615 was not covered by tests
return $value;
}

Expand Down
7 changes: 7 additions & 0 deletions src/Listener/ViewSearchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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, '.')) {
Expand Down
3 changes: 2 additions & 1 deletion src/View/Cell/TablesListCell.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ class TablesListCell extends Cell
*/
public function display(?array $tables = null, ?array $blacklist = null): void
{
if (empty($tables)) {
if ($tables === null) {

Check warning on line 21 in src/View/Cell/TablesListCell.php

View check run for this annotation

Codecov / codecov/patch

src/View/Cell/TablesListCell.php#L21

Added line #L21 was not covered by tests
/** @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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/View/Helper/CrudViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 163 in src/View/Helper/CrudViewHelper.php

View check run for this annotation

Codecov / codecov/patch

src/View/Helper/CrudViewHelper.php#L162-L163

Added lines #L162 - L163 were not covered by tests
}

Expand Down Expand Up @@ -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

Check warning on line 247 in src/View/Helper/CrudViewHelper.php

View check run for this annotation

Codecov / codecov/patch

src/View/Helper/CrudViewHelper.php#L247

Added line #L247 was not covered by tests
{
if (is_scalar($value)) {
return $value;
return (string)$value;

Check warning on line 250 in src/View/Helper/CrudViewHelper.php

View check run for this annotation

Codecov / codecov/patch

src/View/Helper/CrudViewHelper.php#L249-L250

Added lines #L249 - L250 were not covered by tests
}

return $value instanceof EnumLabelInterface ?
Expand Down

0 comments on commit 8b2afe0

Please sign in to comment.