From 004aab95acd52951b81ba6325bfa00f6da6b7acd Mon Sep 17 00:00:00 2001 From: Chauncey McAskill Date: Mon, 29 Jan 2024 19:26:58 -0500 Subject: [PATCH] Fix issues reported by PHPCS and PHPUnit --- phpcs.xml.dist | 16 +++++++++++++--- .../Admin/Action/ElfinderConnectorAction.php | 14 +++++++------- src/Charcoal/Admin/Property/AbstractProperty.php | 4 ++-- .../Admin/Property/AbstractPropertyDisplay.php | 7 ++++--- .../Admin/Property/AbstractPropertyInput.php | 14 +++++++------- .../Admin/Property/Display/MessageDisplay.php | 2 +- .../Admin/Property/Input/ReadonlyInput.php | 2 +- src/Charcoal/Admin/Support/Sorter.php | 2 +- .../Admin/Ui/HasLanguageSwitcherTrait.php | 2 +- .../Admin/Ui/LanguageSwitcherAwareInterface.php | 2 +- src/Charcoal/Admin/Widget/FormWidget.php | 4 ++-- src/Charcoal/Admin/Widget/ObjectFormWidget.php | 4 ++-- tests/Charcoal/Admin/Widget/GraphWidgetTest.php | 10 +++++----- 13 files changed, 47 insertions(+), 36 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 327f3da4f5..71adc15889 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -6,7 +6,7 @@ - + @@ -38,8 +38,6 @@ - - @@ -56,6 +54,10 @@ + + + 0 + @@ -82,10 +84,18 @@ + + + 0 + 0 + + + warning + diff --git a/src/Charcoal/Admin/Action/ElfinderConnectorAction.php b/src/Charcoal/Admin/Action/ElfinderConnectorAction.php index 0984f70df2..c3a1d8fb5f 100644 --- a/src/Charcoal/Admin/Action/ElfinderConnectorAction.php +++ b/src/Charcoal/Admin/Action/ElfinderConnectorAction.php @@ -560,12 +560,12 @@ protected function resolveCallbacksForBindOption(array $toResolve) * * @todo Move this method to a dedicated plugin class. * - * @param string $cmd The command name. - * @param array $result The command result. - * @param array $args The command arguments from the client. - * @param object $elfinder The elFinder instance. - * @param object $volume The current volume instance. - * @return void|bool|array + * @param string $cmd The command name. + * @param mixed $result The command result. + * @param mixed $args The command arguments from the client. + * @param object $elfinder The elFinder instance. + * @param object $volume The current volume instance. + * @return void|boolean|array */ public function translateDirectoriesOnAnyCommand($cmd, &$result, $args, $elfinder, $volume) { @@ -690,7 +690,7 @@ protected function translateFilesystemName(string $ident): ?string * @param string $src The temporary file name. * @param object $elfinder The elFinder instance. * @param object $volume The current volume instance. - * @return void|bool|array + * @return void|boolean|array */ public function sanitizeOnUploadPreSave(&$path, &$name, $src, $elfinder, $volume) { diff --git a/src/Charcoal/Admin/Property/AbstractProperty.php b/src/Charcoal/Admin/Property/AbstractProperty.php index 5530888a21..dc4e7c2d0e 100644 --- a/src/Charcoal/Admin/Property/AbstractProperty.php +++ b/src/Charcoal/Admin/Property/AbstractProperty.php @@ -294,8 +294,8 @@ public function ident() * If a valid "function" option is not passed, * this method does nothing. * - * @param string $val The value to escape. - * @param array $options Optional escape options. + * @param string $val The value to escape. + * @param array $options Optional escape options. * @throws InvalidArgumentException If the value to escape is not a string. * @return string */ diff --git a/src/Charcoal/Admin/Property/AbstractPropertyDisplay.php b/src/Charcoal/Admin/Property/AbstractPropertyDisplay.php index 290877598b..a74c1c3ca0 100644 --- a/src/Charcoal/Admin/Property/AbstractPropertyDisplay.php +++ b/src/Charcoal/Admin/Property/AbstractPropertyDisplay.php @@ -258,7 +258,7 @@ public function setDisplayEscape($escape) */ public function getDisplayEscape() { - return $this->getDisplayEscapeOptions()['function'] ?? null; + return ($this->getDisplayEscapeOptions()['function'] ?? null); } /** @@ -288,8 +288,8 @@ public function getDisplayEscapeOptions() /** * Escapes the given value according to display escape options. * - * @param string $val The value to escape. - * @param array $options Optional escape options. + * @param string $val The value to escape. + * @param array $options Optional escape options. * @throws InvalidArgumentException If the value to escape is not a string. * @return string */ @@ -328,6 +328,7 @@ public function escapeVal($val, array $options = []) } /** + * @throws UnexpectedValueException If the value is not a scalar. * @return string */ public function displayVal() diff --git a/src/Charcoal/Admin/Property/AbstractPropertyInput.php b/src/Charcoal/Admin/Property/AbstractPropertyInput.php index 0e013fb24d..6185497dfd 100644 --- a/src/Charcoal/Admin/Property/AbstractPropertyInput.php +++ b/src/Charcoal/Admin/Property/AbstractPropertyInput.php @@ -310,7 +310,7 @@ public function setInputEscape($escape) */ public function getInputEscape() { - return $this->getInputEscapeOptions()['function'] ?? null; + return ($this->getInputEscapeOptions()['function'] ?? null); } /** @@ -340,8 +340,8 @@ public function getInputEscapeOptions() /** * Escapes the given value according to input escape options. * - * @param string $val The value to escape. - * @param array $options Optional escape options. + * @param string $val The value to escape. + * @param array $options Optional escape options. * @throws InvalidArgumentException If the value to escape is not a string. * @return string */ @@ -508,7 +508,7 @@ public function inputPrefix() } } - return $this->inputPrefix ?? null; + return ($this->inputPrefix ?? null); } /** @@ -559,7 +559,7 @@ public function inputSuffix() } } - return $this->inputSuffix ?? null; + return ($this->inputSuffix ?? null); } /** @@ -655,7 +655,7 @@ public function setPlaceholder($placeholder) } /** - * @return bool + * @return boolean */ public function hasPlaceholder() { @@ -687,7 +687,7 @@ public function placeholder() } } - return $this->placeholder ?? null; + return ($this->placeholder ?? null); } /** diff --git a/src/Charcoal/Admin/Property/Display/MessageDisplay.php b/src/Charcoal/Admin/Property/Display/MessageDisplay.php index 64f0c94891..a0b827eb75 100644 --- a/src/Charcoal/Admin/Property/Display/MessageDisplay.php +++ b/src/Charcoal/Admin/Property/Display/MessageDisplay.php @@ -60,7 +60,7 @@ public function setMessage($message) } /** - * @return bool + * @return boolean */ public function hasMessage() { diff --git a/src/Charcoal/Admin/Property/Input/ReadonlyInput.php b/src/Charcoal/Admin/Property/Input/ReadonlyInput.php index c8df381a03..9e9d62403f 100644 --- a/src/Charcoal/Admin/Property/Input/ReadonlyInput.php +++ b/src/Charcoal/Admin/Property/Input/ReadonlyInput.php @@ -224,7 +224,7 @@ public function maybeUnserializeValue($input) { if (!is_null($input) && $this->maybeInputIsSerialized()) { try { - $output = json_decode($input, false, 512, JSON_THROW_ON_ERROR); + $output = json_decode($input, false, 512, JSON_THROW_ON_ERROR); if (!is_scalar($output) && !is_null($output)) { return $output; } diff --git a/src/Charcoal/Admin/Support/Sorter.php b/src/Charcoal/Admin/Support/Sorter.php index abd8e558a6..c8c172b0d3 100644 --- a/src/Charcoal/Admin/Support/Sorter.php +++ b/src/Charcoal/Admin/Support/Sorter.php @@ -10,7 +10,7 @@ class Sorter /** * Compares the priority attribute of two array-accessible variables * to determine if the first variable is considered to be respectively - * less than, equal to, or greater than the second. + * less than, equal to, or greater than the second. * * To be called with {@see uasort()}. * diff --git a/src/Charcoal/Admin/Ui/HasLanguageSwitcherTrait.php b/src/Charcoal/Admin/Ui/HasLanguageSwitcherTrait.php index 7a2f86b0a3..3064868940 100644 --- a/src/Charcoal/Admin/Ui/HasLanguageSwitcherTrait.php +++ b/src/Charcoal/Admin/Ui/HasLanguageSwitcherTrait.php @@ -70,7 +70,7 @@ public function languages() /** * Resolves whether to display the language switcher or not. * - * @var boolean + * @return boolean */ abstract protected function resolveShowLanguageSwitch(); } diff --git a/src/Charcoal/Admin/Ui/LanguageSwitcherAwareInterface.php b/src/Charcoal/Admin/Ui/LanguageSwitcherAwareInterface.php index 17878deb2d..88a9d3c1d3 100644 --- a/src/Charcoal/Admin/Ui/LanguageSwitcherAwareInterface.php +++ b/src/Charcoal/Admin/Ui/LanguageSwitcherAwareInterface.php @@ -13,7 +13,7 @@ interface LanguageSwitcherAwareInterface /** * Whether a language switcher could be displayed. * - * @return bool + * @return boolean */ public function supportsLanguageSwitch(): bool; } diff --git a/src/Charcoal/Admin/Widget/FormWidget.php b/src/Charcoal/Admin/Widget/FormWidget.php index fbdc185664..8b26270a1c 100644 --- a/src/Charcoal/Admin/Widget/FormWidget.php +++ b/src/Charcoal/Admin/Widget/FormWidget.php @@ -392,7 +392,7 @@ public function addSidebar($sidebarIdent, $sidebar) */ public function hasSidebars() { - return (bool) $this->sidebars; + return (bool)$this->sidebars; } /** @@ -617,7 +617,7 @@ public function hiddenProperties() /** * Whether a language switcher could be displayed. * - * @return bool + * @return boolean */ public function supportsLanguageSwitch(): bool { diff --git a/src/Charcoal/Admin/Widget/ObjectFormWidget.php b/src/Charcoal/Admin/Widget/ObjectFormWidget.php index 1564212aee..a0d84fe96a 100644 --- a/src/Charcoal/Admin/Widget/ObjectFormWidget.php +++ b/src/Charcoal/Admin/Widget/ObjectFormWidget.php @@ -573,7 +573,7 @@ protected function dataFromObject() /** * Whether a language switcher could be displayed. * - * @return bool + * @return boolean */ public function supportsLanguageSwitch(): bool { @@ -624,7 +624,7 @@ public function hasL10nFormProperties() * Determine if the group has any multilingual properties. * * @param FormGroupInterface $group - * @return bool + * @return boolean */ protected function hasL10nGroupProperties(FormGroupInterface $group) { diff --git a/tests/Charcoal/Admin/Widget/GraphWidgetTest.php b/tests/Charcoal/Admin/Widget/GraphWidgetTest.php index 1df71f479e..0e6eaf9cbc 100644 --- a/tests/Charcoal/Admin/Widget/GraphWidgetTest.php +++ b/tests/Charcoal/Admin/Widget/GraphWidgetTest.php @@ -32,11 +32,11 @@ public function testSetData() { $obj = $this->obj; $ret = $obj->setData([ - 'height'=>222, - 'colors'=>['#ff0000', '#0000ff'] + 'height' => 222, + 'colors' => ['#ff0000', '#0000ff'] ]); $this->assertSame($obj, $ret); - $this->assertEquals(222, $obj->height()); + $this->assertEquals('222px', $obj->height()); $this->assertEquals(['#ff0000', '#0000ff'], $obj->colors()); } @@ -46,11 +46,11 @@ public function testSetData() public function testSetHeight() { $obj = $this->obj; - $this->assertEquals(400, $obj->height()); + $this->assertEquals('400px', $obj->height()); $ret = $obj->setHeight(333); $this->assertSame($obj, $ret); - $this->assertEquals(333, $obj->height()); + $this->assertEquals('333px', $obj->height()); //$this->expectException('\InvalidArgumentException'); //$obj->setHeight(false);