PhpStan fixes

This commit is contained in:
Dennis Eichhorn 2018-09-12 22:15:44 +02:00
parent 5bfba4b202
commit a95b0ea026
21 changed files with 57 additions and 59 deletions

View File

@ -420,7 +420,8 @@ class Grammar extends GrammarAbstract
* Compile on.
*
* @param Builder $query Builder
* @param array $joins Joins
* @param array $ons On values
* @param bool $first Is first on element
*
* @return string
*

View File

@ -158,22 +158,25 @@ final class Localization
foreach ($files as $file) {
if (\stripos($file, $langCode) === 0) {
$this->importLocale(
\json_decode(
\file_get_contents(__DIR__ . '/../Localization/Defaults/Definitions/' . $file),
true
)
);
$fileContent = \file_get_contents(__DIR__ . '/../Localization/Defaults/Definitions/' . $file);
if ($fileContent === false) {
return;
}
$this->importLocale(\json_decode($fileContent, true));
return;
}
}
$this->importLocale(
\json_decode(
\file_get_contents(__DIR__ . '/../Localization/Defaults/Definitions/en_US.json'),
true
)
);
$fileContent = \file_get_contents(__DIR__ . '/../Localization/Defaults/Definitions/en_US.json');
if ($fileContent === false) {
return;
}
$this->importLocale(\json_decode($fileContent, true));
}
/**

View File

@ -76,8 +76,8 @@ final class Polygon implements D2ShapeInterface
/**
* Point polygon relative position
*
* @param array<string, int|float> $point Point location
* @param array<int, array<string, int|float> $polygon Polygon definition
* @param array<string, int|float> $point Point location
* @param array<int, array<string, int|float>> $polygon Polygon definition
*
* @return int -1 inside polygon 0 on vertice 1 outside
*
@ -141,8 +141,8 @@ final class Polygon implements D2ShapeInterface
/**
* Is point on vertex?
*
* @param array<string, int|float> $point Point location
* @param array<int, array<string, int|float> $polygon Polygon definition
* @param array<string, int|float> $point Point location
* @param array<int, array<string, int|float>> $polygon Polygon definition
*
* @return bool
*

View File

@ -381,7 +381,7 @@ class Matrix implements \ArrayAccess, \Iterator
public function setMatrix(array $matrix) : Matrix
{
$this->m = \count($matrix);
$this->n = \count($matrix[0] ?? 1);
$this->n = \count($matrix[0] ?? [1]);
$this->matrix = $matrix;
return $this;

View File

@ -54,7 +54,7 @@ final class Integer
*
* @param int $value Integer to factorize
*
* @return array<int>
* @return array<float|int>
*
* @since 1.0.0
*/

View File

@ -235,6 +235,7 @@ final class MeasureOfDispersion
--$count;
}
/** @var int $count */
$count /= 2;
\sort($x);

View File

@ -117,8 +117,9 @@ class ChiSquaredDistribution
}
}
$key = \key(\end(self::TABLE[$df]));
$p = 1 - ($p ?? ($key === false ? 1 : (float) $key));
$tableCopy = self::TABLE[$df];
$key = \key(\end($tableCopy));
$p = 1 - ($p ?? ($key === false ? 1 : (float) $key));
return ['P' => $p, 'H0' => ($p > $significance), 'df' => $df];
}

View File

@ -168,12 +168,8 @@ final class Request extends RequestAbstract
return 'EN';
}
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
if (\stripos($components[0], ',') !== false) {
$locals = \explode(',', $components[0]);
}
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
$locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components;
$firstLocalComponents = \explode('-', $locals[0]);
return $firstLocalComponents[0];

View File

