diff --git a/ApplicationAbstract.php b/ApplicationAbstract.php index ff664c6be..49806be39 100644 --- a/ApplicationAbstract.php +++ b/ApplicationAbstract.php @@ -84,106 +84,106 @@ class ApplicationAbstract /** * Database object. * - * @var null|DatabasePool + * @var DatabasePool * @since 1.0.0 */ - protected ?DatabasePool $dbPool = null; + protected DatabasePool $dbPool; /** * Application settings object. * - * @var null|CoreSettings + * @var CoreSettings * @since 1.0.0 */ - protected ?CoreSettings $appSettings = null; + protected CoreSettings $appSettings; /** * Account manager instance. * - * @var null|AccountManager + * @var AccountManager * @since 1.0.0 */ - protected ?AccountManager $accountManager = null; + protected AccountManager $accountManager; /** * Cache instance. * - * @var null|CachePool + * @var CachePool * @since 1.0.0 */ - protected ?CachePool $cachePool = null; + protected CachePool $cachePool; /** * ModuleManager instance. * - * @var null|ModuleManager + * @var ModuleManager * @since 1.0.0 */ - protected ?ModuleManager $moduleManager = null; + protected ModuleManager $moduleManager; /** * Router instance. * - * @var null|RouterInterface + * @var RouterInterface * @since 1.0.0 */ - protected ?RouterInterface $router = null; + protected RouterInterface $router; /** * Dispatcher instance. * - * @var null|Dispatcher + * @var Dispatcher * @since 1.0.0 */ - protected ?Dispatcher $dispatcher = null; + protected Dispatcher $dispatcher; /** * Session instance. * - * @var null|SessionInterface + * @var SessionInterface * @since 1.0.0 */ - protected ?SessionInterface $sessionManager = null; + protected SessionInterface $sessionManager; /** * Cookie instance. * - * @var null|CookieJar + * @var CookieJar * @since 1.0.0 */ - protected ?CookieJar $cookieJar = null; + protected CookieJar $cookieJar; /** * Server localization. * - * @var null|Localization + * @var Localization * @since 1.0.0 */ - protected ?Localization $l11nServer = null; + protected Localization $l11nServer; /** * Server localization. * - * @var null|FileLogger + * @var FileLogger * @since 1.0.0 */ - protected ?FileLogger $logger = null; + protected FileLogger $logger; /** * L11n manager. * - * @var null|L11nManager + * @var L11nManager * @since 1.0.0 */ - protected ?L11nManager $l11nManager = null; + protected L11nManager $l11nManager; /** * Event manager. * - * @var null|EventManager + * @var EventManager * @since 1.0.0 */ - protected ?EventManager $eventManager = null; + protected EventManager $eventManager; /** * Set values @@ -219,6 +219,6 @@ class ApplicationAbstract */ public function __get($name) { - return $this->{$name}; + return isset($this->{$name}) ? $this->{$name} : null; } } diff --git a/DataStorage/Database/Connection/ConnectionAbstract.php b/DataStorage/Database/Connection/ConnectionAbstract.php index 72e34ce15..52dc28565 100644 --- a/DataStorage/Database/Connection/ConnectionAbstract.php +++ b/DataStorage/Database/Connection/ConnectionAbstract.php @@ -37,10 +37,10 @@ abstract class ConnectionAbstract implements ConnectionInterface * * This can be used externally to define queries and execute them. * - * @var null|\PDO + * @var \PDO * @since 1.0.0 */ - public ?\PDO $con = null; + public \PDO $con; /** * Database prefix. @@ -189,7 +189,7 @@ abstract class ConnectionAbstract implements ConnectionInterface */ public function close() : void { - $this->con = null; + unset($this->con); $this->status = DatabaseStatus::CLOSED; } } diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index 1535d0117..26fda8287 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -74,6 +74,7 @@ final class MysqlConnection extends ConnectionAbstract $this->status = DatabaseStatus::OK; } catch (\PDOException $e) { + unset($this->con); $this->status = DatabaseStatus::MISSING_DATABASE; throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata)); } finally { diff --git a/DataStorage/Database/Connection/PostgresConnection.php b/DataStorage/Database/Connection/PostgresConnection.php index bec6a1a95..97c8ef99b 100644 --- a/DataStorage/Database/Connection/PostgresConnection.php +++ b/DataStorage/Database/Connection/PostgresConnection.php @@ -74,8 +74,8 @@ final class PostgresConnection extends ConnectionAbstract $this->status = DatabaseStatus::OK; } catch (\PDOException $e) { + unset($this->con); $this->status = DatabaseStatus::MISSING_DATABASE; - $this->con = null; } finally { $this->dbdata['password'] = '****'; } diff --git a/DataStorage/Database/Connection/SQLiteConnection.php b/DataStorage/Database/Connection/SQLiteConnection.php index 10c9bbd4c..5414ba3e6 100644 --- a/DataStorage/Database/Connection/SQLiteConnection.php +++ b/DataStorage/Database/Connection/SQLiteConnection.php @@ -74,8 +74,8 @@ final class SQLiteConnection extends ConnectionAbstract $this->status = DatabaseStatus::OK; } catch (\PDOException $e) { + unset($this->con); $this->status = DatabaseStatus::MISSING_DATABASE; - $this->con = null; } finally { $this->dbdata['password'] = '****'; } diff --git a/DataStorage/Database/Connection/SqlServerConnection.php b/DataStorage/Database/Connection/SqlServerConnection.php index e2d464ff4..37742452e 100644 --- a/DataStorage/Database/Connection/SqlServerConnection.php +++ b/DataStorage/Database/Connection/SqlServerConnection.php @@ -74,8 +74,8 @@ final class SqlServerConnection extends ConnectionAbstract $this->status = DatabaseStatus::OK; } catch (\PDOException $e) { + unset($this->con); $this->status = DatabaseStatus::MISSING_DATABASE; - $this->con = null; } finally { $this->dbdata['password'] = '****'; } diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 77cd6b657..9ea461017 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -28,7 +28,7 @@ use phpOMS\Utils\RnG\StringUtils; * * @SuppressWarnings(PHPMD.Superglobals) */ -class HttpSession implements SessionInterface +final class HttpSession implements SessionInterface { /** * Is session locked/already set. @@ -65,21 +65,21 @@ class HttpSession implements SessionInterface /** * Constructor. * - * @param int $liftetime Session life time - * @param bool|int|string $sid Session id - * @param int $inactivityInterval Interval for session activity + * @param int $liftetime Session life time + * @param string $sid Session id + * @param int $inactivityInterval Interval for session activity * * @throws LockException throws this exception if the session is alrady locked for further interaction * * @since 1.0.0 */ - public function __construct(int $liftetime = 3600, $sid = false, int $inactivityInterval = 0) + public function __construct(int $liftetime = 3600, $sid = '', int $inactivityInterval = 0) { if (\session_id()) { \session_write_close(); // @codeCoverageIgnore } - if (!\is_bool($sid)) { + if ($sid !== '') { \session_id((string) $sid); } diff --git a/Message/Console/Request.php b/Message/Console/Request.php index c387389b6..915b30cb2 100644 --- a/Message/Console/Request.php +++ b/Message/Console/Request.php @@ -138,19 +138,6 @@ final class Request extends RequestAbstract } } - /** - * Get request uri. - * - * @return UriInterface - * - * @since 1.0.0 - */ - public function getUri() : UriInterface - { - return $this->uri; - } - - /** * Get request hash. * diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 34097c631..7ccbc0348 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -33,14 +33,6 @@ use phpOMS\Uri\UriInterface; */ final class Request extends RequestAbstract { - /** - * Uri. - * - * @var UriInterface - * @since 1.0.0 - */ - protected UriInterface $uri; - /** * Request method. * @@ -193,19 +185,6 @@ final class Request extends RequestAbstract } } - /** - * Get request uri. - * - * @return UriInterface - * - * @since 1.0.0 - */ - public function getUri() : UriInterface - { - return $this->uri; - } - - /** * Get request hash. * diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index aeca0ee4e..5f65787db 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -26,6 +26,14 @@ use phpOMS\Uri\UriInterface; */ abstract class RequestAbstract implements MessageInterface { + /** + * Uri. + * + * @var UriInterface + * @since 1.0.0 + */ + protected UriInterface $uri; + /** * Request data. * @@ -233,4 +241,16 @@ abstract class RequestAbstract implements MessageInterface { return $this->files; } + + /** + * Get request uri. + * + * @return UriInterface + * + * @since 1.0.0 + */ + public function getUri() : UriInterface + { + return $this->uri; + } } diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 413316a93..426b56590 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -91,10 +91,10 @@ abstract class ModuleAbstract /** * Application instance. * - * @var null|ApplicationAbstract + * @var ApplicationAbstract * @since 1.0.0 */ - protected ?ApplicationAbstract $app = null; + protected ApplicationAbstract $app; /** * Constructor. @@ -105,7 +105,7 @@ abstract class ModuleAbstract */ public function __construct(ApplicationAbstract $app = null) { - $this->app = $app; + $this->app = $app ?? new class extends ApplicationAbstract {}; } /** diff --git a/tests/DataStorage/Session/HttpSessionTest.php b/tests/DataStorage/Session/HttpSessionTest.php index 9080587e3..069918e89 100644 --- a/tests/DataStorage/Session/HttpSessionTest.php +++ b/tests/DataStorage/Session/HttpSessionTest.php @@ -40,7 +40,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testInputOutput() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); self::assertTrue($session->set('test', 'value')); self::assertEquals('value', $session->get('test')); } @@ -51,7 +51,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testInvalidOverwrite() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->set('test', 'value'); self::assertFalse($session->set('test', 'value2')); self::assertEquals('value', $session->get('test')); @@ -63,7 +63,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testOverwrite() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->set('test', 'value'); self::assertTrue($session->set('test', 'value2', true)); self::assertEquals('value2', $session->get('test')); @@ -75,7 +75,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testRemove() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->set('test', 'value'); self::assertTrue($session->remove('test')); } @@ -86,7 +86,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testInvalidRemove() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->set('test', 'value'); $session->remove('test'); @@ -99,7 +99,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testSessionIdInputOutput() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->setSID('abc'); self::assertEquals('abc', $session->getSID()); } @@ -110,7 +110,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testLockInputOutput() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->lock(); self::assertTrue($session->isLocked()); @@ -122,7 +122,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testLockInvalidSet() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); $session->lock(); self::assertFalse($session->set('test', 'value')); @@ -134,7 +134,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase */ public function testLockInvalidRemove() : void { - $session = new HttpSession(1, false, 1); + $session = new HttpSession(1, '', 1); self::assertTrue($session->set('test', 'value')); $session->lock();