diff --git a/DataStorage/Cache/Connection/ConnectionAbstract.php b/DataStorage/Cache/Connection/ConnectionAbstract.php index 83fa481f0..8baac3b3b 100644 --- a/DataStorage/Cache/Connection/ConnectionAbstract.php +++ b/DataStorage/Cache/Connection/ConnectionAbstract.php @@ -39,7 +39,7 @@ abstract class ConnectionAbstract implements ConnectionInterface * @var mixed * @since 1.0.0 */ - private $con = null; + protected $con = null; /** * Database prefix. diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index a05fc19b3..92676ab56 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -59,7 +59,7 @@ final class MysqlConnection extends ConnectionAbstract $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) { - throw new InvalidConnectionConfigException(\json_encode($this->dbdata)); + throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata)); } $this->close(); diff --git a/DataStorage/Database/Connection/PostgresConnection.php b/DataStorage/Database/Connection/PostgresConnection.php index 33fa94d48..ae61b9338 100644 --- a/DataStorage/Database/Connection/PostgresConnection.php +++ b/DataStorage/Database/Connection/PostgresConnection.php @@ -58,7 +58,7 @@ final class PostgresConnection extends ConnectionAbstract $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) { - throw new InvalidConnectionConfigException(\json_encode($this->dbdata)); + throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata)); } $this->close(); diff --git a/DataStorage/Database/Connection/SQLiteConnection.php b/DataStorage/Database/Connection/SQLiteConnection.php index 5e45f345f..23374e332 100644 --- a/DataStorage/Database/Connection/SQLiteConnection.php +++ b/DataStorage/Database/Connection/SQLiteConnection.php @@ -16,7 +16,7 @@ namespace phpOMS\DataStorage\Database\Connection; use phpOMS\DataStorage\Database\DatabaseStatus; use phpOMS\DataStorage\Database\DatabaseType; -use phpOMS\DataStorage\Database\Query\Grammar\SqliteGrammar; +use phpOMS\DataStorage\Database\Query\Grammar\SQLiteGrammar; /** * Database handler. @@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\Query\Grammar\SqliteGrammar; * @link http://website.orange-management.de * @since 1.0.0 */ -final class SqliteConnection extends ConnectionAbstract +final class SQLiteConnection extends ConnectionAbstract { /** @@ -43,8 +43,8 @@ final class SqliteConnection extends ConnectionAbstract */ public function __construct(array $dbdata) { - $this->type = DatabaseType::MYSQL; - $this->grammar = new SqliteGrammar(); + $this->type = DatabaseType::SQLITE; + $this->grammar = new SQLiteGrammar(); $this->connect($dbdata); } @@ -65,9 +65,10 @@ final class SqliteConnection extends ConnectionAbstract $this->status = DatabaseStatus::OK; } catch (\PDOException $e) { - var_dump($e->getMessage()); $this->status = DatabaseStatus::MISSING_DATABASE; $this->con = null; + } finally { + $this->dbdata['password'] = '****'; } } } diff --git a/DataStorage/Database/DatabaseType.php b/DataStorage/Database/DatabaseType.php index 2999a3ace..8fa1a2491 100644 --- a/DataStorage/Database/DatabaseType.php +++ b/DataStorage/Database/DatabaseType.php @@ -30,7 +30,7 @@ abstract class DatabaseType extends Enum { public const MYSQL = 'mysql'; /* MySQL */ public const SQLITE = 'sqlite'; /* SQLITE */ - public const PGSQL = 2; /* PostgreSQL */ + public const PGSQL = 'postgresql'; /* PostgreSQL */ public const ORACLE = 3; /* Oracle */ public const SQLSRV = 'mssql'; /* Microsoft SQL Server */ } diff --git a/DataStorage/Database/Query/Grammar/SQLiteGrammar.php b/DataStorage/Database/Query/Grammar/SQLiteGrammar.php index d77483f85..056a8d6c5 100644 --- a/DataStorage/Database/Query/Grammar/SQLiteGrammar.php +++ b/DataStorage/Database/Query/Grammar/SQLiteGrammar.php @@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\Query\Builder; * @link http://website.orange-management.de * @since 1.0.0 */ -class SqliteGrammar extends Grammar +class SQLiteGrammar extends Grammar { /** diff --git a/DataStorage/Database/Schema/Grammar/MysqlGrammar.php b/DataStorage/Database/Schema/Grammar/MysqlGrammar.php index ea86d288e..43e2e9270 100644 --- a/DataStorage/Database/Schema/Grammar/MysqlGrammar.php +++ b/DataStorage/Database/Schema/Grammar/MysqlGrammar.php @@ -67,7 +67,7 @@ class MysqlGrammar extends Grammar */ protected function compileFrom(Builder $query, array $table) : string { - $expression = $this->expressionizeTableColumn('information_schema.tables'); + $expression = $this->expressionizeTableColumn(['information_schema.tables']); return 'FROM ' . $expression; } diff --git a/DataStorage/Database/Schema/Grammar/PostgresGrammar.php b/DataStorage/Database/Schema/Grammar/PostgresGrammar.php index 51ae131e8..6dfe5424f 100644 --- a/DataStorage/Database/Schema/Grammar/PostgresGrammar.php +++ b/DataStorage/Database/Schema/Grammar/PostgresGrammar.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace phpOMS\DataStorage\Database\Schema\Grammar; -class PostgresGrammar +class PostgresGrammar extends Grammar { } diff --git a/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php b/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php index da4a7dd52..448fe9a91 100644 --- a/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php +++ b/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace phpOMS\DataStorage\Database\Schema\Grammar; -class SQLiteGrammar +class SQLiteGrammar extends Grammar { } diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 2d66dc3a2..443fb5e38 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -50,7 +50,7 @@ class HttpSession implements SessionInterface /** * Session ID. * - * @var string|int + * @var string|int|null * @since 1.0.0 */ private $sid = null; @@ -85,7 +85,7 @@ class HttpSession implements SessionInterface } if (!\is_bool($sid)) { - \session_id($sid); + \session_id((string) $sid); } $this->inactivityInterval = $inactivityInterval; diff --git a/DataStorage/Session/SessionInterface.php b/DataStorage/Session/SessionInterface.php index 98d3b68a5..2e8e6eb77 100644 --- a/DataStorage/Session/SessionInterface.php +++ b/DataStorage/Session/SessionInterface.php @@ -74,14 +74,14 @@ interface SessionInterface public function save() : void; /** - * @return int|string + * @return int|string|null * * @since 1.0.0 */ public function getSID(); /** - * @param int|string $sid Session id + * @param int|string|null $sid Session id * * @return void * diff --git a/Math/Stochastic/Distribution/BinomialDistribution.php b/Math/Stochastic/Distribution/BinomialDistribution.php index ef62eb044..82a49127c 100644 --- a/Math/Stochastic/Distribution/BinomialDistribution.php +++ b/Math/Stochastic/Distribution/BinomialDistribution.php @@ -57,7 +57,7 @@ class BinomialDistribution */ public static function getMgf(int $n, float $t, float $p) : float { - return (float) pow(1 - $p + $p * exp($t), $n); + return pow(1 - $p + $p * exp($t), $n); } /** diff --git a/Math/Stochastic/Distribution/ChiSquaredDistribution.php b/Math/Stochastic/Distribution/ChiSquaredDistribution.php index 80d472bcc..18547f119 100644 --- a/Math/Stochastic/Distribution/ChiSquaredDistribution.php +++ b/Math/Stochastic/Distribution/ChiSquaredDistribution.php @@ -31,7 +31,7 @@ class ChiSquaredDistribution /** * Chi square table. * - * @var array + * @var array> * @since 1.0.0 */ public const TABLE = [ @@ -106,7 +106,7 @@ class ChiSquaredDistribution $df = self::getDegreesOfFreedom($dataset); } - if (!defined(self::TABLE[$df])) { + if (!defined('self::TABLE') || !array_key_exists($df, self::TABLE)) { throw new \Exception('Degrees of freedom not supported'); } @@ -117,7 +117,8 @@ class ChiSquaredDistribution } } - $p = 1 - ($p ?? key(end(self::TABLE[$df]))); + $key = key(end(self::TABLE[$df])); + $p = 1 - ($p ?? ($key === false ? 1 : (float) $key)); return ['P' => $p, 'H0' => ($p > $significance), 'df' => $df]; } @@ -235,7 +236,7 @@ class ChiSquaredDistribution throw new \Exception('Out of bounds'); } - return (float) pow(1 - 2 * $t, -$df / 2); + return pow(1 - 2 * $t, -$df / 2); } /** diff --git a/Math/Stochastic/Distribution/ExponentialDistribution.php b/Math/Stochastic/Distribution/ExponentialDistribution.php index d53ed6303..43be19014 100644 --- a/Math/Stochastic/Distribution/ExponentialDistribution.php +++ b/Math/Stochastic/Distribution/ExponentialDistribution.php @@ -105,7 +105,7 @@ class ExponentialDistribution */ public static function getVariance(float $lambda) : float { - return (float) pow($lambda, -2); + return pow($lambda, -2); } /** diff --git a/Math/Stochastic/Distribution/GeometricDistribution.php b/Math/Stochastic/Distribution/GeometricDistribution.php index 84ec3bf70..fdbca94ad 100644 --- a/Math/Stochastic/Distribution/GeometricDistribution.php +++ b/Math/Stochastic/Distribution/GeometricDistribution.php @@ -36,7 +36,7 @@ class GeometricDistribution */ public static function getPmf(float $p, int $k) : float { - return (float) pow(1 - $p, $k - 1) * $p; + return pow(1 - $p, $k - 1) * $p; } /** diff --git a/Math/Stochastic/Distribution/PoissonDistribution.php b/Math/Stochastic/Distribution/PoissonDistribution.php index 438982080..94d6d9088 100644 --- a/Math/Stochastic/Distribution/PoissonDistribution.php +++ b/Math/Stochastic/Distribution/PoissonDistribution.php @@ -147,7 +147,7 @@ class PoissonDistribution */ public static function getSkewness(float $lambda) : float { - return (float) pow($lambda, -1 / 2); + return pow($lambda, -1 / 2); } /** @@ -161,7 +161,7 @@ class PoissonDistribution */ public static function getFisherInformation(float $lambda) : float { - return (float) pow($lambda, -1); + return pow($lambda, -1); } /** @@ -175,7 +175,7 @@ class PoissonDistribution */ public static function getExKurtosis(float $lambda) : float { - return (float) pow($lambda, -1); + return pow($lambda, -1); } public static function getRandom() diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 834db20b8..8101a5efb 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -140,13 +140,16 @@ final class Request extends RequestAbstract { if (isset($_SERVER['CONTENT_TYPE'])) { if (\stripos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) { - if (($json = \json_decode(($input = \file_get_contents('php://input')), true)) === false || $json === null) { + $input = \file_get_contents('php://input'); + $json = \json_decode($input === false ? '' : $input, true); + if ($input === false || $json === false || $json === null) { throw new \Exception('Is not valid json ' . $input); } $this->data += $json; } elseif (\stripos($_SERVER['CONTENT_TYPE'], 'application/x-www-form-urlencoded') !== false) { - parse_str(file_get_contents('php://input'), $temp); + $content = \file_get_contents('php://input'); + \parse_str($content === false ? '' : $content, $temp); $this->data += $temp; } } @@ -292,7 +295,7 @@ final class Request extends RequestAbstract { if ($this->browser === null) { $arr = BrowserType::getConstants(); - $httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); + $httpUserAgent = \strtolower($_SERVER['HTTP_USER_AGENT']); foreach ($arr as $key => $val) { if (stripos($httpUserAgent, $val)) { @@ -333,10 +336,10 @@ final class Request extends RequestAbstract { if ($this->os === null) { $arr = OSType::getConstants(); - $httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); + $httpUserAgent = \strtolower($_SERVER['HTTP_USER_AGENT']); foreach ($arr as $key => $val) { - if (stripos($httpUserAgent, $val)) { + if (\stripos($httpUserAgent, $val)) { $this->os = $val; return $this->os; @@ -397,7 +400,8 @@ final class Request extends RequestAbstract */ public function getBody() : string { - return \file_get_contents('php://input'); + $body = \file_get_contents('php://input'); + return $body === false ? '' : $body; } /** diff --git a/Message/Mail/Mail.php b/Message/Mail/Mail.php index c9618ba4f..513ea0bab 100644 --- a/Message/Mail/Mail.php +++ b/Message/Mail/Mail.php @@ -123,7 +123,7 @@ class Mail /** * Word wrap. * - * @var string + * @var int * @since 1.0.0 */ protected $wordWrap = 78; diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 4a347780e..6d77f0701 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -115,7 +115,7 @@ class InstallerAbstract */ private static function activate(DatabasePool $dbPool, InfoManager $info) : void { - /** @var ActivateAbstract $class */ + /** @var StatusAbstract $class */ $class = '\Modules\\' . $info->getDirectory() . '\Admin\Status'; $class::activate($dbPool, $info); } diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php index 8084f7a70..fc999e9b3 100644 --- a/System/File/ContainerInterface.php +++ b/System/File/ContainerInterface.php @@ -205,7 +205,7 @@ interface ContainerInterface * @param bool $recursive Consider subdirectories * @param array $ignore Files/paths to ignore (no regex) * - * @return string + * @return int * * @since 1.0.0 */ diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php index 47e3ea97f..922a2ea6e 100644 --- a/Utils/IO/Zip/Gz.php +++ b/Utils/IO/Zip/Gz.php @@ -31,23 +31,25 @@ class Gz implements ArchiveInterface */ public static function pack($source, string $destination, bool $overwrite = true) : bool { - $destination = \str_replace('\\', '/', realpath($destination)); + $destination = \str_replace('\\', '/', $destination); if (!$overwrite && \file_exists($destination)) { return false; } - if (($gz = gzopen($destination, 'w')) === false) { + $gz = \gzopen($destination, 'w'); + $src = \fopen($source, 'r'); + if ($gz === false || $src === false) { return false; } - $src = fopen($source, 'r'); - while (!feof($src)) { - gzwrite($gz, fread($src, 4096)); + while (!\feof($src)) { + $read = \fread($src, 4096); + \gzwrite($gz, $read === false ? '' : $read); } - fclose($src); + \fclose($src); - return gzclose($gz); + return \gzclose($gz); } /** @@ -55,22 +57,23 @@ class Gz implements ArchiveInterface */ public static function unpack(string $source, string $destination) : bool { - $destination = \str_replace('\\', '/', realpath($destination)); - if (file_exists($destination)) { + $destination = \str_replace('\\', '/', $destination); + if (\file_exists($destination)) { return false; } - if (($gz = gzopen($source, 'w')) === false) { + $gz = \gzopen($source, 'w'); + $dest = \fopen($destination, 'w'); + if ($gz === false || $dest === false) { return false; } - $dest = fopen($destination, 'w'); - while (!gzeof($gz)) { - fwrite($dest, gzread($gz, 4096)); + while (!\gzeof($gz)) { + \fwrite($dest, \gzread($gz, 4096)); } - fclose($dest); + \fclose($dest); - return gzclose($gz); + return \gzclose($gz); } } diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php index 37171fee6..8279c7f63 100644 --- a/Utils/TaskSchedule/Cron.php +++ b/Utils/TaskSchedule/Cron.php @@ -39,7 +39,7 @@ class Cron extends SchedulerAbstract */ private function run(string $cmd) : string { - $cmd = 'cd ' . escapeshellarg(\dirname(self::$bin)) . ' && ' . basename(self::$bin) . ' ' . $cmd; + $cmd = 'cd ' . \escapeshellarg(\dirname(self::$bin)) . ' && ' . \basename(self::$bin) . ' ' . $cmd; $pipes = []; $desc = [ @@ -47,15 +47,19 @@ class Cron extends SchedulerAbstract 2 => ['pipe', 'w'], ]; - $resource = proc_open($cmd, $desc, $pipes, __DIR__, null); - $stdout = stream_get_contents($pipes[1]); - $stderr = stream_get_contents($pipes[2]); + $resource = \proc_open($cmd, $desc, $pipes, __DIR__, null); + $stdout = \stream_get_contents($pipes[1]); + $stderr = \stream_get_contents($pipes[2]); foreach ($pipes as $pipe) { - fclose($pipe); + \fclose($pipe); } - $status = trim((string) proc_close($resource)); + if ($resource === false) { + throw new \Exception(); + } + + $status = \proc_close($resource); if ($status == -1) { throw new \Exception($stderr); @@ -88,8 +92,8 @@ class Cron extends SchedulerAbstract $jobs = []; foreach ($lines as $line) { - if ($line !== '' && strrpos($line, '#', -strlen($line)) === false) { - $jobs[] = CronJob::createWith(str_getcsv($line, ' ')); + if ($line !== '' && \strrpos($line, '#', -\strlen($line)) === false) { + $jobs[] = CronJob::createWith(\str_getcsv($line, ' ')); } } @@ -107,18 +111,18 @@ class Cron extends SchedulerAbstract if ($exact) { $jobs = []; foreach ($lines as $line) { - $csv = str_getcsv($line, ' '); + $csv = \str_getcsv($line, ' '); - if ($line !== '' && strrpos($line, '#', -strlen($line)) === false && $csv[5] === $name) { + if ($line !== '' && \strrpos($line, '#', -\strlen($line)) === false && $csv[5] === $name) { $jobs[] = CronJob::createWith($csv); } } } else { $jobs = []; foreach ($lines as $line) { - $csv = str_getcsv($line, ' '); + $csv = \str_getcsv($line, ' '); - if ($line !== '' && strrpos($line, '#', -strlen($line)) === false && \stripos($csv[5], $name) !== false) { + if ($line !== '' && \strrpos($line, '#', -\strlen($line)) === false && \stripos($csv[5], $name) !== false) { $jobs[] = CronJob::createWith($csv); } }