diff --git a/Business/Finance/Loan.php b/Business/Finance/Loan.php index 9a729641c..0e97180fd 100644 --- a/Business/Finance/Loan.php +++ b/Business/Finance/Loan.php @@ -39,7 +39,7 @@ final class Loan * * @since 1.0.0 */ - public static function getPaymentsOnBalloonLoan(float $PV, float $r, int $n, float $balloon = 0) : float + public static function getPaymentsOnBalloonLoan(float $PV, float $r, int $n, float $balloon = 0.0) : float { return ($PV - $balloon / \pow(1 + $r, $n)) * $r / (1 - \pow(1 + $r, -$n)); } diff --git a/DataStorage/File/JsonBuilder.php b/DataStorage/File/JsonBuilder.php index 2123f2020..60f7e3a14 100644 --- a/DataStorage/File/JsonBuilder.php +++ b/DataStorage/File/JsonBuilder.php @@ -1157,4 +1157,4 @@ final class JsonBuilder { return $this->grammar->compileQuery($this); } -} \ No newline at end of file +} diff --git a/Localization/Money.php b/Localization/Money.php index d3aaa2dff..ee3b07abc 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -217,7 +217,7 @@ final class Money implements \Serializable */ public function add($value) : self { - if (\is_string($value) || is_float($value)) { + if (\is_string($value) || \is_float($value)) { $this->value += self::toInt((string) $value, $this->thousands, $this->decimal); } elseif (\is_int($value)) { $this->value += $value; @@ -251,7 +251,7 @@ final class Money implements \Serializable */ public function sub($value) : self { - if (\is_string($value) || is_float($value)) { + if (\is_string($value) || \is_float($value)) { $this->value -= self::toInt((string) $value, $this->thousands, $this->decimal); } elseif (\is_int($value)) { $this->value -= $value; diff --git a/Message/Http/Response.php b/Message/Http/Response.php index 9342636ad..dbd7e386c 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -148,7 +148,9 @@ final class Response extends ResponseAbstract implements RenderableInterface { $types = $this->header->get('Content-Type'); if (\stripos($types[0], MimeType::M_HTML) !== false) { - return \trim(\preg_replace('/(?s).*?<\/pre>(*SKIP)(*F)|(\s{2,}|\n|\t)/', ' ', $render)); + $clean = \preg_replace('/(?s).*?<\/pre>(*SKIP)(*F)|(\s{2,}|\n|\t)/', ' ', $render); + + return \trim($clean ?? ''); } return $render; diff --git a/Module/ModuleFactory.php b/Module/ModuleFactory.php index cb5e30f78..4737977b7 100644 --- a/Module/ModuleFactory.php +++ b/Module/ModuleFactory.php @@ -80,10 +80,10 @@ final class ModuleFactory self::registerRequesting($obj); self::registerProvided($obj); } catch (\Throwable $e) { - self::$loaded[$module] = new NullModule($app); + self::$loaded[$module] = new NullModule(); } } else { - self::$loaded[$module] = new NullModule($app); + self::$loaded[$module] = new NullModule(); } } diff --git a/Stdlib/Queue/PriorityQueue.php b/Stdlib/Queue/PriorityQueue.php index 9011941ab..a03d653ad 100644 --- a/Stdlib/Queue/PriorityQueue.php +++ b/Stdlib/Queue/PriorityQueue.php @@ -78,7 +78,7 @@ class PriorityQueue implements \Countable, \Serializable * * @since 1.0.0 */ - public function insert($data, $priority = 1) : int + public function insert($data, float $priority = 1.0) : int { do { $key = \mt_rand(); @@ -104,9 +104,11 @@ class PriorityQueue implements \Countable, \Serializable * * @return int * + * @throws InvalidEnumValue + * * @since 1.0.0 */ - private function getInsertPosition($priority) : int + private function getInsertPosition(float $priority) : int { switch($this->type) { case PriorityMode::FIFO: @@ -131,7 +133,7 @@ class PriorityQueue implements \Countable, \Serializable * * @since 1.0.0 */ - private function getInsertFIFO($priority) : int + private function getInsertFIFO(float $priority) : int { return 0; } @@ -145,7 +147,7 @@ class PriorityQueue implements \Countable, \Serializable * * @since 1.0.0 */ - private function getInsertLIFO($priority) : int + private function getInsertLIFO(float $priority) : int { return \count($this->queue); } @@ -159,7 +161,7 @@ class PriorityQueue implements \Countable, \Serializable * * @since 1.0.0 */ - private function getInsertHighest($priority) : int + private function getInsertHighest(float $priority) : int { $pos = 0; foreach ($this->queue as $ele) { @@ -182,7 +184,7 @@ class PriorityQueue implements \Countable, \Serializable * * @since 1.0.0 */ - private function getInsertLowest($priority) : int + private function getInsertLowest(float $priority) : int { $pos = 0; foreach ($this->queue as $ele) { @@ -205,7 +207,7 @@ class PriorityQueue implements \Countable, \Serializable * * @since 1.0.0 */ - public function increaseAll($increase = 1) : void + public function increaseAll(float $increase = 1.0) : void { foreach ($this->queue as $key => &$ele) { $ele['priority'] += $increase; @@ -248,13 +250,13 @@ class PriorityQueue implements \Countable, \Serializable * Set element priority. * * @param mixed $id Element ID - * @param mixed $priority Element priority + * @param float $priority Element priority * * @return void * * @since 1.0.0 */ - public function setPriority($id, $priority) : void + public function setPriority($id, float $priority) : void { if ($this->type === PriorityMode::FIFO || $this->type === PriorityMode::LIFO) { $this->queue[$id]['priority'] = $priority; diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index 79dcfb965..83e670273 100644 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -130,12 +130,14 @@ final class FileUtils */ public static function changeFileEncoding(string $file, string $encoding) : void { - $content = \file_get_contents($file); - $detected = \mb_detect_encoding($content); + $content = \file_get_contents($file); - if ($content !== false) { - \file_put_contents($file, \mb_convert_encoding($content, $encoding, $detected === false ? \mb_list_encodings() : $detected)); + if ($content === false) { + return; } + + $detected = \mb_detect_encoding($content); + \file_put_contents($file, \mb_convert_encoding($content, $encoding, $detected === false ? \mb_list_encodings() : $detected)); } /** diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 07737ab38..e94e84e59 100644 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -176,7 +176,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory if ($filename['type'] === 'dir' && $recursive) { $countSize += self::size($con, $key, $recursive); - } elseif ($filename['type'] === 'file' ) { + } elseif ($filename['type'] === 'file') { $countSize += \ftp_size($con, $key); } } @@ -308,7 +308,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory $e['month'], $e['day'], $e['time'] - ) = $chunks; + ) = $chunks; $e['permission'] = FileUtils::permissionToOctal(\substr($e['permission'], 1)); $e['type'] = $chunks[0]{0} === 'd' ? 'dir' : 'file'; diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index ef4092992..4d95b6b8c 100644 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -115,7 +115,7 @@ class File extends FileAbstract implements FileInterface */ public static function put($con, string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool { - $exists = self::exists($con, $path); + $exists = self::exists($con, $path); if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) || (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 81d80d4a4..bd9b882cc 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -403,7 +403,7 @@ final class Directory extends FileAbstract implements LocalContainerInterface, D */ public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;:\[\]\(\]\/]/') : string { - return \preg_replace($invalid, $replace, $path); + return \preg_replace($invalid, $replace, $path) ?? ''; } /** diff --git a/System/File/Local/File.php b/System/File/Local/File.php index f56a4cdfb..82da5107e 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -197,7 +197,7 @@ final class File extends FileAbstract implements LocalContainerInterface, FileIn */ public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string { - return \preg_replace($invalid, $replace, $path); + return \preg_replace($invalid, $replace, $path) ?? ''; } /** diff --git a/Uri/Http.php b/Uri/Http.php index e93ed8ce8..4144a430e 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -163,6 +163,10 @@ final class Http implements UriInterface $this->uri = $uri; $url = \parse_url($this->uri); + if ($url === false) { + return; + } + $this->scheme = $url['scheme'] ?? ''; $this->host = $url['host'] ?? ''; $this->port = $url['port'] ?? 80; diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 465e11d19..e1c96d2d3 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -241,6 +241,6 @@ final class UriFactory return $toMatch[$match] ?? self::$uri[$match] ?? $match; }, $uri); - return self::unique($parsed); + return self::unique($parsed ?? ''); } } diff --git a/Utils/Barcode/C25.php b/Utils/Barcode/C25.php index 9f2d3deaa..af26d0b71 100644 --- a/Utils/Barcode/C25.php +++ b/Utils/Barcode/C25.php @@ -62,21 +62,6 @@ class C25 extends C128Abstract */ protected static $CODE_END = '311'; - /** - * Constructor - * - * @param string $content Content to encrypt - * @param int $width Barcode width - * @param int $height Barcode height - * @param int $orientation Orientation of the barcode - * - * @since 1.0.0 - */ - public function __construct(string $content = '', int $width = 100, int $height = 20, int $orientation = OrientationType::HORIZONTAL) - { - parent::__construct($content, $width, $height, $orientation); - } - /** * Set content to encrypt * diff --git a/Utils/Converter/Numeric.php b/Utils/Converter/Numeric.php index d95210ef4..442915124 100644 --- a/Utils/Converter/Numeric.php +++ b/Utils/Converter/Numeric.php @@ -60,7 +60,7 @@ class Numeric */ public static function convertBase(string $numberInput, string $fromBaseInput, string $toBaseInput) : string { - if ($fromBaseInput == $toBaseInput) { + if ($fromBaseInput === $toBaseInput) { return $numberInput; } diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php index 545533aeb..3dcb3a90d 100644 --- a/Utils/Git/Repository.php +++ b/Utils/Git/Repository.php @@ -201,10 +201,10 @@ class Repository $status = \proc_close($resource); if ($status == -1) { - throw new \Exception($stderr); + throw new \Exception((string) $stderr); } - return $this->parseLines(\trim($stdout)); + return $this->parseLines(\trim($stdout === false ? '' : $stdout)); } /** diff --git a/Utils/Permutation.php b/Utils/Permutation.php index df7eeea2b..700b579f1 100644 --- a/Utils/Permutation.php +++ b/Utils/Permutation.php @@ -93,7 +93,7 @@ final class Permutation */ public static function isPalindrome(string $a, string $filter = 'a-zA-Z0-9') : bool { - $a = \strtolower(\preg_replace('/[^' . $filter . ']/', '', $a)); + $a = \strtolower(\preg_replace('/[^' . $filter . ']/', '', $a) ?? ''); return $a === \strrev($a); } diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index 4ee480188..9c2e84b51 100644 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -268,7 +268,7 @@ final class StringUtils } else { $charlist = \str_replace('/', '\/', \preg_quote($charlist)); - return \preg_replace('/(^[' . $charlist . ']+)|([ ' . $charlist . ']+$)/us', '', $string); + return \preg_replace('/(^[' . $charlist . ']+)|([ ' . $charlist . ']+$)/us', '', $string) ?? ''; } } @@ -289,7 +289,7 @@ final class StringUtils } else { $charlist = \str_replace('/', '\/', \preg_quote($charlist)); - return \preg_replace('/([' . $charlist . ']+$)/us', '', $string); + return \preg_replace('/([' . $charlist . ']+$)/us', '', $string) ?? ''; } } @@ -310,7 +310,7 @@ final class StringUtils } else { $charlist = \str_replace('/', '\/', \preg_quote($charlist)); - return \preg_replace('/(^[' . $charlist . ']+)/us', '', $string); + return \preg_replace('/(^[' . $charlist . ']+)/us', '', $string) ?? ''; } } @@ -472,7 +472,7 @@ final class StringUtils } switch ($mc) { - case -1: + case -1: $result .= ''; break; case 1: diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php index ee01d8d2c..f3644a931 100644 --- a/Utils/TaskSchedule/SchedulerAbstract.php +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -164,10 +164,10 @@ abstract class SchedulerAbstract $status = \proc_close($resource); if ($status === -1) { - throw new \Exception($stderr); + throw new \Exception((string) $stderr); } - return \trim($stdout); + return $stdout === false ? '' : \trim($stdout); } /** diff --git a/Validation/Finance/CreditCard.php b/Validation/Finance/CreditCard.php index 152bf943c..2b90125d5 100644 --- a/Validation/Finance/CreditCard.php +++ b/Validation/Finance/CreditCard.php @@ -32,7 +32,11 @@ final class CreditCard extends ValidatorAbstract */ public static function isValid($value, array $constraints = null) : bool { - $value = preg_replace('/\D/', '', $value); + if (!\is_string($value)) { + throw new \InvalidArgumentException(); + } + + $value = \preg_replace('/\D/', '', $value) ?? ''; // Set the string length and parity $numberLength = \strlen($value); diff --git a/Views/TableView.php b/Views/TableView.php new file mode 100644 index 000000000..ce04de9e6 --- /dev/null +++ b/Views/TableView.php @@ -0,0 +1,31 @@ +