From f09df7ea16f2961c870df5e4bfce83f8bd3fa6e1 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 27 May 2023 03:06:46 +0000 Subject: [PATCH] rector fixes + bug fixes --- Ai/Ocr/BasicOcr.php | 2 +- Ai/Ocr/Tesseract/TesseractOcr.php | 22 ++-- Algorithm/Clustering/Kmeans.php | 6 +- Algorithm/Graph/DependencyResolver.php | 2 +- Algorithm/PathFinding/JumpPointSearch.php | 38 +++---- Algorithm/PathFinding/Path.php | 4 +- Api/Geocoding/Nominatim.php | 2 +- DataStorage/Cache/Connection/MemCached.php | 6 +- DataStorage/Cache/Connection/RedisCache.php | 8 +- DataStorage/Database/Mapper/DeleteMapper.php | 3 +- DataStorage/Database/Mapper/WriteMapper.php | 4 +- DataStorage/Database/SchemaMapper.php | 8 +- Image/Skew.php | 4 +- Localization/L11nManager.php | 14 +-- Localization/LanguageDetection/Language.php | 35 +++--- .../LanguageDetection/LanguageResult.php | 4 +- Math/Functions/Functions.php | 12 +- Math/Geometry/Shape/D2/Polygon.php | 3 +- Math/Matrix/CholeskyDecomposition.php | 6 +- Math/Matrix/EigenvalueDecomposition.php | 44 ++++---- Math/Matrix/LUDecomposition.php | 16 +-- Math/Matrix/Matrix.php | 4 +- Math/Matrix/QRDecomposition.php | 6 +- Math/Number/Numbers.php | 4 +- Math/Number/Prime.php | 2 +- Math/Parser/Evaluator.php | 8 +- Math/Statistic/Average.php | 2 +- Math/Statistic/Basic.php | 6 +- Message/Cli/CliRequest.php | 106 +++++++++++++++++- Message/Http/HttpRequest.php | 8 +- Message/Http/HttpResponse.php | 2 +- Message/Http/Rest.php | 4 +- Message/Mail/Email.php | 77 ++++++------- Message/Mail/Imap.php | 8 +- Message/Mail/MailHandler.php | 2 +- Message/Mail/Pop3.php | 4 +- Message/Mail/Smtp.php | 8 +- Message/RequestAbstract.php | 6 +- Model/Html/Head.php | 3 +- Model/Html/Meta.php | 8 +- Module/ModuleManager.php | 10 +- Module/PackageManager.php | 2 +- Security/Guard.php | 13 ++- Socket/Client/Client.php | 4 +- Stdlib/Graph/Graph.php | 5 +- Stdlib/Graph/Node.php | 8 +- Stdlib/Queue/PriorityQueue.php | 2 +- System/File/FileUtils.php | 2 +- System/File/Ftp/Directory.php | 8 +- System/File/Ftp/File.php | 8 +- System/File/Local/File.php | 2 +- UnhandledHandler.php | 2 +- Uri/Argument.php | 4 +- Uri/HttpUri.php | 2 +- Utils/ArrayUtils.php | 1 + Utils/Barcode/BarAbstract.php | 2 +- Utils/Barcode/C128c.php | 12 +- Utils/Barcode/C25.php | 2 +- Utils/Barcode/Codebar.php | 2 +- Utils/Barcode/Datamatrix.php | 49 +++----- Utils/Barcode/QR.php | 100 ++++++++--------- Utils/Compression/LZW.php | 4 +- Utils/Git/Repository.php | 12 +- Utils/ImageUtils.php | 8 +- Utils/NumericUtils.php | 8 +- Utils/Parser/Pdf/PdfParser.php | 90 +++++++++------ .../Presentation/PresentationWriter.php | 14 +-- Utils/RnG/Text.php | 40 ++----- Utils/StringUtils.php | 8 +- Utils/TaskSchedule/CronJob.php | 3 +- Validation/Base/Json.php | 15 +-- Validation/Validator.php | 16 +-- Views/View.php | 4 +- Views/ViewAbstract.php | 4 +- tests/Log/FileLoggerTest.php | 2 +- .../Distribution/GammaDistributionTest.php | 4 +- .../Distribution/ParetoDistributionTest.php | 4 +- tests/Socket/Client/ClientTest.php | 24 ++-- tests/Socket/Server/ServerTestHelper.php | 10 +- tests/System/File/Ftp/FtpStorageTest.php | 2 +- tests/System/File/Local/LocalStorageTest.php | 2 +- 81 files changed, 506 insertions(+), 519 deletions(-) diff --git a/Ai/Ocr/BasicOcr.php b/Ai/Ocr/BasicOcr.php index 238767f5d..3c39435a6 100755 --- a/Ai/Ocr/BasicOcr.php +++ b/Ai/Ocr/BasicOcr.php @@ -294,7 +294,7 @@ final class BasicOcr 3 ); - \array_push($mnist, $gray); + $mnist[] = $gray; } } diff --git a/Ai/Ocr/Tesseract/TesseractOcr.php b/Ai/Ocr/Tesseract/TesseractOcr.php index 7193e756e..4ff80bd28 100755 --- a/Ai/Ocr/Tesseract/TesseractOcr.php +++ b/Ai/Ocr/Tesseract/TesseractOcr.php @@ -92,15 +92,19 @@ final class TesseractOcr return ''; } - SystemUtils::runProc( - self::$bin, - $image . ' ' - . $temp - . ' -c preserve_interword_spaces=1' - . ' --psm ' . $psm - . ' --oem ' . $oem - . ' -l ' . \implode('+', $languages) - ); + try { + SystemUtils::runProc( + self::$bin, + $image . ' ' + . $temp + . ' -c preserve_interword_spaces=1' + . ' --psm ' . $psm + . ' --oem ' . $oem + . ' -l ' . \implode('+', $languages) + ); + } catch (\Throwable $_) { + return ''; + } $filepath = \is_file($temp . '.txt') ? $temp . '.txt' diff --git a/Algorithm/Clustering/Kmeans.php b/Algorithm/Clustering/Kmeans.php index 65cb37def..3ea762cd7 100755 --- a/Algorithm/Clustering/Kmeans.php +++ b/Algorithm/Clustering/Kmeans.php @@ -138,11 +138,7 @@ final class Kmeans foreach ($points as $point) { $clusterPoint = $clusterCenters[$point->group]; - // this should ensure that clusterPoint and therfore the center group is never 0. But this is not true. - $clusterPoint->group = ( - $clusterPoint->group + 1 - ); - + ++$clusterPoint->group; for ($i = 0; $i < $coordinates; ++$i) { $clusterPoint->setCoordinate($i, $clusterPoint->getCoordinate($i) + $point->getCoordinate($i)); } diff --git a/Algorithm/Graph/DependencyResolver.php b/Algorithm/Graph/DependencyResolver.php index 21f570043..e200af960 100755 --- a/Algorithm/Graph/DependencyResolver.php +++ b/Algorithm/Graph/DependencyResolver.php @@ -41,7 +41,7 @@ final class DependencyResolver self::dependencyResolve($table, $graph, $resolved, $unresolved); } - return !empty($unresolved) ? null : $resolved; + return empty($unresolved) ? $resolved : null; } /** diff --git a/Algorithm/PathFinding/JumpPointSearch.php b/Algorithm/PathFinding/JumpPointSearch.php index 51348fd38..4e1380e46 100755 --- a/Algorithm/PathFinding/JumpPointSearch.php +++ b/Algorithm/PathFinding/JumpPointSearch.php @@ -355,19 +355,19 @@ final class JumpPointSearch implements PathFinderInterface if (!$grid->isWalkable($x + 1, $y)) { $neighbors[] = $grid->getNode($x + 1, $y + $dy); } + if (!$grid->isWalkable($x - 1, $y)) { $neighbors[] = $grid->getNode($x - 1, $y + $dy); } } - } else { - if ($grid->isWalkable($x + $dx, $y)) { - $neighbors[] = $grid->getNode($x + $dx, $y); - if (!$grid->isWalkable($x, $y + 1)) { - $neighbors[] = $grid->getNode($x + $dx, $y + 1); - } - if (!$grid->isWalkable($x, $y - 1)) { - $neighbors[] = $grid->getNode($x + $dx, $y - 1); - } + } elseif ($grid->isWalkable($x + $dx, $y)) { + $neighbors[] = $grid->getNode($x + $dx, $y); + if (!$grid->isWalkable($x, $y + 1)) { + $neighbors[] = $grid->getNode($x + $dx, $y + 1); + } + + if (!$grid->isWalkable($x, $y - 1)) { + $neighbors[] = $grid->getNode($x + $dx, $y - 1); } } @@ -598,12 +598,10 @@ final class JumpPointSearch implements PathFinderInterface ) { return $node; } - } else { - if (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y)) - || ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y)) - ) { - return $node; - } + } elseif (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y)) + || ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y)) + ) { + return $node; } return self::jumpDiagonal($grid->getNode($x + $dx, $y + $dy), $node, $endNode, $grid); @@ -658,12 +656,10 @@ final class JumpPointSearch implements PathFinderInterface ) { return $node; } - } else { - if (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y)) - || ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y)) - ) { - return $node; - } + } elseif (($grid->isWalkable($x + 1, $y + $dy) && !$grid->isWalkable($x + 1, $y)) + || ($grid->isWalkable($x - 1, $y + $dy) && !$grid->isWalkable($x - 1, $y)) + ) { + return $node; } if ($grid->isWalkable($x + $dx, $y) || $grid->isWalkable($x, $y + $dy)) { diff --git a/Algorithm/PathFinding/Path.php b/Algorithm/PathFinding/Path.php index 3ce1ac430..4ec26e6c9 100755 --- a/Algorithm/PathFinding/Path.php +++ b/Algorithm/PathFinding/Path.php @@ -190,12 +190,12 @@ class Path if ($e2 > -$dy) { $err -= $dy; - $x0 = $x0 + $sx; + $x0 += $sx; } if ($e2 < $dx) { $err += $dx; - $y0 = $y0 + $sy; + $y0 += $sy; } $node = $this->grid->getNode($x0, $y0); diff --git a/Api/Geocoding/Nominatim.php b/Api/Geocoding/Nominatim.php index 2f5ad2d3b..1aa5de39a 100644 --- a/Api/Geocoding/Nominatim.php +++ b/Api/Geocoding/Nominatim.php @@ -40,7 +40,7 @@ final class Nominatim $request = new HttpRequest( new HttpUri( - $URL . '&country=' . \urlencode($country) . '&city=' . \urlencode($city) . ($address = '' ? '' : '&street=' . \urlencode($address)) + $URL . '&country=' . \urlencode($country) . '&city=' . \urlencode($city) . ($address === '' ? '' : '&street=' . \urlencode($address)) ) ); $request->setMethod(RequestMethod::GET); diff --git a/DataStorage/Cache/Connection/MemCached.php b/DataStorage/Cache/Connection/MemCached.php index d3249de4f..680e123f4 100755 --- a/DataStorage/Cache/Connection/MemCached.php +++ b/DataStorage/Cache/Connection/MemCached.php @@ -276,11 +276,7 @@ final class MemCached extends ConnectionAbstract */ public function flush(int $expire = 0) : bool { - if ($this->status !== CacheStatus::OK) { - return false; - } - - return true; + return $this->status === CacheStatus::OK; } /** diff --git a/DataStorage/Cache/Connection/RedisCache.php b/DataStorage/Cache/Connection/RedisCache.php index 27bd57437..76971e87f 100755 --- a/DataStorage/Cache/Connection/RedisCache.php +++ b/DataStorage/Cache/Connection/RedisCache.php @@ -77,7 +77,7 @@ final class RedisCache extends ConnectionAbstract try { $this->con->ping(); - } catch (\Throwable $e) { + } catch (\Throwable $_) { $this->status = CacheStatus::FAILURE; return; } @@ -301,11 +301,7 @@ final class RedisCache extends ConnectionAbstract */ public function flush(int $expire = 0) : bool { - if ($this->status !== CacheStatus::OK) { - return false; - } - - return true; + return $this->status === CacheStatus::OK; } /** diff --git a/DataStorage/Database/Mapper/DeleteMapper.php b/DataStorage/Database/Mapper/DeleteMapper.php index 5c78b836c..bbc00ccf4 100755 --- a/DataStorage/Database/Mapper/DeleteMapper.php +++ b/DataStorage/Database/Mapper/DeleteMapper.php @@ -183,8 +183,7 @@ final class DeleteMapper extends DataMapperAbstract } /** @var class-string $mapper */ - $mapper = $this->mapper::HAS_MANY[$member]['mapper']; - $relReflectionClass = !empty($values) ? new \ReflectionClass(\reset($values)) : null; + $mapper = $this->mapper::HAS_MANY[$member]['mapper']; foreach ($values as $key => $value) { if (!\is_object($value)) { diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 7afea280c..4848db5ee 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -392,9 +392,9 @@ final class WriteMapper extends DataMapperAbstract if ($sth !== false) { $sth->execute(); } - } catch (\Throwable $e) { + } catch (\Throwable $t) { // @codeCoverageIgnoreStart - \var_dump($e->getMessage()); + \var_dump($t->getMessage()); \var_dump($relQuery->toSql()); \var_dump(\debug_backtrace()); // @codeCoverageIgnoreEnd diff --git a/DataStorage/Database/SchemaMapper.php b/DataStorage/Database/SchemaMapper.php index cad61543f..014f2f559 100755 --- a/DataStorage/Database/SchemaMapper.php +++ b/DataStorage/Database/SchemaMapper.php @@ -86,9 +86,7 @@ class SchemaMapper */ public function getTable(string $name) : Table { - $table = new Table(); - - return $table; + return new Table(); } /** @@ -120,8 +118,6 @@ class SchemaMapper */ public function getField(string $table, string $name) : Field { - $field = new Field(); - - return $field; + return new Field(); } } diff --git a/Image/Skew.php b/Image/Skew.php index 092477a84..2482ce7ef 100755 --- a/Image/Skew.php +++ b/Image/Skew.php @@ -166,10 +166,10 @@ final class Skew private static function getNearestValue(array $pixel, array $dim, float $x, float $y) : int { $xLow = ($x < 0) ? 0 : (($x > ($dim[1] - 1)) ? ($dim[1] - 1) : (int) $x); - $xHigh = ($xLow == ($dim[1] - 1)) ? $xLow : ($xLow + 1); + $xHigh = ($xLow === $dim[1] - 1) ? $xLow : ($xLow + 1); $yLow = ($y < 0) ? 0 : (($y > ($dim[0] - 1)) ? ($dim[0] - 1) : (int) $y); - $yHigh = ($yLow == ($dim[0] - 1)) ? $yLow : ($yLow + 1); + $yHigh = ($yLow === $dim[0] - 1) ? $yLow : ($yLow + 1); $points = [ [$xLow, $yLow], diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index 4a4ef2ca7..af7d2b229 100755 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -73,9 +73,9 @@ final class L11nManager return; } - $this->language[$language][$from] = !isset($this->language[$language][$from]) - ? $translation[$from] - : $translation[$from] + $this->language[$language][$from]; + $this->language[$language][$from] = isset($this->language[$language][$from]) + ? $translation[$from] + $this->language[$language][$from] + : $translation[$from]; } /** @@ -176,7 +176,7 @@ final class L11nManager } $this->loadLanguage($code, $module, $class::getLocalization($code, $theme)); - } catch (\Throwable $e) { + } catch (\Throwable $_) { // @codeCoverageIgnoreStart FileLogger::getInstance()->warning(FileLogger::MSG_FULL, [ 'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.', @@ -296,9 +296,9 @@ final class L11nManager $currency = $currency->value; } - $money = !($currency instanceof Money) - ? new Money((int) ($currency / $divide)) - : $currency; + $money = $currency instanceof Money + ? $currency + : new Money((int) ($currency / $divide)); $money->setLocalization( $l11n->getThousands(), diff --git a/Localization/LanguageDetection/Language.php b/Localization/LanguageDetection/Language.php index d87d399d3..071770631 100755 --- a/Localization/LanguageDetection/Language.php +++ b/Localization/LanguageDetection/Language.php @@ -80,30 +80,33 @@ class Language extends NgramParser $samples = $this->getNgrams($str); $result = []; - if (\count($samples) > 0) { - foreach ($this->tokens as $lang => $value) { - $index = 0; - $sum = 0; - $value = \array_flip($value); + if (empty($samples)) { + return new LanguageResult($result); + } - foreach ($samples as $v) { - if (isset($value[$v])) { - $x = $index++ - $value[$v]; - $y = $x >> (\PHP_INT_SIZE * 8); - $sum += ($x + $y) ^ $y; - continue; - } + foreach ($this->tokens as $lang => $value) { + $index = 0; + $sum = 0; + $value = \array_flip($value); - $sum += $this->maxNgrams; - ++$index; + foreach ($samples as $v) { + if (isset($value[$v])) { + $x = $index++ - $value[$v]; + $y = $x >> (\PHP_INT_SIZE * 8); + $sum += ($x + $y) ^ $y; + + continue; } - $result[$lang] = 1 - ($sum / ($this->maxNgrams * $index)); + $sum += $this->maxNgrams; + ++$index; } - \arsort($result, \SORT_NUMERIC); + $result[$lang] = 1 - ($sum / ($this->maxNgrams * $index)); } + \arsort($result, \SORT_NUMERIC); + return new LanguageResult($result); } } diff --git a/Localization/LanguageDetection/LanguageResult.php b/Localization/LanguageDetection/LanguageResult.php index 83e1868bf..7bca4600d 100755 --- a/Localization/LanguageDetection/LanguageResult.php +++ b/Localization/LanguageDetection/LanguageResult.php @@ -157,14 +157,14 @@ class LanguageResult implements \JsonSerializable, \IteratorAggregate, \ArrayAcc */ public function bestResults(): LanguageResult { - if (!\count($this->result)) { + if (empty($this->result)) { return new LanguageResult; } $first = \array_values($this->result)[0]; return new LanguageResult(\array_filter($this->result, function ($value) use ($first) { - return ($first - $value) <= self::THRESHOLD ? true : false; + return ($first - $value) <= self::THRESHOLD; })); } diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index 6b66f3973..1eca2c311 100755 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -345,19 +345,11 @@ final class Functions for ($n = 0; $n < 20; ++$n) { foreach ($a as $key => $value) { - if ($n === 0) { - $aProd[$n][$key] = 1; - } else { - $aProd[$n][$key] = $aProd[$n - 1][$key] * ($value + $n - 1); - } + $aProd[$n][$key] = $n === 0 ? 1 : $aProd[$n - 1][$key] * ($value + $n - 1); } foreach ($b as $key => $value) { - if ($n === 0) { - $bProd[$n][$key] = 1; - } else { - $bProd[$n][$key] = $bProd[$n - 1][$key] * ($value + $n - 1); - } + $bProd[$n][$key] = $n === 0 ? 1 : $bProd[$n - 1][$key] * ($value + $n - 1); } $temp = \array_product($aProd[$n]) / \array_product($bProd[$n]); diff --git a/Math/Geometry/Shape/D2/Polygon.php b/Math/Geometry/Shape/D2/Polygon.php index 9bdefadeb..aa8b372f2 100755 --- a/Math/Geometry/Shape/D2/Polygon.php +++ b/Math/Geometry/Shape/D2/Polygon.php @@ -212,9 +212,8 @@ final class Polygon implements D2ShapeInterface } $surface += $this->coord[$count - 1]['x'] * $this->coord[0]['y'] - $this->coord[0]['x'] * $this->coord[$count - 1]['y']; - $surface /= 2; - return $surface; + return $surface / 2; } /** diff --git a/Math/Matrix/CholeskyDecomposition.php b/Math/Matrix/CholeskyDecomposition.php index 9917b30e7..eba74c8a8 100755 --- a/Math/Matrix/CholeskyDecomposition.php +++ b/Math/Matrix/CholeskyDecomposition.php @@ -77,10 +77,8 @@ final class CholeskyDecomposition } else { $this->isSpd = false; } - } else { - if ($this->L[$i][$i] !== 0) { - $this->L[$j][$i] = $sum / $this->L[$i][$i]; - } + } elseif ($this->L[$i][$i] !== 0) { + $this->L[$j][$i] = $sum / $this->L[$i][$i]; } } diff --git a/Math/Matrix/EigenvalueDecomposition.php b/Math/Matrix/EigenvalueDecomposition.php index 6defd089f..82975802e 100755 --- a/Math/Matrix/EigenvalueDecomposition.php +++ b/Math/Matrix/EigenvalueDecomposition.php @@ -552,10 +552,10 @@ final class EigenvalueDecomposition } if ($l === $n) { - $this->H[$n][$n] = $this->H[$n][$n] + $exshift; - $this->D[$n] = $this->H[$n][$n]; - $this->E[$n] = 0.0; - $iter = 0; + $this->H[$n][$n] += $exshift; + $this->D[$n] = $this->H[$n][$n]; + $this->E[$n] = 0.0; + $iter = 0; --$n; } elseif ($l === $n - 1) { @@ -721,12 +721,12 @@ final class EigenvalueDecomposition for ($j = $k; $j < $nn; ++$j) { $p = $this->H[$k][$j] + $q * $this->H[$k + 1][$j]; if ($notlast) { - $p = $p + $r * $this->H[$k + 2][$j]; - $this->H[$k + 2][$j] = $this->H[$k + 2][$j] - $p * $z; + $p += $r * $this->H[$k + 2][$j]; + $this->H[$k + 2][$j] -= $p * $z; } - $this->H[$k][$j] = $this->H[$k][$j] - $p * $x; - $this->H[$k + 1][$j] = $this->H[$k + 1][$j] - $p * $y; + $this->H[$k][$j] -= $p * $x; + $this->H[$k + 1][$j] -= $p * $y; } $min = \min($n, $k + 3); @@ -734,23 +734,23 @@ final class EigenvalueDecomposition $p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k + 1]; if ($notlast) { - $p = $p + $z * $this->H[$i][$k + 2]; - $this->H[$i][$k + 2] = $this->H[$i][$k + 2] - $p * $r; + $p += $z * $this->H[$i][$k + 2]; + $this->H[$i][$k + 2] -= $p * $r; } - $this->H[$i][$k] = $this->H[$i][$k] - $p; - $this->H[$i][$k + 1] = $this->H[$i][$k + 1] - $p * $q; + $this->H[$i][$k] -= $p; + $this->H[$i][$k + 1] -= $p * $q; } for ($i = $low; $i <= $high; ++$i) { $p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k + 1]; if ($notlast) { - $p += $z * $this->V[$i][$k + 2]; - $this->V[$i][$k + 2] = $this->V[$i][$k + 2] - $p * $r; + $p += $z * $this->V[$i][$k + 2]; + $this->V[$i][$k + 2] -= $p * $r; } - $this->V[$i][$k] = $this->V[$i][$k] - $p; - $this->V[$i][$k + 1] = $this->V[$i][$k + 1] - $p * $q; + $this->V[$i][$k] -= $p; + $this->V[$i][$k + 1] -= $p * $q; } } } @@ -796,7 +796,7 @@ final class EigenvalueDecomposition $t = \abs($this->H[$i][$n]); if ((self::EPSILON * $t) * $t > 1) { for ($j = $i; $j <= $n; ++$j) { - $this->H[$j][$n] = $this->H[$j][$n] / $t; + $this->H[$j][$n] /= $t; } } } @@ -821,8 +821,8 @@ final class EigenvalueDecomposition $sa = 0.0; for ($j = $l; $j <= $n; ++$j) { - $ra = $ra + $this->H[$i][$j] * $this->H[$j][$n - 1]; - $sa = $sa + $this->H[$i][$j] * $this->H[$j][$n]; + $ra += $this->H[$i][$j] * $this->H[$j][$n - 1]; + $sa += $this->H[$i][$j] * $this->H[$j][$n]; } $w = $this->H[$i][$i] - $p; @@ -844,7 +844,7 @@ final class EigenvalueDecomposition $vr = ($this->D[$i] - $p) * ($this->D[$i] - $p) + $this->E[$i] * $this->E[$i] - $q * $q; $vi = ($this->D[$i] - $p) * 2.0 * $q; - if ($vr == 0 & $vi == 0) { + if (($vr == 0 & $vi == 0) !== 0) { $vr = self::EPSILON * $norm * (\abs($w) + \abs($q) + \abs($x) + \abs($y) + \abs($z)); } @@ -866,8 +866,8 @@ final class EigenvalueDecomposition $t = \max(\abs($this->H[$i][$n - 1]), \abs($this->H[$i][$n])); if ((self::EPSILON * $t) * $t > 1) { for ($j = $i; $j <= $n; ++$j) { - $this->H[$j][$n - 1] = $this->H[$j][$n - 1] / $t; - $this->H[$j][$n] = $this->H[$j][$n] / $t; + $this->H[$j][$n - 1] /= $t; + $this->H[$j][$n] /= $t; } } } diff --git a/Math/Matrix/LUDecomposition.php b/Math/Matrix/LUDecomposition.php index 052216a3f..5c525c43d 100755 --- a/Math/Matrix/LUDecomposition.php +++ b/Math/Matrix/LUDecomposition.php @@ -119,10 +119,10 @@ final class LUDecomposition $this->LU[$j][$k] = $t; } - $k = $this->piv[$p]; - $this->piv[$p] = $this->piv[$j]; - $this->piv[$j] = $k; - $this->pivSign = $this->pivSign * -1; + $k = $this->piv[$p]; + $this->piv[$p] = $this->piv[$j]; + $this->piv[$j] = $k; + $this->pivSign *= -1; } if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) { @@ -148,7 +148,7 @@ final class LUDecomposition for ($j = 0; $j < $this->n; ++$j) { if ($i > $j) { $L[$i][$j] = $this->LU[$i][$j]; - } elseif ($i == $j) { + } elseif ($i === $j) { $L[$i][$j] = 1.0; } else { $L[$i][$j] = 0.0; @@ -175,11 +175,7 @@ final class LUDecomposition for ($i = 0; $i < $this->n; ++$i) { for ($j = 0; $j < $this->n; ++$j) { - if ($i <= $j) { - $U[$i][$j] = $this->LU[$i][$j] ?? 0; - } else { - $U[$i][$j] = 0.0; - } + $U[$i][$j] = $i <= $j ? $this->LU[$i][$j] ?? 0 : 0.0; } } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index 43d9d6fb1..bb317b736 100755 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -375,7 +375,7 @@ class Matrix implements \ArrayAccess, \Iterator public function setMatrix(array $matrix) : self { $this->m = \count($matrix); - $this->n = !\is_array($matrix[0] ?? 1) ? 1 : \count($matrix[0]); + $this->n = \is_array($matrix[0] ?? 1) ? \count($matrix[0]) : 1; $this->matrix = $matrix; return $this; @@ -619,7 +619,7 @@ class Matrix implements \ArrayAccess, \Iterator } } - if ($max) { + if ($max !== 0) { $sign = -$sign; $temp = $arr[$i]; $arr[$i] = $arr[$max]; diff --git a/Math/Matrix/QRDecomposition.php b/Math/Matrix/QRDecomposition.php index 7e4221e6d..6caabc9a3 100755 --- a/Math/Matrix/QRDecomposition.php +++ b/Math/Matrix/QRDecomposition.php @@ -57,7 +57,7 @@ final class QRDecomposition /** * R diagonal * - * @var array + * @var array * @since 1.0.0 */ private array $Rdiag = []; @@ -124,7 +124,7 @@ final class QRDecomposition public function isFullRank() : bool { for ($j = 0; $j < $this->n; ++$j) { - if ($this->Rdiag[$j] == 0) { + if (\abs($this->Rdiag[$j]) < Matrix::EPSILON) { return false; } } @@ -147,7 +147,7 @@ final class QRDecomposition for ($j = 0; $j < $this->n; ++$j) { if ($i < $j) { $R[$i][$j] = $this->QR[$i][$j]; - } elseif ($i == $j) { + } elseif ($i === $j) { $R[$i][$j] = $this->Rdiag[$i]; } else { $R[$i][$j] = 0.0; diff --git a/Math/Number/Numbers.php b/Math/Number/Numbers.php index 2abce63ff..0cf2a78f4 100755 --- a/Math/Number/Numbers.php +++ b/Math/Number/Numbers.php @@ -114,12 +114,12 @@ final class Numbers { $count = 0; while ($n !== 0) { - if ($n & 1 === 1) { + if (($n & 1) === 1) { break; } ++$count; - $n = $n >> 1; + $n >>= 1; } return $count; diff --git a/Math/Number/Prime.php b/Math/Number/Prime.php index c55dec5c2..c65e29a72 100755 --- a/Math/Number/Prime.php +++ b/Math/Number/Prime.php @@ -159,7 +159,7 @@ final class Prime while ($number * $number < $n) { for ($i = $number; $i <= $n; $i += $number) { - if ($i == $number) { + if ($i === $number) { continue; } diff --git a/Math/Parser/Evaluator.php b/Math/Parser/Evaluator.php index 540069786..b00bd6311 100755 --- a/Math/Parser/Evaluator.php +++ b/Math/Parser/Evaluator.php @@ -83,9 +83,9 @@ final class Evaluator */ private static function parseValue(int | float | string $value) : int | float { - return !\is_string($value) - ? $value - : (\stripos($value, '.') === false ? (int) $value : (float) $value); + return \is_string($value) + ? (\stripos($value, '.') === false ? (int) $value : (float) $value) + : $value; } /** @@ -149,7 +149,7 @@ final class Evaluator } } - while (\count($stack) > 0) { + while (!empty($stack)) { $output[] = \array_pop($stack); } diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index 4738b8df5..c50a124e2 100755 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -247,7 +247,7 @@ final class Average $count = \count($values); $middleval = (int) \floor(($count - 1) / 2); - if ($count % 2) { + if ($count % 2 !== 0) { $median = $values[$middleval]; } else { $low = $values[$middleval]; diff --git a/Math/Statistic/Basic.php b/Math/Statistic/Basic.php index 3d9c7e2b9..56bb293ee 100755 --- a/Math/Statistic/Basic.php +++ b/Math/Statistic/Basic.php @@ -55,11 +55,7 @@ final class Basic } foreach ($values as $value) { - if (\is_array($value)) { - $freaquency[] = self::frequency($value); - } else { - $freaquency[] = $value / $sum; - } + $freaquency[] = \is_array($value) ? self::frequency($value) : $value / $sum; } return $freaquency; diff --git a/Message/Cli/CliRequest.php b/Message/Cli/CliRequest.php index 5d0f249bf..d806d2c92 100755 --- a/Message/Cli/CliRequest.php +++ b/Message/Cli/CliRequest.php @@ -91,7 +91,7 @@ final class CliRequest extends RequestAbstract return $this->data; } - $key = '-' . \mb_strtolower($key); + $key = \mb_strtolower($key); switch ($type) { case 'int': @@ -106,18 +106,118 @@ final class CliRequest extends RequestAbstract case 'bool': /* @phpstan-ignore-next-line */ return (bool) ArrayUtils::getArg($key, $this->data); + case 'DateTime': + return new \DateTime((string) ArrayUtils::getArg($key, $this->data)); default: /* @phpstan-ignore-next-line */ return ArrayUtils::getArg($key, $this->data); } } + /** + * Get data. + * + * @param string $key Data key + * + * @return null|string + * + * @since 1.0.0 + */ + public function getDataString(string $key) : ?string + { + $key = \mb_strtolower($key); + + if (ArrayUtils::hasArg($key, $this->data) === -1) { + return null; + } + + return (string) ArrayUtils::getArg($key, $this->data); + } + + /** + * Get data. + * + * @param string $key Data key + * + * @return null|int + * + * @since 1.0.0 + */ + public function getDataInt(string $key) : ?int + { + $key = \mb_strtolower($key); + + if (ArrayUtils::hasArg($key, $this->data) === -1) { + return null; + } + + return (int) ArrayUtils::getArg($key, $this->data); + } + + /** + * Get data. + * + * @param string $key Data key + * + * @return null|float + * + * @since 1.0.0 + */ + public function getDataFloat(string $key) : ?float + { + $key = \mb_strtolower($key); + + if (ArrayUtils::hasArg($key, $this->data) === -1) { + return null; + } + + return (float) ArrayUtils::getArg($key, $this->data); + } + + /** + * Get data. + * + * @param string $key Data key + * + * @return null|bool + * + * @since 1.0.0 + */ + public function getDataBool(string $key) : ?bool + { + $key = \mb_strtolower($key); + + if (ArrayUtils::hasArg($key, $this->data) === -1) { + return null; + } + + return (bool) ArrayUtils::getArg($key, $this->data); + } + + /** + * Get data. + * + * @param string $key Data key + * + * @return null|\DateTime + * + * @since 1.0.0 + */ + public function getDataDateTime(string $key) : ?\DateTime + { + $key = \mb_strtolower($key); + + return empty($this->data[$key] ?? null) + ? null + : new \DateTime((string) ArrayUtils::getArg($key, $this->data)); + } + /** * {@inheritdoc} */ public function hasData(string $key) : bool { - $key = '-' . \mb_strtolower($key); + $key = \mb_strtolower($key); /* @phpstan-ignore-next-line */ return ArrayUtils::hasArg($key, $this->data) > -1; @@ -136,7 +236,7 @@ final class CliRequest extends RequestAbstract */ public function setData(string $key, mixed $value, bool $overwrite = false) : bool { - $key = '-' . \mb_strtolower($key); + $key = \mb_strtolower($key); $pos = -1; /* @phpstan-ignore-next-line */ diff --git a/Message/Http/HttpRequest.php b/Message/Http/HttpRequest.php index d9c112bc4..c571f27b6 100755 --- a/Message/Http/HttpRequest.php +++ b/Message/Http/HttpRequest.php @@ -267,11 +267,9 @@ final class HttpRequest extends RequestAbstract $lastLine = $lineRaw; } - if ($lastLine !== null) { - if (\fwrite($outFP, \rtrim($lastLine, "\r\n")) === false) { - $this->files[$name]['error'] = \UPLOAD_ERR_CANT_WRITE; - return; - } + if ($lastLine !== null && \fwrite($outFP, \rtrim($lastLine, "\r\n")) === false) { + $this->files[$name]['error'] = \UPLOAD_ERR_CANT_WRITE; + return; } \fclose($outFP); diff --git a/Message/Http/HttpResponse.php b/Message/Http/HttpResponse.php index 3139b418b..2995813ea 100755 --- a/Message/Http/HttpResponse.php +++ b/Message/Http/HttpResponse.php @@ -97,7 +97,7 @@ final class HttpResponse extends ResponseAbstract implements RenderableInterface { $json = \json_decode($this->getRaw(), true); - return !\is_array($json) ? [] : $json; + return \is_array($json) ? $json : []; } /** diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index d62c13f3b..a1fdc56ae 100755 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -183,8 +183,6 @@ final class Rest . $content . "\r\n"; } - $data .= '--' . $delim . "--\r\n"; - - return $data; + return $data . ('--' . $delim . "--\r\n"); } } diff --git a/Message/Mail/Email.php b/Message/Mail/Email.php index 73ecb33c2..4ea33530f 100755 --- a/Message/Mail/Email.php +++ b/Message/Mail/Email.php @@ -634,7 +634,7 @@ class Email implements MessageInterface $this->header = ''; $this->mailer = $mailer; - if (\count($this->to) + \count($this->cc) + \count($this->bcc) < 1) { + if (empty($this->to) && empty($this->cc) && empty($this->bcc)) { return false; } @@ -652,9 +652,9 @@ class Email implements MessageInterface $this->headerMime .= $tempheaders; if ($this->mailer === SubmitType::MAIL) { - $this->header .= \count($this->to) > 0 - ? $this->createAddressList('To', $this->to) - : 'Subject: undisclosed-recipients:;' . self::$LE; + $this->header .= empty($this->to) + ? 'Subject: undisclosed-recipients:;' . self::$LE + : $this->createAddressList('To', $this->to); $this->header .= 'Subject: ' . $this->encodeHeader(\trim(\str_replace(["\r", "\n"], '', $this->subject))) . self::$LE; } @@ -691,22 +691,21 @@ class Email implements MessageInterface */ private function createHeader() : string { - $result = ''; - $result .= 'Date : ' . ($this->messageDate === null + $result = 'Date : ' . ($this->messageDate === null ? (new \DateTime('now'))->format('D, j M Y H:i:s O') : $this->messageDate->format('D, j M Y H:i:s O')) . self::$LE; if ($this->mailer !== SubmitType::MAIL) { - $result .= \count($this->to) > 0 - ? $this->addrAppend('To', $this->to) - : 'To: undisclosed-recipients:;' . self::$LE; + $result .= empty($this->to) + ? 'To: undisclosed-recipients:;' . self::$LE + : $this->addrAppend('To', $this->to); } $result .= $this->addrAppend('From', [$this->from]); // sendmail and mail() extract Cc from the header before sending - if (\count($this->cc) > 0) { + if (!empty($this->cc)) { $result .= $this->addrAppend('Cc', $this->cc); } @@ -714,12 +713,12 @@ class Email implements MessageInterface if (($this->mailer === SubmitType::MAIL || $this->mailer === SubmitType::SENDMAIL || $this->mailer === SubmitType::QMAIL) - && \count($this->bcc) > 0 + && !empty($this->bcc) ) { $result .= $this->addrAppend('Bcc', $this->bcc); } - if (\count($this->replyTo) > 0) { + if (!empty($this->replyTo)) { $result .= $this->addrAppend('Reply-To', $this->replyTo); } @@ -1206,7 +1205,7 @@ class Email implements MessageInterface $bString = $attachment[5]; $string = $bString ? $attachment[0] : ''; - $path = !$bString ? $attachment[0] : ''; + $path = $bString ? '' : $attachment[0]; $inclHash = \hash('sha256', \serialize($attachment)); if (\in_array($inclHash, $incl, true)) { @@ -1228,16 +1227,16 @@ class Email implements MessageInterface $mime[] = \sprintf('--%s%s', $boundary, self::$LE); //Only include a filename property if we have one - $mime[] = !empty($name) - ? \sprintf('Content-Type: %s; name=%s%s', + $mime[] = empty($name) + ? \sprintf('Content-Type: %s%s', + $type, + self::$LE + ) + : \sprintf('Content-Type: %s; name=%s%s', $type, self::quotedString($this->encodeHeader(\trim(\str_replace(["\r", "\n"], '', $name)))), self::$LE - ) - : \sprintf('Content-Type: %s%s', - $type, - self::$LE - ); + ); // RFC1341 part 5 says 7bit is assumed if not specified if ($encoding !== EncodingType::E_7BIT) { @@ -1252,13 +1251,14 @@ class Email implements MessageInterface // Allow for bypassing the Content-Disposition header if (!empty($disposition)) { $encodedName = $this->encodeHeader(\trim(\str_replace(["\r", "\n"], '', $name))); - $mime[] = !empty($encodedName) - ? \sprintf('Content-Disposition: %s; filename=%s%s', + $mime[] = empty($encodedName) + ? \sprintf('Content-Disposition: %s%s', $disposition, self::$LE . self::$LE) + : \sprintf('Content-Disposition: %s; filename=%s%s', $disposition, self::quotedString($encodedName), self::$LE . self::$LE - ) - : \sprintf('Content-Disposition: %s%s', $disposition, self::$LE . self::$LE); + ) ; + } else { $mime[] = self::$LE; } @@ -1312,13 +1312,8 @@ class Email implements MessageInterface } $fileBuffer = \file_get_contents($path); - if ($fileBuffer === false) { - return ''; // @codeCoverageIgnore - } - $fileBuffer = $this->encodeString($fileBuffer, $encoding); - - return $fileBuffer; + return $fileBuffer === false ? '' : $this->encodeString($fileBuffer, $encoding); } /** @@ -2199,19 +2194,17 @@ class Email implements MessageInterface return ''; } - $privKeyStr = !empty($this->dkimPrivateKey) - ? $this->dkimPrivateKey - : \file_get_contents($this->dkimPrivatePath); + $privKeyStr = empty($this->dkimPrivateKey) + ? \file_get_contents($this->dkimPrivatePath) + : $this->dkimPrivateKey; - $privKey = $this->dkimPass !== '' - ? \openssl_pkey_get_private($privKeyStr, $this->dkimPass) - : \openssl_pkey_get_private($privKeyStr); + $privKey = $this->dkimPass === '' + ? \openssl_pkey_get_private($privKeyStr) + : \openssl_pkey_get_private($privKeyStr, $this->dkimPass); - if (\openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption')) { - return \base64_encode($signature); - } - - return ''; + return \openssl_sign($signHeader, $signature, $privKey, 'sha256WithRSAEncryption') + ? \base64_encode($signature) + : ''; } /** @@ -2361,7 +2354,7 @@ class Email implements MessageInterface } $copiedHeaderFields = ''; - if ($this->dkimCopyHeader && \count($copiedHeaders) > 0) { + if ($this->dkimCopyHeader && !empty($copiedHeaders)) { $copiedHeaderFields = ' z='; $first = true; diff --git a/Message/Mail/Imap.php b/Message/Mail/Imap.php index 9c175e772..199f80640 100755 --- a/Message/Mail/Imap.php +++ b/Message/Mail/Imap.php @@ -281,7 +281,7 @@ class Imap implements MailBoxInterface */ public function copyMail(string | array $messages, string $box) : bool { - return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . '}' . $box); + return \imap_mail_copy($this->mailbox, \is_string($messages) ? $messages : \implode(',', $messages), '{' . $this->host . ':' . $this->port . '}' . $box); } /** @@ -298,9 +298,9 @@ class Imap implements MailBoxInterface { return \imap_mail_copy( $this->mailbox, - !\is_string($messages) - ? \implode(',', $messages) - : $messages, '{' . $this->host . ':' . $this->port . '}' . $box + \is_string($messages) + ? $messages + : \implode(',', $messages), '{' . $this->host . ':' . $this->port . '}' . $box ); } diff --git a/Message/Mail/MailHandler.php b/Message/Mail/MailHandler.php index 5558f4873..f45268937 100755 --- a/Message/Mail/MailHandler.php +++ b/Message/Mail/MailHandler.php @@ -548,7 +548,7 @@ class MailHandler } if ($this->smtp->connect($prefix . $host, $port, $this->timeout, $options)) { - $hello = !empty($this->helo) ? $this->helo : SystemUtils::getHostname(); + $hello = empty($this->helo) ? SystemUtils::getHostname() : $this->helo; $this->smtp->hello($hello); diff --git a/Message/Mail/Pop3.php b/Message/Mail/Pop3.php index 3670e26be..7c220c250 100755 --- a/Message/Mail/Pop3.php +++ b/Message/Mail/Pop3.php @@ -277,7 +277,7 @@ class Pop3 implements MailBoxInterface */ public function copyMail(string | array $messages, string $box) : bool { - return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box); + return \imap_mail_copy($this->mailbox, \is_string($messages) ? $messages : \implode(',', $messages), '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box); } /** @@ -292,7 +292,7 @@ class Pop3 implements MailBoxInterface */ public function moveMail(string | array $messages, string $box) : bool { - return \imap_mail_copy($this->mailbox, !\is_string($messages) ? \implode(',', $messages) : $messages, '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box); + return \imap_mail_copy($this->mailbox, \is_string($messages) ? $messages : \implode(',', $messages), '{' . $this->host . ':' . $this->port . $this->flags . '}' . $box); } /** diff --git a/Message/Mail/Smtp.php b/Message/Mail/Smtp.php index 1d84830b9..2492a9889 100755 --- a/Message/Mail/Smtp.php +++ b/Message/Mail/Smtp.php @@ -543,7 +543,7 @@ class Smtp continue; } - if (!$n) { + if ($n === 0) { $name = $type; $fields = $fields[0]; } else { @@ -681,11 +681,7 @@ class Smtp $code = (int) \substr($this->lastReply, 0, 3); } - if (!\in_array($code, $expect, true)) { - return false; - } - - return true; + return \in_array($code, $expect, true); } /** diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 04b2c8499..fc9f1bb1c 100755 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -229,7 +229,9 @@ abstract class RequestAbstract implements MessageInterface { $key = \mb_strtolower($key); - return !empty($this->data[$key] ?? null) ? new \DateTime((string) $this->data[$key]) : null; + return empty($this->data[$key] ?? null) + ? null + : new \DateTime((string) $this->data[$key]); } /** @@ -251,7 +253,7 @@ abstract class RequestAbstract implements MessageInterface $json = \json_decode($this->data[$key], true); /** @phpstan-ignore-line */ - return !\is_array($json) ? [] : $json; + return \is_array($json) ? $json : []; } /** diff --git a/Model/Html/Head.php b/Model/Html/Head.php index 6396d3797..809e8fe8e 100755 --- a/Model/Html/Head.php +++ b/Model/Html/Head.php @@ -171,9 +171,8 @@ final class Head implements RenderableInterface $head .= $this->meta->render(); $head .= $this->renderAssets(); $head .= empty($this->style) ? '' : ''; - $head .= empty($this->script) ? '' : ''; - return $head; + return $head . (empty($this->script) ? '' : ''); } /** diff --git a/Model/Html/Meta.php b/Model/Html/Meta.php index ce99b11e6..8f42cbd44 100755 --- a/Model/Html/Meta.php +++ b/Model/Html/Meta.php @@ -229,10 +229,10 @@ final class Meta implements RenderableInterface */ public function render(mixed ...$data) : string { - return (\count($this->keywords) > 0 ? '' : '') - . (!empty($this->author) ? '' : '') - . (!empty($this->description) ? '' : '') - . (!empty($this->charset) ? '' : '') + return (empty($this->keywords) ? '' : '') + . (empty($this->author) ? '' : '') + . (empty($this->description) ? '' : '') + . (empty($this->charset) ? '' : '') . '' . $this->renderProperty() . $this->renderItemprop() diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index ca0e28bdc..3b10dd5a7 100755 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -384,7 +384,7 @@ final class ModuleManager $this->deactivateModule($info); return true; - } catch (\Exception $e) { + } catch (\Exception $_) { return false; // @codeCoverageIgnore } } @@ -436,7 +436,7 @@ final class ModuleManager $this->activateModule($info); return true; - } catch (\Exception $e) { + } catch (\Exception $_) { return false; // @codeCoverageIgnore } } @@ -714,14 +714,14 @@ final class ModuleManager $class = '\\Modules\\' . $module . '\\Controller\\' . ($ctlName ?? $this->app->appName) . 'Controller'; if (!isset($this->running[$class])) { - if (Autoloader::exists($class) !== false - || Autoloader::exists($class = '\\Modules\\' . $module . '\\Controller\\Controller') !== false + if (Autoloader::exists($class) + || Autoloader::exists($class = '\\Modules\\' . $module . '\\Controller\\Controller') ) { try { /** @var ModuleAbstract $obj */ $obj = new $class($this->app); $this->running[$class] = $obj; - } catch (\Throwable $e) { + } catch (\Throwable $_) { $this->running[$class] = new NullModule(); } } else { diff --git a/Module/PackageManager.php b/Module/PackageManager.php index cbc57af66..1a234678f 100755 --- a/Module/PackageManager.php +++ b/Module/PackageManager.php @@ -123,7 +123,7 @@ final class PackageManager $contents = \file_get_contents($this->extractPath . '/info.json'); $info = \json_decode($contents === false ? '[]' : $contents, true); - $this->info = !\is_array($info) ? [] : $info; + $this->info = \is_array($info) ? $info : []; } /** diff --git a/Security/Guard.php b/Security/Guard.php index 48ba8a577..fa3aac164 100755 --- a/Security/Guard.php +++ b/Security/Guard.php @@ -50,7 +50,10 @@ final class Guard */ public static function isSafePath(string $path, string $base = '') : bool { - return \stripos(FileUtils::absolute($path), FileUtils::absolute(empty($base) ? self::$BASE_PATH : $base)) === 0; + return \stripos( + FileUtils::absolute($path), + FileUtils::absolute(empty($base) ? self::$BASE_PATH : $base) + ) === 0; } /** @@ -69,11 +72,9 @@ final class Guard if (\is_array($data)) { $result = []; foreach ($data as $key => $value) { - if (\is_string($value) || \is_array($value)) { - $result[$key] = self::unslash($value); - } else { - $result[$key] = $value; - } + $result[$key] = \is_string($value) || \is_array($value) + ? self::unslash($value) + : $value; } return $result; diff --git a/Socket/Client/Client.php b/Socket/Client/Client.php index d5cdcd169..432265283 100755 --- a/Socket/Client/Client.php +++ b/Socket/Client/Client.php @@ -104,7 +104,7 @@ class Client extends SocketAbstract // socket_strerror(socket_last_error()); //} - if (\count($read) > 0) { + if (!empty($read)) { $data = \socket_read($this->sock, 1024); \var_dump($data); @@ -126,7 +126,7 @@ class Client extends SocketAbstract if ($errorCounter > 10) { $this->run = false; } - } catch (\Throwable $e) { + } catch (\Throwable $_) { $this->run = false; } } diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index be37c22c1..353df8cfe 100755 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -1206,8 +1206,7 @@ class Graph $node1 = \reset($this->nodes); $colors[$node1->getId()] = 1; - $stack = []; - \array_push($stack, $node1); + $stack = [$node1]; while (!empty($stack)) { $node = \array_pop($stack); @@ -1220,7 +1219,7 @@ class Graph if ($colors[$adj->getId()] === -1) { $colors[$adj->getId()] = 1 - $colors[$node->getId()]; - \array_push($stack, $adj); + $stack[] = $adj; } elseif ($colors[$adj->getId()] === $colors[$node->getId()]) { return false; } diff --git a/Stdlib/Graph/Node.php b/Stdlib/Graph/Node.php index 9a888b0d1..54b85154e 100755 --- a/Stdlib/Graph/Node.php +++ b/Stdlib/Graph/Node.php @@ -250,11 +250,9 @@ class Node foreach ($this->edges as $edge) { $nodes = $edge->getNodes(); - if ($nodes[0] !== null && !$this->isEqual($nodes[0])) { - $neighbors[] = $nodes[0]; - } else { - $neighbors[] = $nodes[1]; - } + $neighbors[] = $nodes[0] !== null && !$this->isEqual($nodes[0]) + ? $nodes[0] + : $nodes[1]; } return $neighbors; diff --git a/Stdlib/Queue/PriorityQueue.php b/Stdlib/Queue/PriorityQueue.php index 4bd4691de..a21dbb29c 100755 --- a/Stdlib/Queue/PriorityQueue.php +++ b/Stdlib/Queue/PriorityQueue.php @@ -87,7 +87,7 @@ class PriorityQueue implements \Countable, SerializableInterface $key = \mt_rand(); } while (isset($this->queue[$key])); - if (\count($this->queue) === 0) { + if (empty($this->queue)) { $this->queue[$key] = ['data' => $data, 'priority' => $priority]; } else { $pos = $this->getInsertPosition($priority); diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index 0f03913fd..686b6f4cf 100755 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -113,7 +113,7 @@ final class FileUtils */ public static function absolute(string $origPath) : string { - if (\file_exists($origPath) !== false) { + if (\file_exists($origPath)) { $path = \realpath($origPath); return $path === false ? '' : $path; diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 9cae09de5..e9759255f 100755 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -469,18 +469,14 @@ class Directory extends FileAbstract implements DirectoryInterface $download = self::get($con, $from, $tempName . '/' . self::name($from)); if (!$download) { - if ($status !== false) { - LocalDirectory::delete($tempName); - } + LocalDirectory::delete($tempName); return false; } $upload = self::put($con, $tempName . '/' . self::name($from), $to); if (!$upload) { - if ($status !== false) { - LocalDirectory::delete($tempName); - } + LocalDirectory::delete($tempName); return false; } diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index 248aa3dd4..b8e503d98 100755 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -137,13 +137,11 @@ class File extends FileAbstract implements FileInterface || (!$exists && ContentPutMode::hasFlag($mode, ContentPutMode::CREATE)) ) { if (ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) { - $content = self::get($con, $path) . $content; + $content .= self::get($con, $path); } elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) { $content = $content . self::get($con, $path); - } else { - if (!Directory::exists($con, \dirname($path))) { - Directory::create($con, \dirname($path), 0755, true); - } + } elseif (!Directory::exists($con, \dirname($path))) { + Directory::create($con, \dirname($path), 0755, true); } $fp = \fopen('php://memory', 'r+'); diff --git a/System/File/Local/File.php b/System/File/Local/File.php index ef20f2278..0058cb87a 100755 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -93,7 +93,7 @@ final class File extends FileAbstract implements FileInterface return true; } - } catch (\Throwable $e) { + } catch (\Throwable $_) { return false; // @codeCoverageIgnore } diff --git a/UnhandledHandler.php b/UnhandledHandler.php index 41497cc10..da66cda2e 100755 --- a/UnhandledHandler.php +++ b/UnhandledHandler.php @@ -64,7 +64,7 @@ final class UnhandledHandler { $logger = FileLogger::getInstance(__DIR__ . '/../Logs'); - if (!(\error_reporting() & $errno)) { + if ((\error_reporting() & $errno) === 0) { \error_clear_last(); $_SERVER = []; diff --git a/Uri/Argument.php b/Uri/Argument.php index d3493c710..9621ef44e 100755 --- a/Uri/Argument.php +++ b/Uri/Argument.php @@ -172,7 +172,7 @@ final class Argument implements UriInterface // Handle no path information only data $uriParts = \stripos($uriParts[0], '-') === 0 ? ['/', $uriParts[0]] : $uriParts; - $this->path = \count($uriParts) === 0 ? '' : \array_shift($uriParts); + $this->path = empty($uriParts) ? '' : \array_shift($uriParts); $this->pathElements = \explode('/', \ltrim($this->path, '/')); $path = \array_slice($this->pathElements, $this->pathOffset); @@ -297,7 +297,7 @@ final class Argument implements UriInterface $path = $ignoreOffset ? $this->path : $this->offsetPath; $query = $this->getQuery(); - return $path . (!empty($query) ? ' ' . $this->getQuery() : ''); + return $path . (empty($query) ? '' : ' ' . $this->getQuery()); } /** diff --git a/Uri/HttpUri.php b/Uri/HttpUri.php index d4f904606..380034109 100755 --- a/Uri/HttpUri.php +++ b/Uri/HttpUri.php @@ -354,7 +354,7 @@ final class HttpUri implements UriInterface $path = $ignoreOffset ? $this->path : $this->offsetPath; $query = $this->getQuery(); - return $path . (!empty($query) ? '?' . $this->getQuery() : ''); + return $path . (empty($query) ? '' : '?' . $this->getQuery()); } /** diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index e5ce8ebe3..51605ab7f 100755 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -330,6 +330,7 @@ final class ArrayUtils */ public static function hasArg(string $id, array $args) : int { + $t = \array_search($id, $args); return ($key = \array_search($id, $args)) === false ? -1 : (int) $key; diff --git a/Utils/Barcode/BarAbstract.php b/Utils/Barcode/BarAbstract.php index fbe14cf16..c6fbaf10e 100755 --- a/Utils/Barcode/BarAbstract.php +++ b/Utils/Barcode/BarAbstract.php @@ -202,7 +202,7 @@ abstract class BarAbstract extends CodeAbstract $length = \strlen($codeString); for ($i = 1; $i <= $length; ++$i) { - $codeLength = $codeLength + (int) (\substr($codeString, ($i - 1), 1)); + $codeLength += (int) (\substr($codeString, ($i - 1), 1)); } return $codeLength; diff --git a/Utils/Barcode/C128c.php b/Utils/Barcode/C128c.php index 0882d66f6..b0c45b737 100755 --- a/Utils/Barcode/C128c.php +++ b/Utils/Barcode/C128c.php @@ -92,19 +92,15 @@ class C128c extends BarAbstract $checkPos = 1; for ($pos = 1; $pos <= $length; $pos += 2) { - if ($pos + 1 <= $length) { - $activeKey = \substr($this->content, ($pos - 1), 2); - } else { - $activeKey = \substr($this->content, ($pos - 1), 1) . '0'; - } + $activeKey = $pos + 1 <= $length + ? \substr($this->content, ($pos - 1), 2) + : \substr($this->content, ($pos - 1), 1) . '0'; $codeString .= self::$CODEARRAY[$activeKey]; $checksum += $values[$activeKey] * $checkPos; ++$checkPos; } - $codeString .= self::$CODEARRAY[$keys[($checksum - ((int) ($checksum / 103) * 103))]]; - - return $codeString; + return $codeString . self::$CODEARRAY[$keys[($checksum - ((int) ($checksum / 103) * 103))]]; } } diff --git a/Utils/Barcode/C25.php b/Utils/Barcode/C25.php index 00f67a120..62c5ab67f 100755 --- a/Utils/Barcode/C25.php +++ b/Utils/Barcode/C25.php @@ -94,7 +94,7 @@ class C25 extends BarAbstract for ($posX = 1; $posX <= $length; ++$posX) { for ($posY = 0; $posY < $arrayLength; ++$posY) { - if (\substr($this->content, ($posX - 1), 1) == self::$CODEARRAY[$posY]) { + if (\substr($this->content, ($posX - 1), 1) === self::$CODEARRAY[$posY]) { $temp[$posX] = self::$CODEARRAY2[$posY]; } } diff --git a/Utils/Barcode/Codebar.php b/Utils/Barcode/Codebar.php index 36ee90ca3..5e3d63970 100755 --- a/Utils/Barcode/Codebar.php +++ b/Utils/Barcode/Codebar.php @@ -81,7 +81,7 @@ class Codebar extends BarAbstract for ($posX = 1; $posX <= $length; ++$posX) { for ($posY = 0; $posY < $lenCodearr; ++$posY) { - if (\substr($this->content, ($posX - 1), 1) == self::$CODEARRAY[$posY]) { + if (\substr($this->content, ($posX - 1), 1) === self::$CODEARRAY[$posY]) { $codeString .= self::$CODEARRAY2[$posY] . '1'; } } diff --git a/Utils/Barcode/Datamatrix.php b/Utils/Barcode/Datamatrix.php index 65271914f..b4f039276 100755 --- a/Utils/Barcode/Datamatrix.php +++ b/Utils/Barcode/Datamatrix.php @@ -214,11 +214,7 @@ class Datamatrix extends TwoDAbstract // braw bits by case if ($r === 0) { // top finder pattern - if ($c % 2) { - $this->codearray[$row][$col] = false; - } else { - $this->codearray[$row][$col] = true; - } + $this->codearray[$row][$col] = $c % 2 === 0; } elseif ($r === $rdri) { // bottom finder pattern $this->codearray[$row][$col] = true; @@ -227,11 +223,7 @@ class Datamatrix extends TwoDAbstract $this->codearray[$row][$col] = true; } elseif ($c === $rdci) { // right finder pattern - if ($r % 2) { - $this->codearray[$row][$col] = true; - } else { - $this->codearray[$row][$col] = false; - } + $this->codearray[$row][$col] = $r % 2; } else { // data bit if ($places[$i] < 2) { $this->codearray[$row][$col] = (bool) $places[$i]; @@ -240,7 +232,7 @@ class Datamatrix extends TwoDAbstract $cw_id = (\floor($places[$i] / 10) - 1); // codeword BIT mask $cw_bit = \pow(2, (8 - ($places[$i] % 10))); - $this->codearray[$row][$col] = (($cw[$cw_id] & $cw_bit) === 0) ? false : true; + $this->codearray[$row][$col] = ($cw[$cw_id] & $cw_bit) !== 0; } ++$i; @@ -701,7 +693,7 @@ class Datamatrix extends TwoDAbstract && $this->isCharMode(\ord($data[$pos + 1]), self::ENC_ASCII_NUM)) ) { // 1. If the next data sequence is at least 2 consecutive digits, encode the next two digits as a double digit in ASCII mode. - $cw[] = (intval(substr($data, $pos, 2)) + 130); + $cw[] = ((int) substr($data, $pos, 2) + 130); ++$cw_num; $pos += 2; } else { @@ -750,12 +742,12 @@ class Datamatrix extends TwoDAbstract ++$epos; // check for extended character - if ($chr & 0x80) { + if (($chr & 0x80) !== 0) { if ($enc === self::ENC_X12) { return []; } - $chr = ($chr & 0x7f); + $chr &= 0x7f; $temp_cw[] = 1; // shift 2 $temp_cw[] = 30; // upper shift $p += 2; @@ -855,17 +847,15 @@ class Datamatrix extends TwoDAbstract $pos = $epos; $enc = self::ENC_ASCII; $this->encoding = $enc; - } else { + } elseif ($enc !== self::ENC_ASCII) { // switch to ASCII encoding - if ($enc !== self::ENC_ASCII) { - $enc = self::ENC_ASCII; - $this->encoding = $enc; - $cw[] = $this->getSwitchEncodingCodeword($enc); + $enc = self::ENC_ASCII; + $this->encoding = $enc; + $cw[] = $this->getSwitchEncodingCodeword($enc); - ++$cw_num; + ++$cw_num; - $pos = ($epos - $p); - } + $pos = ($epos - $p); } } break; @@ -1023,9 +1013,8 @@ class Datamatrix extends TwoDAbstract $marr = $this->placeModule($marr, $nrow, $ncol, $row - 1, $col, $chr, 5); $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col - 2, $chr, 6); $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col - 1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, $row, $col, $chr, 8); - return $marr; + return $this->placeModule($marr, $nrow, $ncol, $row, $col, $chr, 8); } /** @@ -1040,9 +1029,8 @@ class Datamatrix extends TwoDAbstract $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol - 1, $chr, 5); $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 1, $chr, 6); $marr = $this->placeModule($marr, $nrow, $ncol, 2, $ncol - 1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 3, $ncol - 1, $chr, 8); - return $marr; + return $this->placeModule($marr, $nrow, $ncol, 3, $ncol - 1, $chr, 8); } /** @@ -1057,9 +1045,8 @@ class Datamatrix extends TwoDAbstract $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol - 3, $chr, 5); $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol - 2, $chr, 6); $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol - 1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 1, $chr, 8); - return $marr; + return $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 1, $chr, 8); } /** @@ -1074,9 +1061,8 @@ class Datamatrix extends TwoDAbstract $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol - 1, $chr, 5); $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 1, $chr, 6); $marr = $this->placeModule($marr, $nrow, $ncol, 2, $ncol - 1, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 3, $ncol - 1, $chr, 8); - return $marr; + return $this->placeModule($marr, $nrow, $ncol, 3, $ncol - 1, $chr, 8); } /** @@ -1091,9 +1077,8 @@ class Datamatrix extends TwoDAbstract $marr = $this->placeModule($marr, $nrow, $ncol, 0, $ncol - 1, $chr, 5); $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 3, $chr, 6); $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 2, $chr, 7); - $marr = $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 1, $chr, 8); - return $marr; + return $this->placeModule($marr, $nrow, $ncol, 1, $ncol - 1, $chr, 8); } /** diff --git a/Utils/Barcode/QR.php b/Utils/Barcode/QR.php index 77e1a3df0..6ddd7ebe5 100755 --- a/Utils/Barcode/QR.php +++ b/Utils/Barcode/QR.php @@ -540,7 +540,7 @@ class QR extends TwoDAbstract foreach ($frame as $row => $cols) { $len = \strlen($cols); for ($i = 0; $i < $len; ++$i) { - $bin[$row][$i] = \ord($frame[$row][$i]) & 1 ? true : false; + $bin[$row][$i] = \ord($frame[$row][$i]) & 1; } } @@ -613,7 +613,7 @@ class QR extends TwoDAbstract for ($j = 0; $j < 8; ++$j) { $addr = $this->getNextPosition(); $this->frame[$addr['y']][$addr['x']] = 0x02 | (($bit & $code) !== 0); - $bit = $bit >> 1; + $bit >>= 1; } } @@ -694,16 +694,14 @@ class QR extends TwoDAbstract $y = 9; } } - } else { - if ($y === $w) { - $y = $w - 1; - $x -= 2; - $this->dir = -1; + } elseif ($y === $w) { + $y = $w - 1; + $x -= 2; + $this->dir = -1; - if ($x === 6) { - --$x; - $y -= 8; - } + if ($x === 6) { + --$x; + $y -= 8; } } @@ -830,7 +828,7 @@ class QR extends TwoDAbstract : self::FORMAT_INFO[$level][$mask]; for ($i = 0; $i < 8; ++$i) { - if ($format & 1) { + if (($format & 1) !== 0) { $blacks += 2; $v = 0x85; } else { @@ -844,11 +842,11 @@ class QR extends TwoDAbstract $frame[$i + 1][8] = \chr($v); } - $format = $format >> 1; + $format >>= 1; } for ($i = 0; $i < 7; ++$i) { - if ($format & 1) { + if (($format & 1) !== 0) { $blacks += 2; $v = 0x85; } else { @@ -862,7 +860,7 @@ class QR extends TwoDAbstract $frame[8][6 - $i] = \chr($v); } - $format = $format >> 1; + $format >>= 1; } return $blacks; @@ -880,7 +878,7 @@ class QR extends TwoDAbstract $bitMask = \array_fill(0, $width, \array_fill(0, $width, 0)); for ($y = 0; $y < $width; ++$y) { for ($x = 0; $x < $width; ++$x) { - if (\ord($frame[$y][$x]) & 0x80) { + if ((\ord($frame[$y][$x]) & 0x80) !== 0) { $bitMask[$y][$x] = 0; } else { $maskFunc = 0; @@ -981,20 +979,20 @@ class QR extends TwoDAbstract $demerit += (self::N1 + ($this->runLength[$i] - 5)); } - if ($i & 1) { - if (($i >= 3) && ($i < ($length - 2)) && ($this->runLength[$i] % 3 === 0)) { - $fact = (int) ($this->runLength[$i] / 3); + if (($i & 1) !== 0 && (($i >= 3) + && ($i < ($length - 2)) && ($this->runLength[$i] % 3 === 0)) + ) { + $fact = (int) ($this->runLength[$i] / 3); - if (($this->runLength[$i - 2] === $fact) - && ($this->runLength[$i - 1] === $fact) - && ($this->runLength[$i + 1] === $fact) - && ($this->runLength[$i + 2] === $fact) - ) { - if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) { - $demerit += self::N3; - } elseif (($i + 3) >= $length || $this->runLength[$i + 3] >= (4 * $fact)) { - $demerit += self::N3; - } + if (($this->runLength[$i - 2] === $fact) + && ($this->runLength[$i - 1] === $fact) + && ($this->runLength[$i + 1] === $fact) + && ($this->runLength[$i + 2] === $fact) + ) { + if (($this->runLength[$i - 3] < 0) || ($this->runLength[$i - 3] >= (4 * $fact))) { + $demerit += self::N3; + } elseif (($i + 3) >= $length || $this->runLength[$i + 3] >= (4 * $fact)) { + $demerit += self::N3; } } } @@ -1029,7 +1027,7 @@ class QR extends TwoDAbstract $b22 = \ord($frameY[$x]) & \ord($frameY[$x - 1]) & \ord($frameYM[$x]) & \ord($frameYM[$x - 1]); $w22 = \ord($frameY[$x]) | \ord($frameY[$x - 1]) | \ord($frameYM[$x]) | \ord($frameYM[$x - 1]); - if (($b22 | ($w22 ^ 1)) & 1) { + if ((($b22 | ($w22 ^ 1)) & 1) !== 0) { $demerit += self::N2; } } @@ -1039,7 +1037,7 @@ class QR extends TwoDAbstract $head = 1; $this->runLength[$head] = 1; } elseif ($x > 0) { - if ((\ord($frameY[$x]) ^ \ord($frameY[$x - 1])) & 1) { + if (((\ord($frameY[$x]) ^ \ord($frameY[$x - 1])) & 1) !== 0) { ++$head; $this->runLength[$head] = 1; } else { @@ -1061,7 +1059,7 @@ class QR extends TwoDAbstract $head = 1; $this->runLength[$head] = 1; } elseif ($y > 0) { - if ((\ord($frame[$y][$x]) ^ \ord($frame[$y - 1][$x])) & 1) { + if (((\ord($frame[$y][$x]) ^ \ord($frame[$y - 1][$x])) & 1) !== 0) { ++$head; $this->runLength[$head] = 1; } else { @@ -1292,9 +1290,8 @@ class QR extends TwoDAbstract } $this->items = $this->appendNewInputItem($this->items, self::QR_MODE_KJ, $p, \str_split($this->dataStr)); - $run = $p; - return $run; + return $p; } /** @@ -1517,7 +1514,7 @@ class QR extends TwoDAbstract $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val); } - if ($inputitem['size'] & 1) { + if (($inputitem['size'] & 1) !== 0) { $val = $this->lookAnTable(\ord($inputitem['data'][($words * 2)])); $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val); @@ -1785,7 +1782,7 @@ class QR extends TwoDAbstract protected function estimateBitsModeAn(int $size) : int { $bits = (int) ($size * 5.5); // (size / 2 ) * 11 - if ($size & 1) { + if (($size & 1) !== 0) { $bits += 6; } @@ -1825,7 +1822,7 @@ class QR extends TwoDAbstract */ protected function checkModeKanji(int $size, array $data) : bool { - if ($size & 1) { + if (($size & 1) !== 0) { return false; } @@ -2085,7 +2082,7 @@ class QR extends TwoDAbstract $padbuf = []; for ($i = 0; $i < $padlen; ++$i) { - $padbuf[$i] = ($i & 1) ? 0x11 : 0xec; + $padbuf[$i] = (($i & 1) !== 0) ? 0x11 : 0xec; } $padding = $this->appendBytes($padding, $padlen, $padbuf); @@ -2169,8 +2166,8 @@ class QR extends TwoDAbstract $mask = 1 << ($bits - 1); for ($i = 0; $i < $bits; ++$i) { - $bstream[$i] = ($num & $mask) ? 1 : 0; - $mask = $mask >> 1; + $bstream[$i] = (($num & $mask) !== 0) ? 1 : 0; + $mask >>= 1; } return $bstream; @@ -2192,8 +2189,8 @@ class QR extends TwoDAbstract $mask = 0x80; for ($j = 0; $j < 8; ++$j) { - $bstream[$p] = ($data[$i] & $mask) ? 1 : 0; - $mask = $mask >> 1; + $bstream[$p] = (($data[$i] & $mask) !== 0) ? 1 : 0; + $mask >>= 1; ++$p; } @@ -2280,7 +2277,7 @@ class QR extends TwoDAbstract $v = 0; for ($j = 0; $j < 8; ++$j) { - $v = $v << 1; + $v <<= 1; $v |= $bstream[$p]; ++$p; } @@ -2288,11 +2285,11 @@ class QR extends TwoDAbstract $data[$i] = $v; } - if ($size & 7) { + if (($size & 7) !== 0) { $v = 0; for ($j = 0; $j < ($size & 7); ++$j) { - $v = $v << 1; + $v <<= 1; $v |= $bstream[$p]; ++$p; } @@ -2470,11 +2467,10 @@ class QR extends TwoDAbstract : (int) (($width - self::ALIGNMENT_PATTERN[$version][0]) / $d + 2); if ($w * $w - 3 === 1) { - $x = self::ALIGNMENT_PATTERN[$version][0]; - $y = self::ALIGNMENT_PATTERN[$version][0]; - $frame = $this->putAlignmentMarker($frame, $x, $y); + $x = self::ALIGNMENT_PATTERN[$version][0]; + $y = self::ALIGNMENT_PATTERN[$version][0]; - return $frame; + return $this->putAlignmentMarker($frame, $x, $y); } $cx = self::ALIGNMENT_PATTERN[$version][0]; @@ -2583,7 +2579,7 @@ class QR extends TwoDAbstract for ($x = 0; $x<6; ++$x) { for ($y = 0; $y<3; ++$y) { $frame[($width - 11)+$y][$x] = \chr(0x88 | ($v & 1)); - $v = $v >> 1; + $v >>= 1; } } @@ -2591,7 +2587,7 @@ class QR extends TwoDAbstract for ($y = 0; $y < 6; ++$y) { for ($x = 0; $x < 3; ++$x) { $frame[$y][$x + ($width - 11)] = \chr(0x88 | ($v & 1)); - $v = $v >> 1; + $v >>= 1; } } } @@ -2709,7 +2705,7 @@ class QR extends TwoDAbstract $rs['alpha_to'][$i] = $sr; $sr <<= 1; - if ($sr & (1 << $symsize)) { + if (($sr & (1 << $symsize)) !== 0) { $sr ^= $gfpoly; } diff --git a/Utils/Compression/LZW.php b/Utils/Compression/LZW.php index eafebc634..619ddbb93 100755 --- a/Utils/Compression/LZW.php +++ b/Utils/Compression/LZW.php @@ -44,7 +44,7 @@ class LZW implements CompressionInterface $wc = $w . $c; if (\array_key_exists($w . $c, $dictionary)) { - $w = $w . $c; + $w .= $c; } else { $result[] = $dictionary[$w]; $dictionary[$wc] = $dictSize++; @@ -69,7 +69,7 @@ class LZW implements CompressionInterface $entry = ''; $dictSize = 256; - if ($compressed === [] || $compressed === [''] || $compressed === false) { + if (empty($compressed) || $compressed === ['']) { return ''; } diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php index b10292d7b..ffb231bb0 100755 --- a/Utils/Git/Repository.php +++ b/Utils/Git/Repository.php @@ -833,11 +833,7 @@ class Repository $end = new \DateTime('now'); } - if ($author === null) { - $author = ''; - } else { - $author = ' --author=' . \escapeshellarg($author->name) . ''; - } + $author = $author === null ? '' : ' --author=' . \escapeshellarg($author->name) . ''; $lines = $this->run( 'git log --before="' . $end->format('Y-m-d') @@ -890,11 +886,7 @@ class Repository } $author = \explode(':', $lines[1] ?? ''); - if (\count($author) < 2) { - $author = ['none', 'none']; - } else { - $author = \explode('<', \trim($author[1] ?? '')); - } + $author = \count($author) < 2 ? ['none', 'none'] : \explode('<', \trim($author[1] ?? '')); $date = \substr($lines[2] ?? '', 6); if ($date === false) { diff --git a/Utils/ImageUtils.php b/Utils/ImageUtils.php index 362a7ef54..b90b30bd5 100755 --- a/Utils/ImageUtils.php +++ b/Utils/ImageUtils.php @@ -130,12 +130,10 @@ final class ImageUtils } else { $imageDim[1] = (int) \ceil($imageDim[1] - ($imageDim[1] * \abs($ratio - $width / $height))); } + } elseif ($width / $height > $ratio) { + $width = (int) ($height * $ratio); } else { - if ($width / $height > $ratio) { - $width = (int) ($height * $ratio); - } else { - $height = (int) ($width / $ratio); - } + $height = (int) ($width / $ratio); } $src = null; diff --git a/Utils/NumericUtils.php b/Utils/NumericUtils.php index d88d506c8..a134ec9ef 100755 --- a/Utils/NumericUtils.php +++ b/Utils/NumericUtils.php @@ -48,7 +48,7 @@ final class NumericUtils { if ($b >= 32 || $b < -32) { $m = (int) ($b / 32); - $b = $b - ($m * 32); + $b -= $m * 32; } if ($b < 0) { @@ -60,12 +60,12 @@ final class NumericUtils } if ($a < 0) { - $a = ($a >> 1); + $a >>= 1; $a &= 0x7fffffff; $a |= 0x40000000; - $a = ($a >> ($b - 1)); + $a >>= $b - 1; } else { - $a = ($a >> $b); + $a >>= $b; } return $a; diff --git a/Utils/Parser/Pdf/PdfParser.php b/Utils/Parser/Pdf/PdfParser.php index c82876938..ac53d61ac 100755 --- a/Utils/Parser/Pdf/PdfParser.php +++ b/Utils/Parser/Pdf/PdfParser.php @@ -64,11 +64,17 @@ class PdfParser } if (\is_file(self::$pdftotext)) { - SystemUtils::runProc( - self::$pdftotext, '-layout ' - . \escapeshellarg($path) . ' ' - . \escapeshellarg($out) - ); + try { + SystemUtils::runProc( + self::$pdftotext, '-layout ' + . \escapeshellarg($path) . ' ' + . \escapeshellarg($out) + ); + } catch (\Throwable $_) { + \unlink($out); + + return ''; + } } $text = \file_get_contents($out); @@ -78,58 +84,72 @@ class PdfParser $text = ''; } - if (\strlen($text) < 256) { - $out = \tempnam($tmpDir, 'oms_pdf_'); - if ($out === false) { - return ''; - } + if (\strlen($text) > 255) { + return $text; + } - if (\is_file(self::$pdftoppm)) { + $out = \tempnam($tmpDir, 'oms_pdf_'); + if ($out === false) { + return ''; + } + + if (\is_file(self::$pdftoppm)) { + try { SystemUtils::runProc( self::$pdftoppm, '-jpeg -r 300 ' . \escapeshellarg($path) . ' ' . \escapeshellarg($out) ); - } - - $files = \glob($out . '*'); - if ($files === false) { + } catch (\Throwable $_) { \unlink($out); - return $text === false ? '' : $text; + return ''; + } + } + + $files = \glob($out . '*'); + if ($files === false) { + \unlink($out); + + return $text === false ? '' : $text; + } + + foreach ($files as $file) { + if (!StringUtils::endsWith($file, '.jpg') + && !StringUtils::endsWith($file, '.png') + && !StringUtils::endsWith($file, '.gif') + ) { + continue; } - foreach ($files as $file) { - if (!StringUtils::endsWith($file, '.jpg') - && !StringUtils::endsWith($file, '.png') - && !StringUtils::endsWith($file, '.gif') - ) { - continue; - } + /* Too slow + Thresholding::integralThresholding($file, $file); + Skew::autoRotate($file, $file, 10); + */ - /* Too slow - Thresholding::integralThresholding($file, $file); - Skew::autoRotate($file, $file, 10); - */ - - if (!empty($optimizer) && \is_file($optimizer)) { + if (!empty($optimizer) && \is_file($optimizer)) { + try { SystemUtils::runProc( $optimizer, \escapeshellarg($file) . ' ' . \escapeshellarg($file) ); + } catch (\Throwable $_) { + \unlink($file); + + continue; } - - $ocr = new TesseractOcr(); - $text = $ocr->parseImage($file); - - \unlink($file); } - \unlink($out); + $ocr = new TesseractOcr(); + $text = $ocr->parseImage($file); + + \unlink($file); } + \unlink($out); + return $text; } } diff --git a/Utils/Parser/Presentation/PresentationWriter.php b/Utils/Parser/Presentation/PresentationWriter.php index 0ecd1171f..5f2074d65 100755 --- a/Utils/Parser/Presentation/PresentationWriter.php +++ b/Utils/Parser/Presentation/PresentationWriter.php @@ -15,11 +15,8 @@ declare(strict_types=1); namespace phpOMS\Utils\Parser\Presentation; use PhpOffice\PhpPresentation\AbstractShape; -use PhpOffice\PhpPresentation\Autoloader; use PhpOffice\PhpPresentation\DocumentLayout; -use PhpOffice\PhpPresentation\IOFactory; use PhpOffice\PhpPresentation\PhpPresentation; -use PhpOffice\PhpPresentation\Shape\Drawing; use PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter; use PhpOffice\PhpPresentation\Shape\Drawing\Base64; use PhpOffice\PhpPresentation\Shape\Drawing\File; @@ -29,13 +26,10 @@ use PhpOffice\PhpPresentation\Shape\Group; use PhpOffice\PhpPresentation\Shape\RichText; use PhpOffice\PhpPresentation\Shape\RichText\BreakElement; use PhpOffice\PhpPresentation\Shape\RichText\TextElement; -use PhpOffice\PhpPresentation\Slide; use PhpOffice\PhpPresentation\Slide\AbstractBackground; use PhpOffice\PhpPresentation\Slide\Background\Color as BackgroundColor; use PhpOffice\PhpPresentation\Slide\Background\Image; -use PhpOffice\PhpPresentation\Style\Alignment; use PhpOffice\PhpPresentation\Style\Bullet; -use PhpOffice\PhpPresentation\Style\Color; /** * Presentation parser class. @@ -377,11 +371,9 @@ class PresentationWriter $this->append('SuperScript : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N')); $this->append(''); - if ($oRichText instanceof TextElement) { - if ($oRichText->hasHyperlink()) { - $this->append('
Hyperlink URL
' . $oRichText->getHyperlink()->getUrl() . '
'); - $this->append('
Hyperlink Tooltip
' . $oRichText->getHyperlink()->getTooltip() . '
'); - } + if ($oRichText instanceof TextElement && $oRichText->hasHyperlink()) { + $this->append('
Hyperlink URL
' . $oRichText->getHyperlink()->getUrl() . '
'); + $this->append('
Hyperlink Tooltip
' . $oRichText->getHyperlink()->getTooltip() . '
'); } $this->append(''); diff --git a/Utils/RnG/Text.php b/Utils/RnG/Text.php index 6317f7658..45fe3577f 100755 --- a/Utils/RnG/Text.php +++ b/Utils/RnG/Text.php @@ -134,17 +134,10 @@ class Text $wordCount = \count($words); for ($i = 0; $i < $length + 1; ++$i) { - $newSentence = false; - $lastChar = \substr($text, -1); + $word = $words[\mt_rand(0, $wordCount - 1)] ?? ''; if ($lastChar === '.' || $lastChar === '!' || $lastChar === '?' || !$lastChar) { - $newSentence = true; - } - - $word = $words[\mt_rand(0, $wordCount - 1)] ?? ''; - - if ($newSentence) { $word = \ucfirst($word); ++$sentenceCount; @@ -171,11 +164,7 @@ class Text $text = \ltrim($text); - if ($this->hasParagraphs) { - $text = '

' . $text . '

'; - } - - return $text; + return $this->hasParagraphs ? '

' . $text . '

' : $text; } /** @@ -206,16 +195,13 @@ class Text } /* Handle comma */ - $commaHere = (\mt_rand(0, 100) <= $probComma * 100 && $sentenceLength >= 2 * $minCommaSpacing ? true : false); $posComma = []; - if ($commaHere) { + if (\mt_rand(0, 100) <= $probComma * 100 && $sentenceLength >= 2 * $minCommaSpacing) { $posComma[] = \mt_rand($minCommaSpacing, $sentenceLength - $minCommaSpacing); $punctuation[] = [$i + $posComma[0], ',']; - $commaHere = (\mt_rand(0, 100) <= $probComma * 100 && $sentenceLength > $posComma[0] + $minCommaSpacing * 2 ? true : false); - - if ($commaHere) { + if (\mt_rand(0, 100) <= $probComma * 100 && $sentenceLength > $posComma[0] + $minCommaSpacing * 2) { $posComma[] = \mt_rand($posComma[0] + $minCommaSpacing, $sentenceLength - $minCommaSpacing); $punctuation[] = [$i + $posComma[1], ',']; } @@ -224,16 +210,12 @@ class Text $i += $sentenceLength; /* Handle sentence ending */ - $isDot = (\mt_rand(0, 100) <= $probDot * 100 ? true : false); - - if ($isDot) { + if (\mt_rand(0, 100) <= $probDot * 100) { $punctuation[] = [$i, '.']; continue; } - $isEx = (\mt_rand(0, 100) <= $probExc * 100 ? true : false); - - if ($isEx) { + if (\mt_rand(0, 100) <= $probExc * 100) { $punctuation[] = [$i, '!']; continue; } @@ -292,19 +274,15 @@ class Text $formatting = []; for ($i = 0; $i < $length; ++$i) { - $isCursive = (\mt_rand(0, 1000) <= 1000 * $probCursive ? true : false); - $isBold = (\mt_rand(0, 1000) <= 1000 * $probBold ? true : false); - $isUline = (\mt_rand(0, 1000) <= 1000 * $probUline ? true : false); - - if ($isUline) { + if (\mt_rand(0, 1000) <= 1000 * $probUline) { $formatting[$i] = 'u'; } - if ($isBold) { + if (\mt_rand(0, 1000) <= 1000 * $probBold) { $formatting[$i] = 'b'; } - if ($isCursive) { + if (\mt_rand(0, 1000) <= 1000 * $probCursive) { $formatting[$i] = 'i'; } } diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index 881c1513c..680371afd 100755 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -239,8 +239,8 @@ final class StringUtils */ public static function createDiffMarkup(string $old, string $new, string $delim = '') : string { - $splitOld = !empty($delim) ? \explode($delim, $old) : \str_split($old); - $splitNew = !empty($delim) ? \explode($delim, $new) : \str_split($new); + $splitOld = empty($delim) ? \str_split($old) : \explode($delim, $old); + $splitNew = empty($delim) ? \str_split($new) : \explode($delim, $new); if ($splitOld === false || (empty($old) && !empty($new)) @@ -398,10 +398,10 @@ final class StringUtils * * @since 1.0.0 */ - public static function isShellSafe(string $string) + public static function isShellSafe(string $string) : bool { if (\escapeshellcmd($string) !== $string - || !\in_array(\escapeshellarg($string), ["'${string}'", "\"${string}\""]) + || !\in_array(\escapeshellarg($string), ["'{$string}'", "\"{$string}\""]) ) { return false; } diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php index 639d03a70..debb65257 100755 --- a/Utils/TaskSchedule/CronJob.php +++ b/Utils/TaskSchedule/CronJob.php @@ -40,8 +40,7 @@ class CronJob extends TaskAbstract public static function createWith(array $jobData) : TaskAbstract { $interval = \array_splice($jobData, 1, 5); - $job = new self($jobData[0], $jobData[1], \implode(' ', $interval)); - return $job; + return new self($jobData[0], $jobData[1], \implode(' ', $interval)); } } diff --git a/Validation/Base/Json.php b/Validation/Base/Json.php index b6707de96..dab21c1d0 100755 --- a/Validation/Base/Json.php +++ b/Validation/Base/Json.php @@ -69,12 +69,7 @@ abstract class Json extends ValidatorAbstract } } - $isValid = self::isValidSource($templatePaths, $sourcePaths); - if (!$isValid) { - return false; - } - - return true; + return self::isValidSource($templatePaths, $sourcePaths); } /** @@ -164,10 +159,8 @@ abstract class Json extends ValidatorAbstract $completePaths[$key] = $value; } - foreach ($completePaths as $tPath => $tValue) { - $sourceIsComplete = false; - - foreach ($source as $sPath => $sValue) { + foreach ($completePaths as $tPath => $_) { + foreach ($source as $sPath => $_) { if ($tPath === $sPath || \preg_match('~' . \str_replace('/', '\\/', $tPath) . '~', $sPath) === 1 ) { @@ -177,7 +170,7 @@ abstract class Json extends ValidatorAbstract } } - return \count($completePaths) === 0; + return empty($completePaths); } /** diff --git a/Validation/Validator.php b/Validation/Validator.php index c7015b16d..baed1be38 100755 --- a/Validation/Validator.php +++ b/Validation/Validator.php @@ -51,7 +51,7 @@ final class Validator extends ValidatorAbstract throw new \BadFunctionCallException(); } - $valid = !empty($settings) ? $callback($var, ...$settings) : $callback($var); + $valid = empty($settings) ? $callback($var) : $callback($var, ...$settings); $valid = (StringUtils::endsWith($test, 'Not') ? !$valid : $valid); if (!$valid) { @@ -102,11 +102,7 @@ final class Validator extends ValidatorAbstract { $length = \strlen($var); - if ($length <= $max && $length >= $min) { - return true; - } - - return false; + return $length <= $max && $length >= $min; } /** @@ -136,7 +132,7 @@ final class Validator extends ValidatorAbstract */ public static function matches(string $var, string $pattern) : bool { - return (\preg_match($pattern, $var) === 1 ? true : false); + return \preg_match($pattern, $var) === 1; } /** @@ -152,10 +148,6 @@ final class Validator extends ValidatorAbstract */ public static function hasLimit(int | float $var, int | float $min = 0, int | float $max = \PHP_INT_MAX) : bool { - if ($var <= $max && $var >= $min) { - return true; - } - - return false; + return $var <= $max && $var >= $min; } } diff --git a/Views/View.php b/Views/View.php index 861fab93c..5d7c95598 100755 --- a/Views/View.php +++ b/Views/View.php @@ -238,7 +238,7 @@ class View extends ViewAbstract $this->module = '0'; } - $start = $start + \strlen($match); + $start += \strlen($match); if (\strlen($this->template) < $start) { throw new InvalidModuleException($this->template); } @@ -274,7 +274,7 @@ class View extends ViewAbstract $this->theme = '0'; } - $start = $start + \strlen($match); + $start += \strlen($match); if (\strlen($this->template) < $start) { throw new InvalidThemeException($this->template); } diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 92281e3ca..81fc162b5 100755 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -302,7 +302,7 @@ abstract class ViewAbstract implements RenderableInterface if (\is_array($includeData)) { $ob .= (string) \json_encode($includeData); } - } catch (\Throwable $e) { + } catch (\Throwable $_) { if ($obLevel > 0 && $this->isBuffered) { $ob .= (string) \ob_get_clean(); } @@ -333,7 +333,7 @@ abstract class ViewAbstract implements RenderableInterface /** @noinspection PhpIncludeInspection */ $ob = include $path; - } catch (\Throwable $e) { + } catch (\Throwable $_) { $ob = ''; } diff --git a/tests/Log/FileLoggerTest.php b/tests/Log/FileLoggerTest.php index b97233175..a7a6c828f 100755 --- a/tests/Log/FileLoggerTest.php +++ b/tests/Log/FileLoggerTest.php @@ -81,7 +81,7 @@ final class FileLoggerTest extends \PHPUnit\Framework\TestCase } $instance = FileLogger::getInstance(__DIR__ . '/named.log', false); - TestUtils::getMember($instance, 'instance', null); + TestUtils::getMember($instance, 'instance'); $log = FileLogger::getInstance(__DIR__ . '/named.log', false); self::assertInstanceOf(FileLogger::class, $log); diff --git a/tests/Math/Stochastic/Distribution/GammaDistributionTest.php b/tests/Math/Stochastic/Distribution/GammaDistributionTest.php index 785d1df7c..5e057b09e 100755 --- a/tests/Math/Stochastic/Distribution/GammaDistributionTest.php +++ b/tests/Math/Stochastic/Distribution/GammaDistributionTest.php @@ -142,7 +142,7 @@ final class GammaDistributionTest extends \PHPUnit\Framework\TestCase */ public function testExKurtosis() : void { - self::assertEqualsWithDelta(3, GammaDistribution::getExKurtosis(2, 4), 0.001); + self::assertEqualsWithDelta(3, GammaDistribution::getExKurtosis(2), 0.001); } /** @@ -151,7 +151,7 @@ final class GammaDistributionTest extends \PHPUnit\Framework\TestCase */ public function testSkewness() : void { - self::assertEqualsWithDelta(\sqrt(2), GammaDistribution::getSkewness(2, 4), 0.001); + self::assertEqualsWithDelta(\sqrt(2), GammaDistribution::getSkewness(2), 0.001); } /** diff --git a/tests/Math/Stochastic/Distribution/ParetoDistributionTest.php b/tests/Math/Stochastic/Distribution/ParetoDistributionTest.php index ff26c979f..0a688e85f 100755 --- a/tests/Math/Stochastic/Distribution/ParetoDistributionTest.php +++ b/tests/Math/Stochastic/Distribution/ParetoDistributionTest.php @@ -74,7 +74,7 @@ final class ParetoDistributionTest extends \PHPUnit\Framework\TestCase */ public function testExKurtosis() : void { - self::assertEqualsWithDelta(35.666666666666664, ParetoDistribution::getExKurtosis(6, 5), 0.001); + self::assertEqualsWithDelta(35.666666666666664, ParetoDistribution::getExKurtosis(6), 0.001); self::assertEquals(0.0, ParetoDistribution::getExKurtosis(4)); } @@ -84,7 +84,7 @@ final class ParetoDistributionTest extends \PHPUnit\Framework\TestCase */ public function testSkewness() : void { - self::assertEqualsWithDelta(3.810317377662722, ParetoDistribution::getSkewness(6, 5), 0.001); + self::assertEqualsWithDelta(3.810317377662722, ParetoDistribution::getSkewness(6), 0.001); self::assertEquals(0.0, ParetoDistribution::getSkewness(3)); } diff --git a/tests/Socket/Client/ClientTest.php b/tests/Socket/Client/ClientTest.php index 8b33a9820..ed4ad32ba 100755 --- a/tests/Socket/Client/ClientTest.php +++ b/tests/Socket/Client/ClientTest.php @@ -95,24 +95,24 @@ final class ClientTest extends \PHPUnit\Framework\TestCase $socket = new Client($this->app); $socket->create('127.0.0.1', $GLOBALS['CONFIG']['socket']['master']['port']); - $socket->addPacket('handshake' . "\r"); - $socket->addPacket('help' . "\r"); - $socket->addPacket('shutdown' . "\r"); + $socket->addPacket("handshake\r"); + $socket->addPacket("help\r"); + $socket->addPacket("shutdown\r"); $this->app->router->add('^shutdown$', function() use ($socket) : void { $socket->shutdown(); }); $socket->run(); self::assertEquals( - 'Creating socket...' . "\n" - . 'Binding socket...' . "\n" - . 'Start listening...' . "\n" - . 'Is running...' . "\n" - . 'Connecting client...' . "\n" - . 'Connected client.' . "\n" - . 'Doing handshake...' . "\n" - . 'Handshake succeeded.' . "\n" - . 'Is shutdown...' . "\n", + "Creating socket...\n" + . "Binding socket...\n" + . "Start listening...\n" + . "Is running...\n" + . "Connecting client...\n" + . "Connected client.\n" + . "Doing handshake...\n" + . "Handshake succeeded.\n" + . "Is shutdown...\n", \file_get_contents(__DIR__ . '/server.log') ); diff --git a/tests/Socket/Server/ServerTestHelper.php b/tests/Socket/Server/ServerTestHelper.php index 04c9ffc0f..02967cf15 100755 --- a/tests/Socket/Server/ServerTestHelper.php +++ b/tests/Socket/Server/ServerTestHelper.php @@ -34,9 +34,9 @@ try { handleSocketError($sock); $msgs = [ - 'handshake' . "\r", // this needs to happen first (of course the submitted handshake data needs to be implemented correctl. just sending this is of course bad!) - 'help' . "\r", - 'shutdown' . "\r", + "handshake\r", // this needs to happen first (of course the submitted handshake data needs to be implemented correctl. just sending this is of course bad!) + "help\r", + "shutdown\r", ]; foreach ($msgs as $msg) { @@ -60,8 +60,8 @@ try { handleSocketError($sock); \socket_close($sock); -} catch (\Throwable $e) { - \file_put_contents(__DIR__ . '/client.log', $e->getMessage(), \FILE_APPEND); +} catch (\Throwable $t) { + \file_put_contents(__DIR__ . '/client.log', $t->getMessage(), \FILE_APPEND); } handleSocketError($sock); diff --git a/tests/System/File/Ftp/FtpStorageTest.php b/tests/System/File/Ftp/FtpStorageTest.php index 79f93b7bf..5a0c32751 100755 --- a/tests/System/File/Ftp/FtpStorageTest.php +++ b/tests/System/File/Ftp/FtpStorageTest.php @@ -127,7 +127,7 @@ final class FtpStorageTest extends \PHPUnit\Framework\TestCase public function testStaticSubdirDirectory() : void { $dirPath = __DIR__ . '/test/sub/path'; - self::assertTrue(FtpStorage::create($dirPath, 0755, true)); + self::assertTrue(FtpStorage::create($dirPath)); self::assertTrue(FtpStorage::exists($dirPath)); Directory::delete(self::$con, __DIR__ . '/test/sub/path'); diff --git a/tests/System/File/Local/LocalStorageTest.php b/tests/System/File/Local/LocalStorageTest.php index 7d5a7896e..ab1e7050d 100755 --- a/tests/System/File/Local/LocalStorageTest.php +++ b/tests/System/File/Local/LocalStorageTest.php @@ -71,7 +71,7 @@ final class LocalStorageTest extends \PHPUnit\Framework\TestCase public function testStaticSubdirDirectory() : void { $dirPath = __DIR__ . '/test/sub/path'; - self::assertTrue(LocalStorage::create($dirPath, 0755, true)); + self::assertTrue(LocalStorage::create($dirPath)); self::assertTrue(LocalStorage::exists($dirPath)); \rmdir(__DIR__ . '/test/sub/path');