fix typehints

This commit is contained in:
Dennis Eichhorn 2020-02-13 18:54:50 +01:00
parent 7835797701
commit 7aa99fa987
16 changed files with 40 additions and 55 deletions

View File

@ -272,9 +272,7 @@ final class Money implements \Serializable
*/
public function mult($value) : self
{
if (\is_float($value) || \is_int($value)) {
$this->value = (int) ($this->value * $value);
}
$this->value = (int) ($this->value * $value);
return $this;
}
@ -290,9 +288,7 @@ final class Money implements \Serializable
*/
public function div($value) : self
{
if (\is_float($value) || \is_int($value)) {
$this->value = (int) ($this->value / $value);
}
$this->value = (int) ($this->value / $value);
return $this;
}
@ -322,9 +318,7 @@ final class Money implements \Serializable
*/
public function pow($value) : self
{
if (\is_float($value) || \is_int($value)) {
$this->value = (int) ($this->value ** $value);
}
$this->value = (int) ($this->value ** $value);
return $this;
}

View File

@ -552,7 +552,7 @@ final class FileLogger implements LoggerInterface
while (($line = \fgetcsv($this->fp, 0, ';')) !== false && $current <= $id) {
++$current;
if ($current < $id) {
if ($current < $id || $line === null) {
continue;
}

View File

@ -24,10 +24,5 @@ namespace phpOMS\Module;
*/
final class NullModule extends ModuleAbstract
{
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct() {}
}

View File

@ -314,7 +314,9 @@ final class PackageManager
\fclose($pipe);
}
\proc_close($resource);
if ($resource !== false) {
\proc_close($resource);
}
}
}
}

View File

@ -16,6 +16,7 @@ namespace phpOMS\Socket\Server;
use phpOMS\Socket\Client\ClientConnection;
use phpOMS\Socket\Client\NullClientConnection;
use phpOMS\Account\NullAccount;
/**
* Client manager class.
@ -72,7 +73,7 @@ class ClientManager
}
}
return new NullClientConnection($id, null);
return new NullClientConnection(new NullAccount(), null);
}
/**

View File

@ -54,7 +54,7 @@ abstract class SocketAbstract implements SocketInterface
* @var resource
* @since 1.0.0
*/
protected $sock = null;
protected $sock;
/**
* {@inheritdoc}
@ -81,10 +81,10 @@ abstract class SocketAbstract implements SocketInterface
*/
public function close() : void
{
if ($this->sock !== null) {
if (isset($this->sock)) {
\socket_shutdown($this->sock, 2);
\socket_close($this->sock);
$this->sock = null;
unset($this->sock);
}
}
}

View File

@ -98,7 +98,7 @@ abstract class Enum
*
* @param string $value Enum value
*
* @return mixed
* @return false|int|string
*
* @since 1.0.0
*/

View File

@ -292,7 +292,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory
* @param resource $con FTP connection
* @param string $path Path of the resource
*
* @return array
* @return array<string, array{permission:int, number:string, user:string, group:string, size:string, month:string, day:string, time:string, type:string}>
*
* @since 1.0.0
*/
@ -302,8 +302,17 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory
$names = \ftp_nlist($con, $path);
$data = [];
if ($names === false || $listData === false) {
return [];
}
foreach ($listData as $key => $item) {
$chunks = \preg_split("/\s+/", $item);
if ($chunks === false) {
continue;
}
list(
$e['permission'],
$e['number'],
@ -313,7 +322,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';

View File

@ -63,18 +63,18 @@ abstract class FileAbstract implements ContainerInterface
/**
* Created at.
*
* @var null|\DateTime
* @var \DateTime
* @since 1.0.0
*/
protected ?\DateTime $createdAt = null;
protected \DateTime $createdAt;
/**
* Last changed at.
*
* @var null|\DateTime
* @var \DateTime
* @since 1.0.0
*/
protected ?\DateTime $changedAt = null;
protected \DateTime $changedAt;
/**
* Owner.

View File

@ -63,18 +63,18 @@ abstract class FileAbstract implements ContainerInterface
/**
* Created at.
*
* @var null|\DateTime
* @var \DateTime
* @since 1.0.0
*/
protected ?\DateTime $createdAt = null;
protected \DateTime $createdAt;
/**
* Last changed at.
*
* @var null|\DateTime
* @var \DateTime
* @since 1.0.0
*/
protected ?\DateTime $changedAt = null;
protected \DateTime $changedAt;
/**
* Owner.

View File

@ -61,7 +61,9 @@ final class Storage
if (\is_string(self::$registered[$env])) {
$instance = new self::$registered[$env]();
self::$registered[$env] = $instance;
} elseif (self::$registered[$env] instanceof StorageAbstract || self::$registered[$env] instanceof ContainerInterface) {
} elseif (self::$registered[$env] instanceof StorageAbstract
|| self::$registered[$env] instanceof ContainerInterface
) {
$instance = self::$registered[$env];
} else {
throw new \Exception('Invalid type');

View File

@ -73,10 +73,6 @@ final class Numeric
$numberLen = \strlen($numberInput);
$newOutput = '';
if ($fromBase === false || $toBase === false || $number === false) {
throw new \Exception();
}
if ($toBaseInput === '0123456789') {
$newOutput = '0';

View File

@ -36,7 +36,7 @@ interface IODatabaseMapper
/**
* Select data from database and store in excel sheet
*
* @param Builder[] $queries Queries to execute
* @param \phpOMS\DataStorage\Database\Query\Builder[] $queries Queries to execute
*
* @return void
*

View File

@ -112,10 +112,6 @@ final class Permutation
*/
public static function permutate($toPermute, array $key)
{
if (!\is_array($toPermute) && !\is_string($toPermute)) {
throw new \InvalidArgumentException('Parameter has to be array or string');
}
$length = \is_array($toPermute) ? \count($toPermute) : \strlen($toPermute);
if (\count($key) > $length) {

View File

@ -526,7 +526,7 @@ class Interval implements \Serializable
*/
public function serialize() : string
{
return \json_encode([
$serialized = \json_encode([
'start' => $this->start->format('Y-m-d H:i:s'),
'end' => $this->end === null ? null : $this->end->format('Y-m-d H:i:s'),
'maxDuration' => $this->maxDuration,
@ -536,6 +536,8 @@ class Interval implements \Serializable
'dayOfWeek' => $this->dayOfWeek,
'year' => $this->year,
]);
return $serialized === false ? '{}' : $serialized;
}
/**

View File

@ -73,18 +73,6 @@ class PermutationTest extends \PHPUnit\Framework\TestCase
self::assertEquals(['c', 'b', 'a'], Permutation::permutate(['a', 'b', 'c'], [2, 1, 1]));
}
/**
* @testdox A invalid permutation type throws a InvalidArgumentException
* @covers phpOMS\Utils\Permutation
* @group framework
*/
public function testWrongPermuteParameterType() : void
{
self::expectException(\InvalidArgumentException::class);
Permutation::permutate(4, [2, 1, 1]);
}
/**
* @testdox A none-existing permutation key throws a OutOfBoundsException
* @covers phpOMS\Utils\Permutation