Skip to content

Commit

Permalink
Fix issues reported by PHPCS and PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaskill committed Jan 30, 2024
1 parent cab8138 commit 004aab9
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 36 deletions.
16 changes: 13 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<config name="show_progress" value="1" />
<config name="ignore_warnings_on_exit" value="1" />
<config name="php_version" value="50630" />
<config name="php_version" value="70300" />

<rule ref="PSR2" />

Expand Down Expand Up @@ -38,8 +38,6 @@

<!-- Code Analysis Sniffs -->

<!-- Do not allow empty if, else or case -->
<rule ref="Generic.CodeAnalysis.EmptyStatement" />
<!-- Simple for loops (for(;true;){}) should be while -->
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop" />
<!-- Do not allow function in for(...) loops. Use a temporary variable to store the result instead -->
Expand All @@ -56,6 +54,10 @@
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod" />
<!-- This sniff class detects empty statement. -->
<rule ref="Generic.CodeAnalysis.EmptyStatement" />
<!-- Ignore empty CATCH statement -->
<rule ref="Generic.CodeAnalysis.EmptyStatement.DetectedCatch">
<severity>0</severity>
</rule>

<!-- Commenting Sniffs -->

Expand All @@ -82,10 +84,18 @@
<!--<rule ref="Squiz.Commenting.FileComment" />-->
<!-- Function comment blocks -->
<rule ref="Squiz.Commenting.FunctionComment" />
<!-- Ignore missing parameter comment -->
<rule ref="Squiz.Commenting.FunctionComment.MissingParamComment">
<severity>0</severity>
</rule>
<!-- Do not test scalar typehint (php-7 only feature) -->
<rule ref="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing">
<severity>0</severity>
</rule>
<!-- Do not test PHP-7 typehint (php-7 only feature) -->
<rule ref="Squiz.Commenting.FunctionComment.TypeHintMissing">
<type>warning</type>
</rule>
<!-- Verifies that a @throws tag exists for a function that throws exceptions -->
<rule ref="Squiz.Commenting.FunctionCommentThrowTag" />
<!-- Checks that there is adequate spacing between comments -->
Expand Down
14 changes: 7 additions & 7 deletions src/Charcoal/Admin/Action/ElfinderConnectorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Charcoal/Admin/Property/AbstractProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
7 changes: 4 additions & 3 deletions src/Charcoal/Admin/Property/AbstractPropertyDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function setDisplayEscape($escape)
*/
public function getDisplayEscape()
{
return $this->getDisplayEscapeOptions()['function'] ?? null;
return ($this->getDisplayEscapeOptions()['function'] ?? null);
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -328,6 +328,7 @@ public function escapeVal($val, array $options = [])
}

/**
* @throws UnexpectedValueException If the value is not a scalar.
* @return string
*/
public function displayVal()
Expand Down
14 changes: 7 additions & 7 deletions src/Charcoal/Admin/Property/AbstractPropertyInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function setInputEscape($escape)
*/
public function getInputEscape()
{
return $this->getInputEscapeOptions()['function'] ?? null;
return ($this->getInputEscapeOptions()['function'] ?? null);
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -508,7 +508,7 @@ public function inputPrefix()
}
}

return $this->inputPrefix ?? null;
return ($this->inputPrefix ?? null);
}

/**
Expand Down Expand Up @@ -559,7 +559,7 @@ public function inputSuffix()
}
}

return $this->inputSuffix ?? null;
return ($this->inputSuffix ?? null);
}

/**
Expand Down Expand Up @@ -655,7 +655,7 @@ public function setPlaceholder($placeholder)
}

/**
* @return bool
* @return boolean
*/
public function hasPlaceholder()
{
Expand Down Expand Up @@ -687,7 +687,7 @@ public function placeholder()
}
}

return $this->placeholder ?? null;
return ($this->placeholder ?? null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Charcoal/Admin/Property/Display/MessageDisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function setMessage($message)
}

/**
* @return bool
* @return boolean
*/
public function hasMessage()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Charcoal/Admin/Property/Input/ReadonlyInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Charcoal/Admin/Support/Sorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Charcoal/Admin/Ui/HasLanguageSwitcherTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function languages()
/**
* Resolves whether to display the language switcher or not.
*
* @var boolean
* @return boolean
*/
abstract protected function resolveShowLanguageSwitch();
}
2 changes: 1 addition & 1 deletion src/Charcoal/Admin/Ui/LanguageSwitcherAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface LanguageSwitcherAwareInterface
/**
* Whether a language switcher could be displayed.
*
* @return bool
* @return boolean
*/
public function supportsLanguageSwitch(): bool;
}
4 changes: 2 additions & 2 deletions src/Charcoal/Admin/Widget/FormWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public function addSidebar($sidebarIdent, $sidebar)
*/
public function hasSidebars()
{
return (bool) $this->sidebars;
return (bool)$this->sidebars;
}

/**
Expand Down Expand Up @@ -617,7 +617,7 @@ public function hiddenProperties()
/**
* Whether a language switcher could be displayed.
*
* @return bool
* @return boolean
*/
public function supportsLanguageSwitch(): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/Charcoal/Admin/Widget/ObjectFormWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ protected function dataFromObject()
/**
* Whether a language switcher could be displayed.
*
* @return bool
* @return boolean
*/
public function supportsLanguageSwitch(): bool
{
Expand Down Expand Up @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Charcoal/Admin/Widget/GraphWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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);
Expand Down

0 comments on commit 004aab9

Please sign in to comment.