rector fixes + bug fixes

This commit is contained in:
Dennis Eichhorn 2023-05-27 03:06:46 +00:00
parent fc2fd1343f
commit f09df7ea16
81 changed files with 506 additions and 519 deletions

View File

@ -294,7 +294,7 @@ final class BasicOcr
3
);
\array_push($mnist, $gray);
$mnist[] = $gray;
}
}

View File

@ -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'

View File

@ -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));
}

View File

@ -41,7 +41,7 @@ final class DependencyResolver
self::dependencyResolve($table, $graph, $resolved, $unresolved);
}
return !empty($unresolved) ? null : $resolved;
return empty($unresolved) ? $resolved : null;
}
/**

View File

@ -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)) {

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -183,8 +183,7 @@ final class DeleteMapper extends DataMapperAbstract
}
/** @var class-string<DataMapperFactory> $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)) {

View File

@ -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

View File

@ -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();
}
}

View File

@ -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],

View File

@ -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(),

View File

@ -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);
}
}

View File

@ -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;
}));
}

View File

@ -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]);

View File

@ -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;
}
/**

View File

@ -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];
}
}

View File

@ -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;
}
}
}

View File

@ -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;
}
}

View File

@ -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];

View File

@ -57,7 +57,7 @@ final class QRDecomposition
/**
* R diagonal
*
* @var array
* @var array<int, int|float>
* @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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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];

View File

@ -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;

View File

@ -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 */

View File

@ -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);

View File

@ -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 : [];
}
/**

View File

@ -183,8 +183,6 @@ final class Rest
. $content . "\r\n";
}
$data .= '--' . $delim . "--\r\n";
return $data;
return $data . ('--' . $delim . "--\r\n");
}
}

View File

@ -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;

View File

@ -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
);
}

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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 : [];
}
/**

View File

@ -171,9 +171,8 @@ final class Head implements RenderableInterface
$head .= $this->meta->render();
$head .= $this->renderAssets();
$head .= empty($this->style) ? '' : '<style>' . $this->renderStyle() . '</style>';
$head .= empty($this->script) ? '' : '<script>' . $this->renderScript() . '</script>';
return $head;
return $head . (empty($this->script) ? '' : '<script>' . $this->renderScript() . '</script>');
}
/**

View File

@ -229,10 +229,10 @@ final class Meta implements RenderableInterface
*/
public function render(mixed ...$data) : string
{
return (\count($this->keywords) > 0 ? '<meta name="keywords" content="' . ViewAbstract::html(\implode(',', $this->keywords)) . '">' : '')
. (!empty($this->author) ? '<meta name="author" content="' . ViewAbstract::html($this->author) . '">' : '')
. (!empty($this->description) ? '<meta name="description" content="' . ViewAbstract::html($this->description) . '">' : '')
. (!empty($this->charset) ? '<meta charset="' . ViewAbstract::html($this->charset) . '">' : '')
return (empty($this->keywords) ? '' : '<meta name="keywords" content="' . ViewAbstract::html(\implode(',', $this->keywords)) . '">')
. (empty($this->author) ? '' : '<meta name="author" content="' . ViewAbstract::html($this->author) . '">')
. (empty($this->description) ? '' : '<meta name="description" content="' . ViewAbstract::html($this->description) . '">')
. (empty($this->charset) ? '' : '<meta charset="' . ViewAbstract::html($this->charset) . '">')
. '<meta name="generator" content="Karaka">'
. $this->renderProperty()
. $this->renderItemprop()

View File

@ -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 {

View File

@ -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 : [];
}
/**

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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+');

View File

@ -93,7 +93,7 @@ final class File extends FileAbstract implements FileInterface
return true;
}
} catch (\Throwable $e) {
} catch (\Throwable $_) {
return false; // @codeCoverageIgnore
}

View File

@ -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 = [];

View File

@ -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());
}
/**

View File

@ -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());
}
/**

View File

@ -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;

View File

@ -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;

View File

@ -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))]];
}
}

View File

@ -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];
}
}

View File

@ -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';
}
}

View File

@ -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);
}
/**

View File

@ -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;
}

View File

@ -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 '';
}

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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('<abbr title="SuperScript">SuperScript</abbr> : ' . ($oRichText->getFont()->isSuperScript() ? 'Y' : 'N'));
$this->append('</dd>');
if ($oRichText instanceof TextElement) {
if ($oRichText->hasHyperlink()) {
$this->append('<dt>Hyperlink URL</dt><dd>' . $oRichText->getHyperlink()->getUrl() . '</dd>');
$this->append('<dt>Hyperlink Tooltip</dt><dd>' . $oRichText->getHyperlink()->getTooltip() . '</dd>');
}
if ($oRichText instanceof TextElement && $oRichText->hasHyperlink()) {
$this->append('<dt>Hyperlink URL</dt><dd>' . $oRichText->getHyperlink()->getUrl() . '</dd>');
$this->append('<dt>Hyperlink Tooltip</dt><dd>' . $oRichText->getHyperlink()->getTooltip() . '</dd>');
}
$this->append('</dl>');

View File

@ -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 = '<p>' . $text . '</p>';
}
return $text;
return $this->hasParagraphs ? '<p>' . $text . '</p>' : $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';
}
}

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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);
}
/**

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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 = '';
}

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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));
}

View File

@ -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')
);

View File

@ -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);

View File

@ -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');

View File

@ -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');