Type check fixes

This commit is contained in:
Dennis Eichhorn 2018-07-15 10:46:34 +02:00
parent da9b2d3406
commit 6843ac5548
22 changed files with 76 additions and 63 deletions

View File

@ -39,7 +39,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
* @var mixed
* @since 1.0.0
*/
private $con = null;
protected $con = null;
/**
* Database prefix.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;
class PostgresGrammar
class PostgresGrammar extends Grammar
{
}

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace phpOMS\DataStorage\Database\Schema\Grammar;
class SQLiteGrammar
class SQLiteGrammar extends Grammar
{
}

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ class ChiSquaredDistribution
/**
* Chi square table.
*
* @var array
* @var array<int, array<string, float>>
* @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);
}
/**

View File

@ -105,7 +105,7 @@ class ExponentialDistribution
*/
public static function getVariance(float $lambda) : float
{
return (float) pow($lambda, -2);
return pow($lambda, -2);
}
/**

View File

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

View File

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

View File

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

View File

@ -123,7 +123,7 @@ class Mail
/**
* Word wrap.
*
* @var string
* @var int
* @since 1.0.0
*/
protected $wordWrap = 78;

View File

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

View File

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

View File

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

View File

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