diff --git a/Account/Account.php b/Account/Account.php index 98a9557c7..efed51bb9 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -215,6 +215,20 @@ class Account implements ArrayableInterface, \JsonSerializable return $this->groups; } + /** + * Add group. + * + * @param mixed $group Group to add + * + * @return void + * + * @since 1.0.0 + */ + public function addGroup($group) /* : void */ + { + $this->groups[] = $group; + } + /** * Set localization. * @@ -258,7 +272,7 @@ class Account implements ArrayableInterface, \JsonSerializable */ public function addPermissions(array $permissions) /* : void */ { - $this->permissions += $permissions; + $this->permissions = array_merge($this->permissions, $permissions); } /** @@ -277,6 +291,18 @@ class Account implements ArrayableInterface, \JsonSerializable $this->permissions[] = $permission; } + /** + * Get permissions. + * + * @return array + * + * @since 1.0.0 + */ + public function getPermissions() : array + { + return $this->permissions; + } + /** * Has permissions. * diff --git a/Auth/Auth.php b/Auth/Auth.php index 581d5a452..0f1a06395 100644 --- a/Auth/Auth.php +++ b/Auth/Auth.php @@ -62,11 +62,7 @@ class Auth { $uid = $this->session->get('UID'); - if (empty($uid)) { - return 0; - } - - return $uid; + return empty($uid) ? 0 : $uid; } /** diff --git a/DataStorage/Cookie/CookieJar.php b/DataStorage/Cookie/CookieJar.php index 4ee0e663b..2124a8d4f 100644 --- a/DataStorage/Cookie/CookieJar.php +++ b/DataStorage/Cookie/CookieJar.php @@ -127,9 +127,13 @@ class CookieJar throw new LockException('CookieJar'); } - setcookie($id, '', time() - 3600); + if(!headers_sent()) { + setcookie($id, '', time() - 3600); - return true; + return true; + } + + return false; } return false; diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index dddbf63db..8c7e7abd6 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -174,6 +174,7 @@ class DataMapperAbstract implements DataMapperInterface * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { @@ -185,6 +186,7 @@ class DataMapperAbstract implements DataMapperInterface * @return void * * @since 1.0.0 + * @codeCoverageIgnore */ private function __clone() { diff --git a/DataStorage/Database/DataMapperBaseAbstract.php b/DataStorage/Database/DataMapperBaseAbstract.php index ac9d69f50..5974cd0a4 100644 --- a/DataStorage/Database/DataMapperBaseAbstract.php +++ b/DataStorage/Database/DataMapperBaseAbstract.php @@ -171,6 +171,7 @@ class DataMapperBaseAbstract * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { @@ -182,6 +183,7 @@ class DataMapperBaseAbstract * @return void * * @since 1.0.0 + * @codeCoverageIgnore */ private function __clone() { diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 725511b0e..d60735bf5 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -545,14 +545,9 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function andWhere(Where $where) : Builder + public function andWhere($where, $operator = null, $values = null) : Builder { - $this->wheres[][] = [ - 'column' => $where, - 'boolean' => 'and', - ]; - - return $this; + return $this->where($where, $operator, $values, 'and'); } /** @@ -564,14 +559,9 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function orWhere(Where $where) : Builder + public function orWhere($where, $operator = null, $values = null) : Builder { - $this->wheres[][] = [ - 'column' => $where, - 'boolean' => 'or', - ]; - - return $this; + return $this->where($where, $operator, $values, 'or'); } /** @@ -693,10 +683,14 @@ class Builder extends BuilderAbstract public function orderBy($columns, $order = 'DESC') : Builder { if (is_string($columns) || $columns instanceof \Closure) { - $this->orders[] = ['column' => $columns, 'order' => $order]; + if(!isset($this->orders[$order])) { + $this->orders[$order] = []; + } + + $this->orders[$order][] = $columns; } elseif (is_array($columns)) { foreach ($columns as $key => $column) { - $this->orders[] = ['column' => $column, 'order' => $order[$key]]; + $this->orders[is_string($order) ? $order : $order[$key]][] = $column; } } else { throw new \InvalidArgumentException(); diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 35cac7a99..ae77081aa 100644 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -288,6 +288,9 @@ class Grammar extends GrammarAbstract if (isset($element['value'])) { $expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix()); + } else { + $operator = strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT'; + $expression .= ' ' . $operator . ' ' . $this->compileValue($element['value'], $query->getPrefix()); } return $expression; @@ -416,8 +419,13 @@ class Grammar extends GrammarAbstract { $expression = ''; - foreach ($orders as $order) { - $expression .= $this->compileSystem($order['column'], $query->getPrefix()) . ' ' . $order['order'] . ', '; + foreach ($orders as $key => $order) { + foreach($order as $column) { + $expression .= $this->compileSystem($column, $query->getPrefix()) . ', '; + } + + $expression = rtrim($expression, ', '); + $expression .= ' ' . $key . ', '; } if ($expression === '') { diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 05a33847c..8101b7553 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -86,8 +86,10 @@ class HttpSession implements SessionInterface $this->inactivityInterval = $inactivityInterval; - session_set_cookie_params($liftetime, '/', '', false, true); - session_start(); + if(session_status() !== PHP_SESSION_ACTIVE && !headers_sent()) { + session_set_cookie_params($liftetime, '/', '', false, true); + session_start(); + } if($this->inactivityInterval > 0 && ($this->inactivityInterval + ($_SESSION['lastActivity'] ?? 0) < time())) { $this->destroy(); diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 230df4ad0..4f2440a09 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -150,6 +150,7 @@ class FileLogger implements LoggerInterface * Closes the logging file * * @since 1.0.0 + * @codeCoverageIgnore */ public function __destruct() { @@ -162,6 +163,7 @@ class FileLogger implements LoggerInterface * Protect instance from getting copied from outside. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __clone() { diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 758da8aa0..53eb4408e 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -67,12 +67,12 @@ class Request extends RequestAbstract /** * Constructor. * - * @param Localization $l11n Localization * @param UriInterface $uri Uri + * @param Localization $l11n Localization * * @since 1.0.0 */ - public function __construct(Localization $l11n = null, UriInterface $uri = null) + public function __construct(UriInterface $uri = null, Localization $l11n = null) { $this->header = new Header(); $this->header->setL11n($l11n ?? new Localization()); @@ -193,15 +193,13 @@ class Request extends RequestAbstract /** * Create request from super globals. * - * @param Localization $l11n Localization - * * @return Request * * @since 1.0.0 */ - public static function createFromSuperglobals(Localization $l11n = null) : Request + public static function createFromSuperglobals() : Request { - return new self($l11n); + return new self(); } /** diff --git a/Message/Http/Response.php b/Message/Http/Response.php index 426e569c9..0b8a5020a 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -47,10 +47,10 @@ class Response extends ResponseAbstract implements RenderableInterface * * @since 1.0.0 */ - public function __construct(Localization $l11n) + public function __construct(Localization $l11n = null) { $this->header = new Header(); - $this->header->setL11n($l11n); + $this->header->setL11n($l11n ?? new Localization()); } /** diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 787d3ef47..8e4aa87dc 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -107,15 +107,6 @@ abstract class ModuleAbstract $this->app = $app; } - /** - * Install external. - * - * @since 1.0.0 - */ - public static function installExternal() /* : void */ - { - } - /** * Get language files. * @@ -171,16 +162,4 @@ abstract class ModuleAbstract /** @noinspection PhpUndefinedFieldInspection */ return static::$dependencies; } - - /** - * Get event id prefix. - * - * @return string - * - * @since 1.0.0 - */ - public function getEventId() : string - { - return static::class; - } } diff --git a/Module/ModuleFactory.php b/Module/ModuleFactory.php index ad5ca06ab..338d2852d 100644 --- a/Module/ModuleFactory.php +++ b/Module/ModuleFactory.php @@ -54,6 +54,7 @@ class ModuleFactory * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index b59bf5d56..d1bd645b9 100644 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -40,6 +40,7 @@ class FileUtils * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/System/File/Storage.php b/System/File/Storage.php index 17a4f52e8..f9e3ab017 100644 --- a/System/File/Storage.php +++ b/System/File/Storage.php @@ -40,6 +40,7 @@ final class Storage * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/System/File/StorageAbstract.php b/System/File/StorageAbstract.php index 58dd135cb..215930f6c 100644 --- a/System/File/StorageAbstract.php +++ b/System/File/StorageAbstract.php @@ -40,6 +40,7 @@ abstract class StorageAbstract * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/System/SystemUtils.php b/System/SystemUtils.php index a900baef4..e7e80cc49 100644 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -31,6 +31,7 @@ class SystemUtils * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/UnhandledHandler.php b/UnhandledHandler.php index 3babe913a..c7595be84 100644 --- a/UnhandledHandler.php +++ b/UnhandledHandler.php @@ -35,6 +35,7 @@ final class UnhandledHandler * @return void * * @since 1.0.0 + * @codeCoverageIgnore */ public static function exceptionHandler(\Throwable $e) /* : void */ { @@ -92,6 +93,7 @@ final class UnhandledHandler * @return void * * @since 1.0.0 + * @codeCoverageIgnore */ public static function shutdownHandler() /* : void */ { diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index d75f968dd..1e08c1d75 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -41,6 +41,7 @@ class UriFactory * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 814d4a3b9..0f66a1faf 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -31,6 +31,7 @@ class ArrayUtils * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index 1c319bb2d..06be05c61 100644 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -46,6 +46,7 @@ class Currency * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { @@ -97,7 +98,7 @@ class Currency public static function getEcbEuroRates() : array { if (!isset(self::$ecbCurrencies)) { - $request = new Request(new Localization(), new Http('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')); + $request = new Request(new Http('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')); $request->setMethod(RequestMethod::GET); $xml = new \SimpleXMLElement(Rest::request($request)); diff --git a/Utils/Converter/File.php b/Utils/Converter/File.php index 427db21d6..14430409c 100644 --- a/Utils/Converter/File.php +++ b/Utils/Converter/File.php @@ -31,6 +31,7 @@ class File * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Utils/Converter/Ip.php b/Utils/Converter/Ip.php index 7c66b7ce9..87fa6c88e 100644 --- a/Utils/Converter/Ip.php +++ b/Utils/Converter/Ip.php @@ -28,6 +28,12 @@ class Ip { /* public */ const IP_TABLE_ITERATIONS = 100; + /** + * Constructor. + * + * @since 1.0.0 + * @codeCoverageIgnore + */ private function __construct() { } diff --git a/Utils/Encoding/Huffman/Dictionary.php b/Utils/Encoding/Huffman/Dictionary.php index 403c5a0dc..6af369bec 100644 --- a/Utils/Encoding/Huffman/Dictionary.php +++ b/Utils/Encoding/Huffman/Dictionary.php @@ -59,7 +59,7 @@ final class Dictionary */ public function __construct(string $source = '') { - if (isset($source)) { + if (!empty($source)) { $this->generate($source); } } @@ -139,15 +139,15 @@ final class Dictionary public function set(string $entry, string $value) /* : void */ { if (strlen($entry) !== 1) { - throw new \Exception('Must be a character.'); + throw new \InvalidArgumentException('Must be a character.'); } if (isset($this->dictionary[$entry])) { - throw new \Exception('Character already exists'); + throw new \InvalidArgumentException('Character already exists'); } if (strlen(str_replace('0', '', str_replace('1', '', $value))) !== 0) { - throw new \Exception('Bad formatting.'); + throw new \InvalidArgumentException('Bad formatting.'); } $length = strlen($value); @@ -177,11 +177,11 @@ final class Dictionary public function get(string $entry) : string { if (strlen($entry) !== 1) { - throw new \Exception('Must be a character.'); + throw new \InvalidArgumentException('Must be a character.'); } if (!isset($this->dictionary[$entry])) { - throw new \Exception('Character does not exist'); + throw new \InvalidArgumentException('Character does not exist'); } return $this->dictionary[$entry]; diff --git a/Utils/Encoding/Huffman/Huffman.php b/Utils/Encoding/Huffman/Huffman.php index 7ce41d93e..165879c0d 100644 --- a/Utils/Encoding/Huffman/Huffman.php +++ b/Utils/Encoding/Huffman/Huffman.php @@ -51,7 +51,7 @@ final class Huffman * * @since 1.0.0 */ - public function getDictionary() : Dictionary + public function getDictionary() /* : ?Dictionary */ { return $this->dictionary; } diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index c9e1cdc6f..8b9df87fd 100644 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -35,6 +35,7 @@ class StringUtils * This class is purely static and is preventing any initialization * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Validation/Finance/Iban.php b/Validation/Finance/Iban.php index a7db7f591..a0479f372 100644 --- a/Validation/Finance/Iban.php +++ b/Validation/Finance/Iban.php @@ -33,6 +33,7 @@ abstract class Iban extends ValidatorAbstract * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Validation/Network/Email.php b/Validation/Network/Email.php index f474ac3e0..30afa77c2 100644 --- a/Validation/Network/Email.php +++ b/Validation/Network/Email.php @@ -33,6 +33,7 @@ class Email extends ValidatorAbstract * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Validation/Network/Hostname.php b/Validation/Network/Hostname.php index 5d64b4c3b..cc0ca5c1d 100644 --- a/Validation/Network/Hostname.php +++ b/Validation/Network/Hostname.php @@ -33,8 +33,9 @@ abstract class Hostname extends ValidatorAbstract * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ - public function __construct() + private function __construct() { } diff --git a/Validation/Network/Ip.php b/Validation/Network/Ip.php index 67cb3a2e0..3289b6872 100644 --- a/Validation/Network/Ip.php +++ b/Validation/Network/Ip.php @@ -33,6 +33,7 @@ class Ip extends ValidatorAbstract * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Version/Version.php b/Version/Version.php index e202faf5d..2f5cc2b8d 100644 --- a/Version/Version.php +++ b/Version/Version.php @@ -33,6 +33,7 @@ class Version * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index 35e9a7b5f..c7bb3cbeb 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -145,22 +145,6 @@ abstract class ViewAbstract implements \Serializable return false; } - /** - * Edit view. - * - * @param string $id View ID - * @param View $view - * @param null|int $order Order of view - * - * @return void - * - * @since 1.0.0 - */ - public function editView(string $id, View $view, $order = null) /* : void */ - { - $this->addView($id, $view, $order, true); - } - /** * Add view. * @@ -247,11 +231,11 @@ abstract class ViewAbstract implements \Serializable try { ob_start(); /** @noinspection PhpIncludeInspection */ - $data = include $path; + $includeData = include $path; $ob = ob_get_clean(); - if (is_array($data)) { - return $data; + if (is_array($includeData)) { + return $includeData; } } catch(\Throwable $e) { $ob = ''; @@ -268,10 +252,10 @@ abstract class ViewAbstract implements \Serializable * @return void * * @since 1.0.0 + * @codeCoverageIgnore */ public function unserialize($raw) { - // todo: implement } }