From 7b1cf0e6601861e612e61e627ef0d74faf24f7ae Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 17 Aug 2019 14:14:58 +0200 Subject: [PATCH] fix after change to php 7.4 --- .../Cache/Connection/ConnectionAbstract.php | 2 +- DataStorage/Cache/Connection/FileCache.php | 2 +- DataStorage/Cache/Connection/RedisCache.php | 4 +- DataStorage/Database/Schema/Builder.php | 36 ++++++++++++ DataStorage/Database/SchemaMapper.php | 7 +++ DataStorage/Session/HttpSession.php | 2 +- Dispatcher/Dispatcher.php | 13 +---- Dispatcher/DispatcherInterface.php | 32 +++++++++++ Event/EventManager.php | 11 ++-- Math/Matrix/Matrix.php | 55 +++++++------------ Module/PackageManager.php | 2 +- Stdlib/Base/Address.php | 4 +- Stdlib/Base/SmartDateTime.php | 2 +- Stdlib/Queue/PriorityQueue.php | 2 +- System/File/Ftp/Directory.php | 2 +- Utils/ArrayUtils.php | 2 +- Utils/Barcode/C128a.php | 2 +- Utils/Barcode/C128b.php | 2 +- Utils/Barcode/C128c.php | 2 +- tests/Dispatcher/DispatcherTest.php | 2 +- tests/Module/ModuleManagerTest.php | 2 +- tests/Module/PackageManagerTest.php | 2 +- tests/Views/ViewTest.php | 2 +- 23 files changed, 124 insertions(+), 68 deletions(-) create mode 100644 Dispatcher/DispatcherInterface.php diff --git a/DataStorage/Cache/Connection/ConnectionAbstract.php b/DataStorage/Cache/Connection/ConnectionAbstract.php index d8c2f507e..b7f5ff7bb 100644 --- a/DataStorage/Cache/Connection/ConnectionAbstract.php +++ b/DataStorage/Cache/Connection/ConnectionAbstract.php @@ -49,7 +49,7 @@ abstract class ConnectionAbstract implements ConnectionInterface * @var string * @since 1.0.0 */ - public string string $prefix = ''; + public string $prefix = ''; /** * Database data. diff --git a/DataStorage/Cache/Connection/FileCache.php b/DataStorage/Cache/Connection/FileCache.php index 1cffdd718..c89ba1ed3 100644 --- a/DataStorage/Cache/Connection/FileCache.php +++ b/DataStorage/Cache/Connection/FileCache.php @@ -45,7 +45,7 @@ class FileCache extends ConnectionAbstract /** * {@inheritdoc} */ - protected $type = CacheType::FILE; + protected string $type = CacheType::FILE; /** * Delimiter for cache meta data diff --git a/DataStorage/Cache/Connection/RedisCache.php b/DataStorage/Cache/Connection/RedisCache.php index 63686e6e0..4bbdbd49c 100644 --- a/DataStorage/Cache/Connection/RedisCache.php +++ b/DataStorage/Cache/Connection/RedisCache.php @@ -74,7 +74,9 @@ class RedisCache extends ConnectionAbstract $this->status = CacheStatus::OK; } - + /** + * {@inheritdoc} + */ public function close() : void { if ($this->con !== null) { diff --git a/DataStorage/Database/Schema/Builder.php b/DataStorage/Database/Schema/Builder.php index a26037910..b86702301 100644 --- a/DataStorage/Database/Schema/Builder.php +++ b/DataStorage/Database/Schema/Builder.php @@ -29,16 +29,52 @@ class Builder extends QueryBuilder { public string $createTable = ''; + /** + * Fields. + * + * @var array + * @since 1.0.0 + */ public array $createFields = []; + /** + * Database to drop. + * + * @var string + * @since 1.0.0 + */ public string $dropDatabase = ''; + /** + * Table to drop. + * + * @var string + * @since 1.0.0 + */ public string $dropTable = ''; + /** + * Tables. + * + * @var array + * @since 1.0.0 + */ public array $selectTables = ['*']; + /** + * Select fields. + * + * @var string + * @since 1.0.0 + */ public string $selectFields = ''; + /** + * @todo: ?????. + * + * @var bool + * @since 1.0.0 + */ public bool $createTableSettings = true; /** diff --git a/DataStorage/Database/SchemaMapper.php b/DataStorage/Database/SchemaMapper.php index c2dd142ad..8f8142fde 100644 --- a/DataStorage/Database/SchemaMapper.php +++ b/DataStorage/Database/SchemaMapper.php @@ -35,6 +35,13 @@ class SchemaMapper */ protected ?ConnectionAbstract $db = null; + /** + * Constructor. + * + * @param ConnectionAbstract $db Database connection + * + * @since 1.0.0 + */ public function __construct(ConnectionAbstract $db) { $this->db = $db; diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index ebfc4137e..475000eb8 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -95,7 +95,7 @@ class HttpSession implements SessionInterface $this->destroy(); } - $this->sessionData = $_SESSION; + $this->sessionData = $_SESSION ?? []; $_SESSION = null; $this->sessionData['lastActivity'] = \time(); $this->sid = \session_id(); diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index f4544d1a7..e9aca281e 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -27,7 +27,7 @@ use phpOMS\System\File\PathException; * @link https://orange-management.org * @since 1.0.0 */ -final class Dispatcher +final class Dispatcher implements DispatcherInterface { /** @@ -61,16 +61,7 @@ final class Dispatcher } /** - * Dispatch controller. - * - * @param array|\Closure|string $controller Controller - * @param null|array|mixed ...$data Data - * - * @return array Returns array of all dispatched results - * - * @throws \UnexpectedValueException This exception is thrown for unsupported controller representations - * - * @since 1.0.0 + * {@inheritdoc} */ public function dispatch($controller, ...$data) : array { diff --git a/Dispatcher/DispatcherInterface.php b/Dispatcher/DispatcherInterface.php new file mode 100644 index 000000000..c751f39cc --- /dev/null +++ b/Dispatcher/DispatcherInterface.php @@ -0,0 +1,32 @@ + + * @var DispatcherInterface|Object * @since 1.0.0 */ - private ?Dispatcher $dispatcher = null; + private ?DispatcherInterface $dispatcher = null; /** * Constructor. @@ -65,10 +66,12 @@ final class EventManager implements \Countable */ public function __construct(Dispatcher $dispatcher = null) { - $this->dispatcher = $dispatcher ?? new class() { - public function dispatch($func, ...$data) : void + $this->dispatcher = $dispatcher ?? new class() implements DispatcherInterface { + public function dispatch($func, ...$data) : array { $func(...$data); + + return []; } }; } diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index c7d4b2df4..a54a529b9 100644 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -301,44 +301,29 @@ class Matrix implements \ArrayAccess, \Iterator $mDim = $this->m; $nDim = $this->n; - if ($this->m > $this->n) { - $mDim = $this->n; - $nDim = $this->m; - $matrix = \array_map(null, ...$matrix); - } + $rank = \max($mDim, $nDim); + $selected = \array_fill(0, $mDim, false); - $rank = $mDim; + for ($i = 0; $i < $nDim; ++$i) { + $j; + for ($j = 0; $j < $mDim; ++$j) { + if (!$selected[$j] && \abs($matrix[$j][$i]) > 0.0001) + break; + } - for ($row = 0; $row < $rank; ++$row) { - if (isset($matrix[$row][$row]) && $matrix[$row][$row] !== 0) { - for ($col = 0; $col < $mDim; ++$col) { - if ($col !== $row) { - $mult = $matrix[$col][$row] / $matrix[$row][$row]; - - for ($i = 0; $i < $rank; ++$i) { - $matrix[$col][$i] -= $mult * $matrix[$row][$i]; - } - } - } + if ($j === $mDim) { + --$rank; } else { - $reduce = true; - - for ($i = $row + 1; $i < $mDim; ++$i) { - if (isset($matrix[$i][$row]) && $matrix[$i][$row] !== 0) { - $this->swapRow($matrix, $row, $i, $rank); - $reduce = false; - break; - } + $selected[$j] = true; + for ($p = $i + 1; $p < $nDim; ++$p) { + $matrix[$j][$p] /= $matrix[$j][$i]; } - if ($reduce) { - --$rank; - - for ($i = 0; $i < $mDim; ++$i) { - $matrix[$i][$row] = $matrix[$i][$rank]; + for ($k = 0; $k < $mDim; ++$k) { + if ($k !== $j && \abs($matrix[$k][$i]) > 0.0001) { + for ($p = $i + 1; $p < $nDim; ++$p) + $matrix[$k][$p] -= $matrix[$j][$p] * $matrix[$k][$i]; } - - --$row; } } } @@ -361,9 +346,9 @@ class Matrix implements \ArrayAccess, \Iterator private function swapRow(array &$matrix, int $row1, int $row2, int $col) : void { for ($i = 0; $i < $col; ++$i) { - $temp = $matrix[$row1][$i]; - $matrix[$row1] = $matrix[$row2][$i]; - $matrix[$row2] = $temp; + $temp = $matrix[$row1][$i]; + $matrix[$row1][$i] = $matrix[$row2][$i]; + $matrix[$row2][$i] = $temp; } } diff --git a/Module/PackageManager.php b/Module/PackageManager.php index 31fe0b5f1..1bafc2630 100644 --- a/Module/PackageManager.php +++ b/Module/PackageManager.php @@ -150,7 +150,7 @@ final class PackageManager $state = \sodium_crypto_generichash_init(); foreach ($files as $file) { - if ($file === 'package.cert') { + if ($file === 'package.cert' || \is_dir($this->extractPath . '/' . $file)) { continue; } diff --git a/Stdlib/Base/Address.php b/Stdlib/Base/Address.php index 8682685a6..2dca46b28 100644 --- a/Stdlib/Base/Address.php +++ b/Stdlib/Base/Address.php @@ -44,10 +44,10 @@ class Address implements \JsonSerializable /** * Location. * - * @var Location + * @var null|Location * @since 1.0.0 */ - private Location $location = null; + private ?Location $location = null; /** * Constructor. diff --git a/Stdlib/Base/SmartDateTime.php b/Stdlib/Base/SmartDateTime.php index 3d4da58c4..8ff02c6c4 100644 --- a/Stdlib/Base/SmartDateTime.php +++ b/Stdlib/Base/SmartDateTime.php @@ -96,7 +96,7 @@ class SmartDateTime extends \DateTime $yearChange = ((int) $this->format('m') - 1 + $m) < 0 && ((int) $this->format('m') - 1 + $m) % 12 === 0 ? $yearChange - 1 : $yearChange; $yearNew = (int) $this->format('Y') + $y + $yearChange; $monthNew = ((int) $this->format('m') + $m) % 12; - $monthNew = $monthNew === 0 ? 12 : $monthNew < 0 ? 12 + $monthNew : $monthNew; + $monthNew = $monthNew === 0 ? 12 : ($monthNew < 0 ? 12 + $monthNew : $monthNew); $dayMonthOld = \cal_days_in_month($calendar, (int) $this->format('m'), (int) $this->format('Y')); $dayMonthNew = \cal_days_in_month($calendar, $monthNew, $yearNew); $dayOld = (int) $this->format('d'); diff --git a/Stdlib/Queue/PriorityQueue.php b/Stdlib/Queue/PriorityQueue.php index 1e3d54760..65446097d 100644 --- a/Stdlib/Queue/PriorityQueue.php +++ b/Stdlib/Queue/PriorityQueue.php @@ -329,6 +329,6 @@ class PriorityQueue implements \Countable, \Serializable */ public function unserialize($data) : void { - $this->queue = \json_decode($data); + $this->queue = \json_decode($data, true); } } diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 402f94e2a..dfcba6b8f 100644 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -310,7 +310,7 @@ class Directory extends FileAbstract implements FtpContainerInterface, Directory ) = $chunks; $e['permission'] = FileUtils::permissionToOctal(\substr($e['permission'], 1)); - $e['type'] = $chunks[0]{0} === 'd' ? 'dir' : 'file'; + $e['type'] = $chunks[0][0] === 'd' ? 'dir' : 'file'; $data[$names[$key]] = $e; } diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 559ca6dd4..400e501e0 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -255,7 +255,7 @@ final class ArrayUtils $str .= $key . ' => \'' . $value . '\', '; break; case 'boolean': - $str .= $key . ' => ' . ($value['default'] ? 'true' : 'false') . ', '; + $str .= $key . ' => ' . ($value ? 'true' : 'false') . ', '; break; case 'NULL': $str .= $key . ' => null, '; diff --git a/Utils/Barcode/C128a.php b/Utils/Barcode/C128a.php index 817015d7c..c28bd426b 100644 --- a/Utils/Barcode/C128a.php +++ b/Utils/Barcode/C128a.php @@ -33,7 +33,7 @@ class C128a extends C128Abstract * @var int * @since 1.0.0 */ - protected static $CHECKSUM = 103; + protected static int $CHECKSUM = 103; /** * Char weighted array. diff --git a/Utils/Barcode/C128b.php b/Utils/Barcode/C128b.php index 6ea9647c3..c6b91763b 100644 --- a/Utils/Barcode/C128b.php +++ b/Utils/Barcode/C128b.php @@ -33,7 +33,7 @@ class C128b extends C128Abstract * @var int * @since 1.0.0 */ - protected static $CHECKSUM = 104; + protected static int $CHECKSUM = 104; /** * Char weighted array. diff --git a/Utils/Barcode/C128c.php b/Utils/Barcode/C128c.php index 8a9394ce2..ce0a32bc2 100644 --- a/Utils/Barcode/C128c.php +++ b/Utils/Barcode/C128c.php @@ -33,7 +33,7 @@ class C128c extends C128Abstract * @var int * @since 1.0.0 */ - protected static $CHECKSUM = 105; + protected static int $CHECKSUM = 105; /** * Char weighted array. diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php index cf569ccfe..f83e306a8 100644 --- a/tests/Dispatcher/DispatcherTest.php +++ b/tests/Dispatcher/DispatcherTest.php @@ -33,7 +33,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase protected function setUp() : void { - $this->app = new class() extends ApplicationAbstract { protected $appName = 'Api'; }; + $this->app = new class() extends ApplicationAbstract { protected string $appName = 'Api'; }; $this->app->router = new Router(); $this->app->dispatcher = new Dispatcher($this->app); } diff --git a/tests/Module/ModuleManagerTest.php b/tests/Module/ModuleManagerTest.php index 728de6898..a3993f6b4 100644 --- a/tests/Module/ModuleManagerTest.php +++ b/tests/Module/ModuleManagerTest.php @@ -30,7 +30,7 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase protected function setUp() : void { - $this->app = new class() extends ApplicationAbstract { protected $appName = 'Api'; }; + $this->app = new class() extends ApplicationAbstract { protected string $appName = 'Api'; }; $this->app->appName = 'Api'; $this->app->dbPool = $GLOBALS['dbpool']; $this->app->dispatcher = new Dispatcher($this->app); diff --git a/tests/Module/PackageManagerTest.php b/tests/Module/PackageManagerTest.php index 1922f9103..5e555e36b 100644 --- a/tests/Module/PackageManagerTest.php +++ b/tests/Module/PackageManagerTest.php @@ -52,7 +52,7 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase $state = \sodium_crypto_generichash_init(); foreach ($files as $file) { - if ($file === 'package.cert') { + if ($file === 'package.cert' || \is_dir(__DIR__ . '/testPackage' . '/' . $file)) { continue; } diff --git a/tests/Views/ViewTest.php b/tests/Views/ViewTest.php index a5693e854..ca4eb528b 100644 --- a/tests/Views/ViewTest.php +++ b/tests/Views/ViewTest.php @@ -43,7 +43,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase $this->app = new class() extends ApplicationAbstract { - protected $appName = 'Api'; + protected string $appName = 'Api'; }; $this->app->l11nManager = new L11nManager($this->app->appName);