From af387549157b553fb24faf9b424d4b9876f93603 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 21 Sep 2023 02:02:27 +0000 Subject: [PATCH] automated rector fixes --- Algorithm/JobScheduling/Weighted.php | 4 +- Algorithm/Rating/Glicko2.php | 2 +- Business/Recommendation/MemoryCF.php | 3 +- .../Connection/ConnectionAbstract.php | 4 +- DataStorage/Database/Mapper/DeleteMapper.php | 6 +- DataStorage/Database/Mapper/ReadMapper.php | 8 +- DataStorage/Database/Mapper/UpdateMapper.php | 16 +-- DataStorage/Database/Mapper/WriteMapper.php | 25 ++--- .../Database/Query/Grammar/Grammar.php | 8 +- DataStorage/Session/JWT.php | 5 +- Math/Matrix/Matrix.php | 6 +- Message/Cli/CliHeader.php | 5 +- Message/Http/HttpHeader.php | 2 +- Model/Html/FormElementGenerator.php | 23 +++-- Socket/SocketAbstract.php | 2 +- Stdlib/Base/SmartDateTime.php | 6 +- Stdlib/Graph/Graph.php | 6 +- System/File/FileUtils.php | 3 +- System/File/Ftp/File.php | 2 +- Uri/HttpUri.php | 2 +- Utils/Barcode/Datamatrix.php | 3 +- Utils/Converter/Currency.php | 2 +- Utils/Parser/Markdown/Markdown.php | 97 ++++++------------- tests/Application/ApplicationManagerTest.php | 4 +- tests/Bootstrap.php | 8 +- tests/Dispatcher/DispatcherTest.php | 6 +- tests/Dispatcher/TestController.php | 6 +- tests/Event/EventManagerTest.php | 20 ++-- tests/Localization/MoneyTest.php | 2 +- tests/Math/Functions/GammaTest.php | 8 +- tests/Security/Sample/hasUnicode.php | 2 +- tests/Security/Sample/noDeprecated.php | 2 +- tests/Security/Sample/noUnicode.php | 2 +- tests/Stdlib/Graph/GraphTest.php | 6 +- 34 files changed, 114 insertions(+), 192 deletions(-) diff --git a/Algorithm/JobScheduling/Weighted.php b/Algorithm/JobScheduling/Weighted.php index f3750ad90..f348f6346 100755 --- a/Algorithm/JobScheduling/Weighted.php +++ b/Algorithm/JobScheduling/Weighted.php @@ -114,7 +114,9 @@ final class Weighted return $jobs; } - \usort($jobs, [self::class, 'sortByEnd']); + \usort($jobs, function (\phpOMS\Algorithm\JobScheduling\JobInterface $j1, \phpOMS\Algorithm\JobScheduling\JobInterface $j2) : int { + return self::sortByEnd($j1, $j2); + }); $valueTable = [$jobs[0]->getValue()]; diff --git a/Algorithm/Rating/Glicko2.php b/Algorithm/Rating/Glicko2.php index 089164925..173f255c5 100644 --- a/Algorithm/Rating/Glicko2.php +++ b/Algorithm/Rating/Glicko2.php @@ -120,7 +120,7 @@ final class Glicko2 $tau = $this->tau; // Step 0: - $rdOld = $rdOld / self::Q; + $rdOld /= self::Q; $elo = ($elo - $this->DEFAULT_ELO) / self::Q; foreach ($oElo as $idx => $value) { diff --git a/Business/Recommendation/MemoryCF.php b/Business/Recommendation/MemoryCF.php index d34f22a27..d66be710e 100644 --- a/Business/Recommendation/MemoryCF.php +++ b/Business/Recommendation/MemoryCF.php @@ -207,8 +207,7 @@ final class MemoryCF } \asort($matches); - $matches = \array_reverse($matches, true); - return $matches; + return \array_reverse($matches, true); } } diff --git a/DataStorage/Database/Connection/ConnectionAbstract.php b/DataStorage/Database/Connection/ConnectionAbstract.php index 3aa1833a6..f911c4188 100755 --- a/DataStorage/Database/Connection/ConnectionAbstract.php +++ b/DataStorage/Database/Connection/ConnectionAbstract.php @@ -193,7 +193,7 @@ abstract class ConnectionAbstract implements ConnectionInterface */ public function isInitialized() : bool { - return isset($this->con) && !($this->con instanceof NullPDO); + return $this->con !== null && !($this->con instanceof NullPDO); } /** @@ -207,7 +207,7 @@ abstract class ConnectionAbstract implements ConnectionInterface */ public function __get(string $name) : mixed { - if ($name === 'con' && !isset($this->con)) { + if ($name === 'con' && $this->con === null) { $this->connect($this->dbdata); } diff --git a/DataStorage/Database/Mapper/DeleteMapper.php b/DataStorage/Database/Mapper/DeleteMapper.php index cf5f1802e..b3112cb0e 100755 --- a/DataStorage/Database/Mapper/DeleteMapper.php +++ b/DataStorage/Database/Mapper/DeleteMapper.php @@ -171,11 +171,7 @@ final class DeleteMapper extends DataMapperAbstract $objIds = []; $refProp = $refClass->getProperty($member); - if (!$refProp->isPublic()) { - $values = $refProp->getValue($obj); - } else { - $values = $obj->{$member}; - } + $values = $refProp->isPublic() ? $obj->{$member} : $refProp->getValue($obj); if (!\is_array($values)) { // conditionals diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index 9dc020ad0..cbf5a4f0c 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -263,7 +263,7 @@ final class ReadMapper extends DataMapperAbstract return []; } - return !\is_array($result) ? [$result] : $result; + return \is_array($result) ? $result : [$result]; } /** @@ -315,10 +315,8 @@ final class ReadMapper extends DataMapperAbstract foreach ($columns as $key => $values) { if (\is_string($values)) { $query->selectAs($key, $values); - } else { - if (($values['writeonly'] ?? false) === false || isset($this->with[$values['internal']])) { - $query->selectAs($this->mapper::TABLE . '_d' . $this->depth . '.' . $key, $key . '_d' . $this->depth); - } + } elseif (($values['writeonly'] ?? false) === false || isset($this->with[$values['internal']])) { + $query->selectAs($this->mapper::TABLE . '_d' . $this->depth . '.' . $key, $key . '_d' . $this->depth); } } diff --git a/DataStorage/Database/Mapper/UpdateMapper.php b/DataStorage/Database/Mapper/UpdateMapper.php index 8afd35e68..47f87896b 100755 --- a/DataStorage/Database/Mapper/UpdateMapper.php +++ b/DataStorage/Database/Mapper/UpdateMapper.php @@ -118,8 +118,8 @@ final class UpdateMapper extends DataMapperAbstract $propertyName = \stripos($column['internal'], '/') !== false ? \explode('/', $column['internal'])[0] : $column['internal']; if (isset($this->mapper::HAS_MANY[$propertyName]) || $column['internal'] === $this->mapper::PRIMARYFIELD - || (($column['readonly'] ?? false) === true && !isset($this->with[$propertyName])) - || (($column['writeonly'] ?? false) === true && !isset($this->with[$propertyName])) + || (($column['readonly'] ?? false) && !isset($this->with[$propertyName])) + || (($column['writeonly'] ?? false) && !isset($this->with[$propertyName])) ) { continue; } @@ -127,11 +127,7 @@ final class UpdateMapper extends DataMapperAbstract $refClass = $refClass ?? new \ReflectionClass($obj); $property = $refClass->getProperty($propertyName); - if (!($property->isPublic())) { - $tValue = $property->getValue($obj); - } else { - $tValue = $obj->{$propertyName}; - } + $tValue = $property->isPublic() ? $obj->{$propertyName} : $property->getValue($obj); if (isset($this->mapper::OWNS_ONE[$propertyName])) { $id = \is_object($tValue) ? $this->updateOwnsOne($propertyName, $tValue) : $tValue; @@ -246,11 +242,7 @@ final class UpdateMapper extends DataMapperAbstract $property = $refClass->getProperty($propertyName); - if (!($isPublic = $property->isPublic())) { - $values = $property->getValue($obj); - } else { - $values = $obj->{$propertyName}; - } + $values = ($isPublic = $property->isPublic()) ? $obj->{$propertyName} : $property->getValue($obj); if (!\is_array($values) || empty($values)) { continue; diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 984df82a4..9d10f2ef3 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -230,11 +230,7 @@ final class WriteMapper extends DataMapperAbstract $refClass = new \ReflectionClass($obj); $refProp = $refClass->getProperty($this->mapper::BELONGS_TO[$propertyName]['by']); - if (!$refProp->isPublic()) { - $obj = $refProp->getValue($obj); - } else { - $obj = $obj->{$this->mapper::BELONGS_TO[$propertyName]['by']}; - } + $obj = $refProp->isPublic() ? $obj->{$this->mapper::BELONGS_TO[$propertyName]['by']} : $refProp->getValue($obj); } /** @var class-string $mapper */ @@ -266,11 +262,7 @@ final class WriteMapper extends DataMapperAbstract } $property = $refClass->getProperty($propertyName); - if (!$property->isPublic()) { - $values = $property->getValue($obj); - } else { - $values = $obj->{$propertyName}; - } + $values = $property->isPublic() ? $obj->{$propertyName} : $property->getValue($obj); /** @var class-string $mapper */ $mapper = $this->mapper::HAS_MANY[$propertyName]['mapper']; @@ -301,7 +293,7 @@ final class WriteMapper extends DataMapperAbstract } $objsIds = []; - $relReflectionClass = !empty($values) ? new \ReflectionClass(\reset($values)) : null; + $relReflectionClass = empty($values) ? null : new \ReflectionClass(\reset($values)); foreach ($values as $key => $value) { if (!\is_object($value)) { @@ -328,19 +320,16 @@ final class WriteMapper extends DataMapperAbstract // todo maybe consider to just set the column type to object, and then check for that (might be faster) if (isset($mapper::BELONGS_TO[$internalName]) - || isset($mapper::OWNS_ONE[$internalName]) - ) { + || isset($mapper::OWNS_ONE[$internalName])) { if (!$isRelPublic) { $relProperty->setValue($value, $this->mapper::createNullModel($objId)); } else { $value->{$internalName} = $this->mapper::createNullModel($objId); } + } elseif (!$isRelPublic) { + $relProperty->setValue($value, $objId); } else { - if (!$isRelPublic) { - $relProperty->setValue($value, $objId); - } else { - $value->{$internalName} = $objId; - } + $value->{$internalName} = $objId; } if (!$isRelPublic) { diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index ccf5d93a9..2fe855b25 100755 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -83,11 +83,11 @@ class Grammar extends GrammarAbstract } if (!empty($query->unions)) { - $sql[] = $this->compileUnions($query, $query->unions); + $sql[] = $this->compileUnions(); } if (!empty($query->lock)) { - $sql[] = $this->compileLock($query, $query->lock); + $sql[] = $this->compileLock(); } break; @@ -399,9 +399,7 @@ class Grammar extends GrammarAbstract $expression .= $this->compileOn($query, $query->ons[$join['alias'] ?? $table]) . ' '; } - $expression = \rtrim($expression, ', '); - - return $expression; + return \rtrim($expression, ', '); } /** diff --git a/DataStorage/Session/JWT.php b/DataStorage/Session/JWT.php index f629efde9..c1fd0ac2f 100644 --- a/DataStorage/Session/JWT.php +++ b/DataStorage/Session/JWT.php @@ -49,10 +49,7 @@ final class JWT $payload64 = Base64Url::encode(\json_encode($payload)); $algorithm = ''; - switch (\strtolower($header['alg'])) { - default: - $algorithm = 'sha256'; - } + $algorithm = 'sha256'; return \hash_hmac($algorithm, $header64 . '.' . $payload64, $secret, false); } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index ade029c5f..2a7cca7b4 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -848,11 +848,7 @@ class Matrix implements \ArrayAccess, \Iterator for ($i = 0; $i < $this->m; ++$i) { $row = []; for ($j = 0; $j < $this->m; ++$j) { - if ($i === $j) { - $row[] = \pow($this->matrix[$i][$j], $exponent); - } else { - $row[] = 0; - } + $row[] = $i === $j ? \pow($this->matrix[$i][$j], $exponent) : 0; } $matrix[] = $row; diff --git a/Message/Cli/CliHeader.php b/Message/Cli/CliHeader.php index 7773b1743..4177b545d 100755 --- a/Message/Cli/CliHeader.php +++ b/Message/Cli/CliHeader.php @@ -153,10 +153,7 @@ final class CliHeader extends HeaderAbstract */ public function generate(int $code) : void { - switch ($code) { - default: - $this->generate500(); - } + $this->generate500(); } public function getRequestTime() : int diff --git a/Message/Http/HttpHeader.php b/Message/Http/HttpHeader.php index 7aaa513ac..19c62191f 100755 --- a/Message/Http/HttpHeader.php +++ b/Message/Http/HttpHeader.php @@ -160,7 +160,7 @@ final class HttpHeader extends HeaderAbstract return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? ''; } - public function getBrowserName() { + public function getBrowserName(): string { $userAgent = $_SERVER['HTTP_USER_AGENT']; if (\strpos($userAgent, 'Opera') !== false || \strpos($userAgent, 'OPR/') !== false) { diff --git a/Model/Html/FormElementGenerator.php b/Model/Html/FormElementGenerator.php index faa696860..d3542999c 100755 --- a/Model/Html/FormElementGenerator.php +++ b/Model/Html/FormElementGenerator.php @@ -80,9 +80,14 @@ final class FormElementGenerator $element .= ($json['subtype'] === 'checkbox' || $json['subtype'] === 'radio') && $json['default']['checked'] ? ' checked' : ''; $element .= '>'; - $element .= $json['subtype'] === 'checkbox' || $json['subtype'] === 'radio' ? '' : ''; - return $element; + return $element + . ($json['subtype'] === 'checkbox' || $json['subtype'] === 'radio' + ? '' + : '' + ); } /** @@ -108,12 +113,12 @@ final class FormElementGenerator $value ??= $json['default']['value']; foreach ($json['options'] as $val => $text) { - $element .= ''; + $element .= ''; } - $element .= ''; - - return $element; + return $element . ''; } /** @@ -137,9 +142,8 @@ final class FormElementGenerator $element .= '>'; $element .= isset($json['default']) ? $value : ''; - $element .= ''; - return $element; + return $element . ''; } /** @@ -161,8 +165,7 @@ final class FormElementGenerator $element .= '>'; $element .= $lang[$json['default']['value']] ?? $json['default']['value']; - $element .= ''; - return $element; + return $element . ''; } } diff --git a/Socket/SocketAbstract.php b/Socket/SocketAbstract.php index 5e884aa26..80354ad87 100755 --- a/Socket/SocketAbstract.php +++ b/Socket/SocketAbstract.php @@ -81,7 +81,7 @@ abstract class SocketAbstract implements SocketInterface */ public function close() : void { - if (isset($this->sock)) { + if ($this->sock !== null) { \socket_shutdown($this->sock, 2); \socket_close($this->sock); $this->sock = null; diff --git a/Stdlib/Base/SmartDateTime.php b/Stdlib/Base/SmartDateTime.php index be4df3e4f..43f4a1e1a 100755 --- a/Stdlib/Base/SmartDateTime.php +++ b/Stdlib/Base/SmartDateTime.php @@ -120,11 +120,7 @@ class SmartDateTime extends \DateTime $dayMonthNew = \cal_days_in_month($calendar, $monthNew, $yearNew); $dayOld = (int) $this->format('d'); - if ($dayOld > $dayMonthNew || $dayOld === $dayMonthOld) { - $dayNew = $dayMonthNew; - } else { - $dayNew = $dayOld; - } + $dayNew = $dayOld > $dayMonthNew || $dayOld === $dayMonthOld ? $dayMonthNew : $dayOld; $this->setDate($yearNew, $monthNew, $dayNew); diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index db8b0cfa9..137192abc 100755 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -269,7 +269,7 @@ class Graph $edges = $this->nodes[$id]->getEdges(); foreach ($edges as $edge) { - $neighbor = !$edge->node1->isEqual($node) ? $edge->node1 : $edge->node2; + $neighbor = $edge->node1->isEqual($node) ? $edge->node2 : $edge->node1; if (!isset($visited[$neighbor->getId()]) || !$visited[$neighbor->getId()]) { $parent[$neighbor->getId()] = $node; @@ -583,7 +583,7 @@ class Graph while (!empty($stack)) { $cNode = \array_pop($stack); - if (isset($visited[$cNode->getId()]) && $visited[$cNode->getId()] === true) { + if (isset($visited[$cNode->getId()]) && $visited[$cNode->getId()]) { continue; } @@ -592,7 +592,7 @@ class Graph $neighbors = $cNode->getNeighbors(); foreach ($neighbors as $neighbor) { - if (!isset($visited[$neighbor->getId()]) || $visited[$neighbor->getId()] === false) { + if (!isset($visited[$neighbor->getId()]) || !$visited[$neighbor->getId()]) { $stack[] = $neighbor; } } diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index 24c3c3266..9a5e2847c 100755 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -295,8 +295,7 @@ final class FileUtils $name = \preg_replace("/[^A-Za-z0-9\-_.]/", '_', $name); $name = \preg_replace("/_+/", '_', $name ?? ''); $name = \trim($name ?? '', '_'); - $name = \strtolower($name); - return $name; + return \strtolower($name); } } diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index 1aab9bcf7..138e36ca5 100755 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -139,7 +139,7 @@ class File extends FileAbstract implements FileInterface if (ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) { $content .= self::get($con, $path); } elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) { - $content = $content . self::get($con, $path); + $content .= self::get($con, $path); } elseif (!Directory::exists($con, \dirname($path))) { Directory::create($con, \dirname($path), 0755, true); } diff --git a/Uri/HttpUri.php b/Uri/HttpUri.php index 7b8b9bf49..779c2e403 100755 --- a/Uri/HttpUri.php +++ b/Uri/HttpUri.php @@ -437,6 +437,6 @@ final class HttpUri implements UriInterface */ public function getUserInfo() : string { - return $this->user . (!empty($this->pass) ? ':' . $this->pass : ''); + return $this->user . (empty($this->pass) ? '' : ':' . $this->pass); } } diff --git a/Utils/Barcode/Datamatrix.php b/Utils/Barcode/Datamatrix.php index fd0bb2422..101505d0b 100755 --- a/Utils/Barcode/Datamatrix.php +++ b/Utils/Barcode/Datamatrix.php @@ -613,8 +613,7 @@ class Datamatrix extends TwoDAbstract if ($this->isCharMode($tmpchr, self::ENC_X12)) { return self::ENC_X12; - } elseif (!($this->isCharMode($tmpchr, self::ENC_X12) - || $this->isCharMode($tmpchr, self::ENC_C40)) + } elseif (!$this->isCharMode($tmpchr, self::ENC_X12) && !$this->isCharMode($tmpchr, self::ENC_C40) ) { break; } diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index 23d12b303..eea5269c0 100755 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -105,7 +105,7 @@ final class Currency try { $xml = new \SimpleXMLElement(Rest::request($request)->getBody()); - if (!isset($xml->Cube)) { + if (!(property_exists($xml, 'Cube') && $xml->Cube !== null)) { throw new \Exception('Invalid xml path'); // @codeCoverageIgnore } diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php index ac41d0cd0..e8c9afe2a 100755 --- a/Utils/Parser/Markdown/Markdown.php +++ b/Utils/Parser/Markdown/Markdown.php @@ -325,19 +325,12 @@ class Markdown $methodName = 'block' . $CurrentBlock['type'] . 'Continue'; $Block = $this->{$methodName}($Line, $CurrentBlock); - if (isset($Block)) - { + if (isset($Block)) { $CurrentBlock = $Block; - continue; - } - else - { - if ($this->isBlockCompletable($CurrentBlock['type'])) - { - $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; - $CurrentBlock = $this->{$methodName}($CurrentBlock); - } + } elseif ($this->isBlockCompletable($CurrentBlock['type'])) { + $methodName = 'block' . $CurrentBlock['type'] . 'Complete'; + $CurrentBlock = $this->{$methodName}($CurrentBlock); } } @@ -450,12 +443,12 @@ class Markdown return $Component['element']; } - protected function isBlockContinuable($Type) + protected function isBlockContinuable($Type): bool { return \method_exists($this, 'block' . $Type . 'Continue'); } - protected function isBlockCompletable($Type) + protected function isBlockCompletable($Type): bool { return \method_exists($this, 'block' . $Type . 'Complete'); } @@ -474,7 +467,7 @@ class Markdown { $text = \substr($Line['body'], 4); - $Block = [ + return [ 'element' => [ 'name' => 'pre', 'element' => [ @@ -483,8 +476,6 @@ class Markdown ], ], ]; - - return $Block; } } @@ -604,7 +595,7 @@ class Markdown $Element['attributes'] = ['class' => "language-{$language}"]; } - $Block = [ + return [ 'char' => $marker, 'openerLength' => $openerLength, 'element' => [ @@ -612,8 +603,6 @@ class Markdown 'element' => $Element, ], ]; - - return $Block; } protected function blockFencedCodeContinue($Line, $Block) @@ -656,11 +645,9 @@ class Markdown { $this->DefinitionData['Abbreviation'][$matches[1]] = $matches[2]; - $Block = [ + return [ 'hidden' => true, ]; - - return $Block; } } @@ -671,13 +658,11 @@ class Markdown { if (\preg_match('/^\[\^(.+?)\]:[ ]?(.*)$/', $Line['text'], $matches)) { - $Block = [ + return [ 'label' => $matches[1], 'text' => $matches[2], 'hidden' => true, ]; - - return $Block; } } @@ -747,18 +732,14 @@ class Markdown $Block['element'] = $Element; - $Block = $this->addDdElement($Line, $Block); - - return $Block; + return $this->addDdElement($Line, $Block); } protected function blockDefinitionListContinue($Line, array $Block) { if ($Line['text'][0] === ':') { - $Block = $this->addDdElement($Line, $Block); - - return $Block; + return $this->addDdElement($Line, $Block); } else { @@ -918,7 +899,7 @@ class Markdown 'name' => 'li', 'handler' => [ 'function' => 'li', - 'argument' => !empty($matches[3]) ? [$matches[3]] : [], + 'argument' => empty($matches[3]) ? [] : [$matches[3]], 'destination' => 'elements', ], ]; @@ -1038,7 +1019,7 @@ class Markdown { if (\preg_match('/^>[ ]?+(.*+)/', $Line['text'], $matches)) { - $Block = [ + return [ 'element' => [ 'name' => 'blockquote', 'handler' => [ @@ -1048,8 +1029,6 @@ class Markdown ], ], ]; - - return $Block; } } @@ -1084,13 +1063,11 @@ class Markdown if (\substr_count($Line['text'], $marker) >= 3 && \rtrim($Line['text'], " {$marker}") === '') { - $Block = [ + return [ 'element' => [ 'name' => 'hr', ], ]; - - return $Block; } } @@ -1307,9 +1284,8 @@ class Markdown $DOMDocument->documentElement->nodeValue = 'placeholder\x1A'; $markup = $DOMDocument->saveHTML($DOMDocument->documentElement); - $markup = \str_replace('placeholder\x1A', $elementText, $markup); - return $markup; + return \str_replace('placeholder\x1A', $elementText, $markup); } # @@ -1329,11 +1305,9 @@ class Markdown $this->DefinitionData['Reference'][$id] = $Data; - $Block = [ + return [ 'element' => [], ]; - - return $Block; } } @@ -1892,7 +1866,7 @@ class Markdown { if (\preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) { - $definition = \strlen($matches[1]) ? $matches[1] : $Element['handler']['argument']; + $definition = \strlen($matches[1]) !== 0 ? $matches[1] : $Element['handler']['argument']; $definition = \strtolower($definition); $extent += \strlen($matches[0]); @@ -2053,7 +2027,7 @@ class Markdown protected function inlineUrl($Excerpt) { - if ($this->urlsLinked !== true || ! isset($Excerpt['text'][2]) || $Excerpt['text'][2] !== '/') + if (!$this->urlsLinked || ! isset($Excerpt['text'][2]) || $Excerpt['text'][2] !== '/') { return; } @@ -2063,7 +2037,7 @@ class Markdown ) { $url = $matches[0][0]; - $Inline = [ + return [ 'extent' => \strlen($matches[0][0]), 'position' => $matches[0][1], 'element' => [ @@ -2074,8 +2048,6 @@ class Markdown ], ], ]; - - return $Inline; } } @@ -2183,9 +2155,7 @@ class Markdown $Element['element'] = $this->elementsApplyRecursiveDepthFirst($closure, $Element['element']); } - $Element = $closure($Element); - - return $Element; + return $closure($Element); } protected function elementsApplyRecursive($closure, array $Elements) @@ -2269,17 +2239,12 @@ class Markdown elseif (isset($Element['element'])) { $markup .= $this->element($Element['element']); + } elseif (!$permitRawHtml) { + $markup .= self::escape($text, true); } else { - if (!$permitRawHtml) - { - $markup .= self::escape($text, true); - } - else - { - $markup .= $text; - } + $markup .= $text; } $markup .= $hasName ? '' : ''; @@ -2292,7 +2257,7 @@ class Markdown return $markup; } - protected function elements(array $Elements) + protected function elements(array $Elements): string { $markup = ''; @@ -2309,15 +2274,13 @@ class Markdown ? $Element['autobreak'] : isset($Element['name']) ); // (autobreak === false) covers both sides of an element - $autoBreak = !$autoBreak ? $autoBreak : $autoBreakNext; + $autoBreak = $autoBreak ? $autoBreakNext : $autoBreak; $markup .= ($autoBreak ? "\n" : '') . $this->element($Element); $autoBreak = $autoBreakNext; } - $markup .= $autoBreak ? "\n" : ''; - - return $markup; + return $markup . ($autoBreak ? "\n" : ''); } # ~ @@ -2377,9 +2340,7 @@ class Markdown { $parsedown = new self(); - $markup = $parsedown->text($text); - - return $markup; + return $parsedown->text($text); } protected function sanitiseElement(array $Element) @@ -2440,7 +2401,7 @@ class Markdown # Static Methods # - protected static function escape($text, $allowQuotes = false) + protected static function escape($text, $allowQuotes = false): string { return \htmlspecialchars($text, $allowQuotes ? \ENT_NOQUOTES : \ENT_QUOTES, 'UTF-8'); } diff --git a/tests/Application/ApplicationManagerTest.php b/tests/Application/ApplicationManagerTest.php index a51ea8b35..6c594c4e1 100755 --- a/tests/Application/ApplicationManagerTest.php +++ b/tests/Application/ApplicationManagerTest.php @@ -178,8 +178,8 @@ final class ApplicationManagerTest extends \PHPUnit\Framework\TestCase */ public function testInvalidSourceUninstallPath() : void { - self::assertFalse($this->appManager->uninstall(__DIR__ . '/invalid', __DIR__)); - self::assertFalse($this->appManager->uninstall(__DIR__, __DIR__)); + self::assertFalse($this->appManager->uninstall(__DIR__ . '/invalid')); + self::assertFalse($this->appManager->uninstall(__DIR__)); } /** diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 6b7b131da..bdb807508 100755 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -8,9 +8,9 @@ declare(strict_types=1); \setlocale(\LC_ALL, 'en_US.UTF-8'); if (\is_file('vendor/autoload.php')) { - include_once 'vendor/autoload.php'; + include_once __DIR__ . '/vendor/autoload.php'; } elseif (\is_file('../../vendor/autoload.php')) { - include_once '../../vendor/autoload.php'; + include_once __DIR__ . '/../../vendor/autoload.php'; } require_once __DIR__ . '/../Autoloader.php'; @@ -455,7 +455,7 @@ function phpServe() : void // Execute the command and store the process ID $output = []; - echo \sprintf('Starting server...') . \PHP_EOL; + echo 'Starting server...' . \PHP_EOL; echo \sprintf(' Current directory: %s', \getcwd()) . \PHP_EOL; echo \sprintf(' %s', $command); \exec($command, $output); @@ -480,7 +480,7 @@ function phpServe() : void // Kill the web server when the process ends \register_shutdown_function(function() use ($killCommand, $pid) : void { - echo \PHP_EOL . \sprintf('Stopping server...') . \PHP_EOL; + echo \PHP_EOL . 'Stopping server...' . \PHP_EOL; echo \sprintf(' %s - Killing process with ID %d', \date('r'), $pid) . \PHP_EOL; \exec($killCommand . $pid); }); diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php index 009d7784e..952a01d92 100755 --- a/tests/Dispatcher/DispatcherTest.php +++ b/tests/Dispatcher/DispatcherTest.php @@ -85,7 +85,7 @@ final class DispatcherTest extends \PHPUnit\Framework\TestCase self::assertTrue( !empty( $this->app->dispatcher->dispatch( - function($req, $resp, $data = null) { return true; }, + function($req, $resp, $data = null): bool { return true; }, new HttpRequest(new HttpUri(''), $localization), new HttpResponse($localization) ) @@ -95,7 +95,7 @@ final class DispatcherTest extends \PHPUnit\Framework\TestCase self::assertTrue( !empty( $this->app->dispatcher->dispatch( - function($req) { return true; } + function($req): bool { return true; } ) ) ); @@ -182,7 +182,7 @@ final class DispatcherTest extends \PHPUnit\Framework\TestCase !empty( $this->app->dispatcher->dispatch( [ - function($app, $req, $resp, $data = null) { return true; }, + function($app, $req, $resp, $data = null): bool { return true; }, 'phpOMS\tests\Dispatcher\TestController:testFunction', 'phpOMS\tests\Dispatcher\TestController::testFunctionStatic', ], diff --git a/tests/Dispatcher/TestController.php b/tests/Dispatcher/TestController.php index 539bc39af..55e58a999 100755 --- a/tests/Dispatcher/TestController.php +++ b/tests/Dispatcher/TestController.php @@ -16,17 +16,17 @@ namespace phpOMS\tests\Dispatcher; class TestController { - public function testFunction($req, $resp, $data = null) + public function testFunction($req, $resp, $data = null): bool { return true; } - public function testFunctionNoPara() + public function testFunctionNoPara(): bool { return true; } - public static function testFunctionStatic($req, $resp, $data = null) + public static function testFunctionStatic($req, $resp, $data = null): bool { return true; } diff --git a/tests/Event/EventManagerTest.php b/tests/Event/EventManagerTest.php index 2302e37e6..9ae71af41 100755 --- a/tests/Event/EventManagerTest.php +++ b/tests/Event/EventManagerTest.php @@ -52,7 +52,7 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testAdd() : void { - self::assertTrue($this->event->attach('group', function() { return true; }, false, false)); + self::assertTrue($this->event->attach('group', function(): bool { return true; }, false, false)); self::assertEquals(1, $this->event->count()); } @@ -63,7 +63,7 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testClear() : void { - self::assertTrue($this->event->attach('group', function() { return true; }, false, false)); + self::assertTrue($this->event->attach('group', function(): bool { return true; }, false, false)); self::assertEquals(1, $this->event->count()); $this->event->clear(); @@ -77,8 +77,8 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testAddMultiple() : void { - self::assertTrue($this->event->attach('group', function() { return true; }, false, false)); - self::assertTrue($this->event->attach('group', function() { return true; }, false, false)); + self::assertTrue($this->event->attach('group', function(): bool { return true; }, false, false)); + self::assertTrue($this->event->attach('group', function(): bool { return true; }, false, false)); self::assertEquals(1, $this->event->count()); } @@ -185,7 +185,7 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testReset() : void { - self::assertTrue($this->event->attach('group', function() { return true; }, false, true)); + self::assertTrue($this->event->attach('group', function(): bool { return true; }, false, true)); $this->event->addGroup('group', 'id1'); $this->event->addGroup('group', 'id2'); @@ -201,7 +201,7 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testNoReset() : void { - self::assertTrue($this->event->attach('group', function() { return true; }, false, false)); + self::assertTrue($this->event->attach('group', function(): bool { return true; }, false, false)); $this->event->addGroup('group', 'id1'); $this->event->addGroup('group', 'id2'); @@ -217,7 +217,7 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testDetach() : void { - $this->event->attach('group', function() { return true; }, false, true); + $this->event->attach('group', function(): bool { return true; }, false, true); $this->event->addGroup('group', 'id1'); $this->event->addGroup('group', 'id2'); @@ -234,7 +234,7 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testInvalidDetach() : void { - $this->event->attach('group', function() { return true; }, false, true); + $this->event->attach('group', function(): bool { return true; }, false, true); $this->event->addGroup('group', 'id1'); $this->event->addGroup('group', 'id2'); @@ -249,8 +249,8 @@ final class EventManagerTest extends \PHPUnit\Framework\TestCase */ public function testRemove() : void { - self::assertTrue($this->event->attach('group1', function() { return true; }, true, false)); - self::assertTrue($this->event->attach('group2', function() { return true; }, true, false)); + self::assertTrue($this->event->attach('group1', function(): bool { return true; }, true, false)); + self::assertTrue($this->event->attach('group2', function(): bool { return true; }, true, false)); self::assertEquals(2, $this->event->count()); $this->event->trigger('group1'); diff --git a/tests/Localization/MoneyTest.php b/tests/Localization/MoneyTest.php index eb094cd51..3e213613e 100755 --- a/tests/Localization/MoneyTest.php +++ b/tests/Localization/MoneyTest.php @@ -87,7 +87,7 @@ final class MoneyTest extends \PHPUnit\Framework\TestCase public function testMoneyLocalization() : void { $money = new Money(12345678); - self::assertEquals('€ 9.992,30', $money->setInt(99923000)->setLocalization('.', ',', ISO4217SymbolEnum::_EUR, 0)->getCurrency()); + self::assertEquals('€ 9.992,30', $money->setInt(99923000)->setLocalization('.', ',')->getCurrency()); } /** diff --git a/tests/Math/Functions/GammaTest.php b/tests/Math/Functions/GammaTest.php index 52ce6871c..bb0c84044 100755 --- a/tests/Math/Functions/GammaTest.php +++ b/tests/Math/Functions/GammaTest.php @@ -57,7 +57,7 @@ final class GammaTest extends \PHPUnit\Framework\TestCase ]; for ($i = 1; $i <= 10; ++$i) { - if (!(\abs($spouge[$i - 1] - Gamma::spougeApproximation($i / 3)) < 0.01)) { + if (\abs($spouge[$i - 1] - Gamma::spougeApproximation($i / 3)) >= 0.01) { self::assertTrue(false); } } @@ -77,7 +77,7 @@ final class GammaTest extends \PHPUnit\Framework\TestCase ]; for ($i = 1; $i <= 10; ++$i) { - if (!(\abs($stirling[$i - 1] - Gamma::stirlingApproximation($i / 3)) < 0.01)) { + if (\abs($stirling[$i - 1] - Gamma::stirlingApproximation($i / 3)) >= 0.01) { self::assertTrue(false); } } @@ -97,7 +97,7 @@ final class GammaTest extends \PHPUnit\Framework\TestCase ]; for ($i = 1; $i <= 10; ++$i) { - if (!(\abs($gsl[$i - 1] - Gamma::lanczosApproximationReal($i / 3)) < 0.01)) { + if (\abs($gsl[$i - 1] - Gamma::lanczosApproximationReal($i / 3)) >= 0.01) { self::assertTrue(false); } } @@ -117,7 +117,7 @@ final class GammaTest extends \PHPUnit\Framework\TestCase ]; for ($i = 1; $i <= 10; ++$i) { - if (!(\abs($gsl[$i - 1] - Gamma::logGamma($i)) < 0.01)) { + if (\abs($gsl[$i - 1] - Gamma::logGamma($i)) >= 0.01) { self::assertTrue(false); } } diff --git a/tests/Security/Sample/hasUnicode.php b/tests/Security/Sample/hasUnicode.php index b8a5875c7..2cffa31cc 100755 --- a/tests/Security/Sample/hasUnicode.php +++ b/tests/Security/Sample/hasUnicode.php @@ -1,7 +1,7 @@ graph->getCircuitRank()); self::assertTrue($this->graph->isConnected()); - self::assertTrue($this->graph->isBipartite(1)); + self::assertTrue($this->graph->isBipartite()); self::assertFalse($this->graph->isDirected()); self::assertFalse($this->graph->hasCycle()); @@ -639,7 +639,7 @@ final class GraphTest extends \PHPUnit\Framework\TestCase $node3->setNodeRelative($node5); $node4->setNodeRelative($node5); - $paths = $this->graph->getFloydWarshallShortestPath($node0, $node5); + $paths = $this->graph->getFloydWarshallShortestPath(); self::assertGreaterThan(1, $paths); } @@ -679,7 +679,7 @@ final class GraphTest extends \PHPUnit\Framework\TestCase $node3->setNodeRelative($node5); $node4->setNodeRelative($node5); - $paths = $this->graph->longestPath($node0, $node5); + $paths = $this->graph->longestPath(); self::assertGreaterThan(1, $paths); }