mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
More type fixes
This commit is contained in:
parent
adf83f0867
commit
23eb9ab80a
|
|
@ -43,7 +43,7 @@ final class Iban
|
|||
/**
|
||||
* Iban chars.
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $chars = 2;
|
||||
|
|
|
|||
|
|
@ -107,6 +107,11 @@ final class Money implements \Serializable
|
|||
public static function toInt(string $value, string $thousands = ',', string $decimal = '.') : int
|
||||
{
|
||||
$split = \explode($decimal, $value);
|
||||
|
||||
if ($split === false) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$left = $split[0];
|
||||
$left = \str_replace($thousands, '', $left);
|
||||
$right = '';
|
||||
|
|
@ -115,9 +120,9 @@ final class Money implements \Serializable
|
|||
$right = $split[1];
|
||||
}
|
||||
|
||||
$right = substr($right, 0, self::MAX_DECIMALS);
|
||||
$right = \substr($right, 0, self::MAX_DECIMALS);
|
||||
|
||||
return ((int) $left) * 10 ** self::MAX_DECIMALS + (int) str_pad($right, self::MAX_DECIMALS, '0');
|
||||
return ((int) $left) * 10 ** self::MAX_DECIMALS + (int) \str_pad($right, self::MAX_DECIMALS, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,10 +190,10 @@ final class Money implements \Serializable
|
|||
{
|
||||
$value = (string) round($this->value, -self::MAX_DECIMALS + $decimals);
|
||||
|
||||
$left = substr($value, 0, -self::MAX_DECIMALS);
|
||||
$right = substr($value, -self::MAX_DECIMALS);
|
||||
$left = \substr($value, 0, -self::MAX_DECIMALS);
|
||||
$right = \substr($value, -self::MAX_DECIMALS);
|
||||
|
||||
return ($decimals > 0) ? number_format((float) $left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left;
|
||||
return ($decimals > 0) ? number_format((float) $left, 0, $this->decimal, $this->thousands) . $this->decimal . \substr($right, 0, $decimals) : $left;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,7 +314,7 @@ final class Money implements \Serializable
|
|||
public function pow($value) : Money
|
||||
{
|
||||
if (is_float($value) || is_int($value)) {
|
||||
$this->value = $this->value ** $value;
|
||||
$this->value = (int) ($this->value ** $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ final class FileLogger implements LoggerInterface
|
|||
*/
|
||||
public function __construct(string $lpath, bool $verbose = false)
|
||||
{
|
||||
$path = realpath($lpath);
|
||||
$path = \realpath($lpath);
|
||||
$this->verbose = $verbose;
|
||||
|
||||
if (is_dir($lpath) || strpos($lpath, '.') === false) {
|
||||
if (\is_dir($lpath) || \strpos($lpath, '.') === false) {
|
||||
$path = $lpath . '/' . date('Y-m-d') . '.log';
|
||||
} else {
|
||||
$path = $lpath;
|
||||
|
|
@ -155,7 +155,7 @@ final class FileLogger implements LoggerInterface
|
|||
public function __destruct()
|
||||
{
|
||||
if (is_resource($this->fp)) {
|
||||
fclose($this->fp);
|
||||
\fclose($this->fp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ final class FileLogger implements LoggerInterface
|
|||
}
|
||||
|
||||
$mtime = \explode(' ', microtime());
|
||||
$mtime = $mtime[1] + $mtime[0];
|
||||
$mtime = (int) $mtime[1] + (int) $mtime[0];
|
||||
|
||||
self::$timings[$id] = ['start' => $mtime];
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ final class FileLogger implements LoggerInterface
|
|||
public static function endTimeLog($id = '') : float
|
||||
{
|
||||
$mtime = \explode(' ', microtime());
|
||||
$mtime = $mtime[1] + $mtime[0];
|
||||
$mtime = (int) $mtime[1] + (int) $mtime[0];
|
||||
|
||||
self::$timings[$id]['end'] = $mtime;
|
||||
self::$timings[$id]['time'] = $mtime - self::$timings[$id]['start'];
|
||||
|
|
@ -267,17 +267,17 @@ final class FileLogger implements LoggerInterface
|
|||
private function write(string $message) : void
|
||||
{
|
||||
$this->createFile();
|
||||
if (!is_writable($this->path)) {
|
||||
if (!\is_writable($this->path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fp = fopen($this->path, 'a');
|
||||
$this->fp = \fopen($this->path, 'a');
|
||||
|
||||
if (flock($this->fp, LOCK_EX) && $this->fp !== false) {
|
||||
fwrite($this->fp, $message . "\n");
|
||||
fflush($this->fp);
|
||||
flock($this->fp, LOCK_UN);
|
||||
fclose($this->fp);
|
||||
if ($this->fp !== false && \flock($this->fp, LOCK_EX)) {
|
||||
\fwrite($this->fp, $message . "\n");
|
||||
\fflush($this->fp);
|
||||
\flock($this->fp, LOCK_UN);
|
||||
\fclose($this->fp);
|
||||
$this->fp = false;
|
||||
}
|
||||
|
||||
|
|
@ -386,10 +386,15 @@ final class FileLogger implements LoggerInterface
|
|||
return $levels;
|
||||
}
|
||||
|
||||
$this->fp = fopen($this->path, 'r');
|
||||
fseek($this->fp, 0);
|
||||
$this->fp = \fopen($this->path, 'r');
|
||||
|
||||
while (($line = fgetcsv($this->fp, 0, ';')) !== false) {
|
||||
if ($this->fp === false) {
|
||||
return $levels;
|
||||
}
|
||||
|
||||
\fseek($this->fp, 0);
|
||||
|
||||
while (($line = \fgetcsv($this->fp, 0, ';')) !== false) {
|
||||
$line[1] = trim($line[1]);
|
||||
|
||||
if (!isset($levels[$line[1]])) {
|
||||
|
|
@ -399,8 +404,8 @@ final class FileLogger implements LoggerInterface
|
|||
$levels[$line[1]]++;
|
||||
}
|
||||
|
||||
fseek($this->fp, 0, SEEK_END);
|
||||
fclose($this->fp);
|
||||
\fseek($this->fp, 0, SEEK_END);
|
||||
\fclose($this->fp);
|
||||
|
||||
return $levels;
|
||||
}
|
||||
|
|
@ -422,10 +427,15 @@ final class FileLogger implements LoggerInterface
|
|||
return $connection;
|
||||
}
|
||||
|
||||
$this->fp = fopen($this->path, 'r');
|
||||
fseek($this->fp, 0);
|
||||
$this->fp = \fopen($this->path, 'r');
|
||||
|
||||
while (($line = fgetcsv($this->fp, 0, ';')) !== false) {
|
||||
if ($this->fp === false) {
|
||||
return $connection;
|
||||
}
|
||||
|
||||
\fseek($this->fp, 0);
|
||||
|
||||
while (($line = \fgetcsv($this->fp, 0, ';')) !== false) {
|
||||
$line[2] = trim($line[2]);
|
||||
|
||||
if (!isset($connection[$line[2]])) {
|
||||
|
|
@ -435,8 +445,8 @@ final class FileLogger implements LoggerInterface
|
|||
$connection[$line[2]]++;
|
||||
}
|
||||
|
||||
fseek($this->fp, 0, SEEK_END);
|
||||
fclose($this->fp);
|
||||
\fseek($this->fp, 0, SEEK_END);
|
||||
\fclose($this->fp);
|
||||
asort($connection);
|
||||
|
||||
return array_slice($connection, 0, $limit);
|
||||
|
|
@ -461,10 +471,16 @@ final class FileLogger implements LoggerInterface
|
|||
return $logs;
|
||||
}
|
||||
|
||||
$this->fp = fopen($this->path, 'r');
|
||||
fseek($this->fp, 0);
|
||||
$this->fp = \fopen($this->path, 'r');
|
||||
|
||||
while (($line = fgetcsv($this->fp, 0, ';')) !== false) {
|
||||
if ($this->fp === false) {
|
||||
return $logs;
|
||||
}
|
||||
|
||||
\fseek($this->fp, 0);
|
||||
|
||||
$line = \fgetcsv($this->fp, 0, ';');
|
||||
while ($line !== false && $line !== null) {
|
||||
$id++;
|
||||
|
||||
if ($offset > 0) {
|
||||
|
|
@ -484,10 +500,11 @@ final class FileLogger implements LoggerInterface
|
|||
$logs[$id] = $line;
|
||||
$limit--;
|
||||
ksort($logs);
|
||||
$line = \fgetcsv($this->fp, 0, ';');
|
||||
}
|
||||
|
||||
fseek($this->fp, 0, SEEK_END);
|
||||
fclose($this->fp);
|
||||
\fseek($this->fp, 0, SEEK_END);
|
||||
\fclose($this->fp);
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
|
@ -510,10 +527,15 @@ final class FileLogger implements LoggerInterface
|
|||
return $log;
|
||||
}
|
||||
|
||||
$this->fp = fopen($this->path, 'r');
|
||||
fseek($this->fp, 0);
|
||||
$this->fp = \fopen($this->path, 'r');
|
||||
|
||||
while (($line = fgetcsv($this->fp, 0, ';')) !== false && $current <= $id) {
|
||||
if ($this->fp === false) {
|
||||
return $log;
|
||||
}
|
||||
|
||||
\fseek($this->fp, 0);
|
||||
|
||||
while (($line = \fgetcsv($this->fp, 0, ';')) !== false && $current <= $id) {
|
||||
$current++;
|
||||
|
||||
if ($current < $id) {
|
||||
|
|
@ -533,8 +555,8 @@ final class FileLogger implements LoggerInterface
|
|||
break;
|
||||
}
|
||||
|
||||
fseek($this->fp, 0, SEEK_END);
|
||||
fclose($this->fp);
|
||||
\fseek($this->fp, 0, SEEK_END);
|
||||
\fclose($this->fp);
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,13 +27,12 @@ final class ZeroDevisionException extends \UnexpectedValueException
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
|
||||
public function __construct(int $code = 0, \Exception $previous = null)
|
||||
{
|
||||
parent::__construct('Devision by zero is not defined.', $code, $previous);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -315,6 +315,6 @@ final class Functions
|
|||
*/
|
||||
public static function getRelativeDegree(int $value, int $length, int $start = 0) : int
|
||||
{
|
||||
return (int) abs(self::mod($value - $start, $length));
|
||||
return abs(self::mod($value - $start, $length));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ final class Polygon implements D2ShapeInterface
|
|||
*/
|
||||
public function getSurface() : float
|
||||
{
|
||||
return (float) abs($this->getSignedSurface());
|
||||
return abs($this->getSignedSurface());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ final class Sphere implements D3ShapeInterface
|
|||
*/
|
||||
public static function getRadiusByVolume(float $v) : float
|
||||
{
|
||||
return (float) pow($v * 3 / (4 * pi()), 1 / 3);
|
||||
return pow($v * 3 / (4 * pi()), 1 / 3);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
{
|
||||
if ($value instanceof Matrix) {
|
||||
return $this->add($value->mult(-1));
|
||||
} elseif (is_numeric($value)) {
|
||||
} elseif (!is_string($value) && is_numeric($value)) {
|
||||
return $this->add(-$value);
|
||||
}
|
||||
|
||||
|
|
@ -424,7 +424,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
{
|
||||
if ($value instanceof Matrix) {
|
||||
return $this->addMatrix($value);
|
||||
} elseif (is_numeric($value)) {
|
||||
} elseif (!is_string($value) && is_numeric($value)) {
|
||||
return $this->addScalar($value);
|
||||
}
|
||||
|
||||
|
|
@ -529,7 +529,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
{
|
||||
if ($value instanceof Matrix) {
|
||||
return $this->multMatrix($value);
|
||||
} elseif (is_numeric($value)) {
|
||||
} elseif (!is_string($value) && is_numeric($value)) {
|
||||
return $this->multScalar($value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ final class Integer
|
|||
}
|
||||
}
|
||||
|
||||
return (int) $m;
|
||||
return $m;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -160,13 +160,13 @@ final class Integer
|
|||
}
|
||||
|
||||
$a = (int) ceil(sqrt($value));
|
||||
$b2 = (int) ($a * $a - $value);
|
||||
$b2 = ($a * $a - $value);
|
||||
$i = 1;
|
||||
|
||||
while (!Numbers::isSquare($b2) && $i < $limit) {
|
||||
$i++;
|
||||
$a += 1;
|
||||
$b2 = (int) ($a * $a - $value);
|
||||
$b2 = ($a * $a - $value);
|
||||
}
|
||||
|
||||
return [(int) round($a - sqrt($b2)), (int) round($a + sqrt($b2))];
|
||||
|
|
|
|||
|
|
@ -69,10 +69,14 @@ final class Numbers
|
|||
public static function isSelfdescribing(int $n) : bool
|
||||
{
|
||||
$n = (string) $n;
|
||||
$split = str_split($n);
|
||||
$split = \str_split($n);
|
||||
|
||||
if ($split === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($split as $place => $value) {
|
||||
if (substr_count($n, (string) $place) != $value) {
|
||||
if (\substr_count($n, (string) $place) != $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ final class Average
|
|||
*
|
||||
* @return float
|
||||
*
|
||||
* @throws phpOMS\Math\Exception\ZeroDevisionException
|
||||
* @throws ZeroDevisionException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -252,7 +252,7 @@ final class Average
|
|||
throw new ZeroDevisionException();
|
||||
}
|
||||
|
||||
return (float) pow(array_product($values), 1 / $count);
|
||||
return pow(\array_product($values), 1 / $count);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user