@ -121,8 +121,8 @@ final class ModuleManager
$files = $this->getUriLoad($request);
$lang = [];
if (isset($files[5])) {
foreach ($files[5] as $module) {
if (isset($files['5'])) {
foreach ($files['5'] as $module) {
$lang[] = '/Modules/' . $module['module_load_from'] . '/Theme/' . $this->app->appName . '/Lang/' . $module['module_load_file'];
}
}
@ -689,8 +689,8 @@ final class ModuleManager
$files = $this->getUriLoad($request);
$modules = [];
if (isset($files[4])) {
foreach ($files[4] as $module) {
if (isset($files['4'])) {
foreach ($files['4'] as $module) {
$modules[] = $module['module_load_file'];
}
}

View File

@ -82,8 +82,8 @@ final class Router
/**
* Route request.
*
* @param string|RequestAbstract $request Request to route
* @param int $verb Route verb
* @param string $request Request to route
* @param int $verb Route verb
*
* @return array[]
*

View File

@ -47,7 +47,7 @@ class Edge
/**
* Is graph/edge directed
*
* @var Node
* @var bool
* @since 1.0.0
*/
private $isDirected = false;

View File

@ -209,7 +209,7 @@ class PriorityQueue implements \Countable, \Serializable
/**
* Pop element.
*
* @return mixed
* @return array
*
* @since 1.0.0
*/

View File

@ -687,7 +687,7 @@ class Repository
* @param \DateTime $start Start date
* @param \DateTime $end End date
*
* @return array<string>
* @return array<Author>
*
* @since 1.0.0
*/
@ -747,7 +747,10 @@ class Repository
foreach ($lines as $line) {
\preg_match('/^[0-9]*/', $line, $matches);
$commits[\substr($line, \strlen($matches[0]) + 1)] = (int) $matches[0];
$temp = \substr($line, \strlen($matches[0]) + 1);
if ($temp !== false) {
$commits[$temp] = (int) $matches[0];
}
}
return $commits;

View File

@ -73,9 +73,9 @@ class ArrayParser
return 'null';
} elseif (\is_scalar($value)) {
return (string) $value;
} elseif ($value instanceOf \Serializable) {
} elseif ($value instanceof \Serializable) {
return self::parseVariable($value->serialize());
} elseif ($value instanceOf \jsonSerializable) {
} elseif ($value instanceof \JsonSerializable) {
return self::parseVariable($value->jsonSerialize());
} else {
throw new \UnexpectedValueException();

View File

@ -46,8 +46,8 @@ final class StringUtils
*
* The validation is done case sensitive.
*
* @param string $haystack Haystack
* @param array<string, float, int> $needles Needles to check if any of them are part of the haystack
* @param string $haystack Haystack
* @param array<string> $needles Needles to check if any of them are part of the haystack
*
* @example StringUtils::contains('This string', ['This', 'test']); // true
*
@ -71,8 +71,8 @@ final class StringUtils
*
* The validation is done case sensitive.
*
* @param string $haystack Haystack
* @param array<string, float, int> $needles Needles to check if any of them are part of the haystack
* @param string $haystack Haystack
* @param array<string> $needles Needles to check if any of them are part of the haystack
*
* @example StringUtils::mb_contains('This string', ['This', 'test']); // true
*

View File

@ -87,7 +87,7 @@ final class TestUtils
*/
public static function getMember(object $obj, string $name)
{
$reflectionClass = new \ReflectionClass(\is_string($obj) ? $obj : \get_class($obj));
$reflectionClass = new \ReflectionClass($obj);
if (!$reflectionClass->hasProperty($name)) {
return null;

View File

@ -151,7 +151,7 @@ class AccountTest extends \PHPUnit\Framework\TestCase
]);
self::assertEquals(4, \count($account->getPermissions()));
self::assertFalse($account->hasPermission(PermissionType::READ, 1, 'a', 1, 1, 1, 1));
self::assertFalse($account->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1));
self::assertTrue($account->hasPermission(PermissionType::NONE));
$account->setL11n(new Localization());

View File

@ -36,8 +36,6 @@ class Autoloader
*
* @return void
*
* @throws AutoloadException Throws this exception if the class to autoload doesn't exist. This could also be related to a wrong namespace/file path correlation.
*
* @since 1.0.0
*/
public static function defaultAutoloader(string $class) : void

View File

@ -40,7 +40,7 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
self::assertEquals($sql, $query->select('a.test', 'b.test')->from('a', 'b')->where('a.test', '=', 'abc')->toSql());
$query = new Builder($this->con);
$datetime = new \Datetime('now');
$datetime = new \DateTime('now');
$sql = 'SELECT `a`.`test`, `b`.`test` FROM `a`, `b` WHERE `a`.`test` = \'' . $datetime->format('Y-m-d H:i:s') . '\';';
self::assertEquals($sql, $query->select('a.test', 'b.test')->from('a', 'b')->where('a.test', '=', $datetime)->toSql());

View File

@ -44,8 +44,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
public function testClosure()
{
$l11nManager = new L11nManager();
$localization = new Localization($l11nManager);
$localization = new Localization();
self::assertTrue(
!empty(
@ -60,8 +59,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
public function testPathMethod()
{
$l11nManager = new L11nManager();
$localization = new Localization($l11nManager);
$localization = new Localization();
self::assertTrue(
!empty(
@ -76,8 +74,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
public function testPathMethodInArray()
{
$l11nManager = new L11nManager();
$localization = new Localization($l11nManager);
$localization = new Localization();
self::assertTrue(
!empty(
@ -92,8 +89,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
public function testPathStatic()
{
$l11nManager = new L11nManager();
$localization = new Localization($l11nManager);
$localization = new Localization();
self::assertTrue(
!empty(
@ -108,8 +104,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
public function testArray()
{
$l11nManager = new L11nManager();
$localization = new Localization($l11nManager);
$localization = new Localization();
self::assertTrue(
!empty(

View File

@ -24,7 +24,7 @@ class ArrayParserTest extends \PHPUnit\Framework\TestCase
public function unserialize($raw) {}
};
$jsonSerialize = new class implements \jsonSerializable {
$jsonSerialize = new class implements \JsonSerializable {
public function jsonSerialize() { return [6, 7]; }
};