fix phpstan bugs

This commit is contained in:
Dennis Eichhorn 2019-12-21 20:51:20 +01:00
parent 34b9ba3097
commit db48bcdb8d
12 changed files with 72 additions and 85 deletions

View File

@ -84,106 +84,106 @@ class ApplicationAbstract
/** /**
* Database object. * Database object.
* *
* @var null|DatabasePool * @var DatabasePool
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?DatabasePool $dbPool = null; protected DatabasePool $dbPool;
/** /**
* Application settings object. * Application settings object.
* *
* @var null|CoreSettings * @var CoreSettings
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?CoreSettings $appSettings = null; protected CoreSettings $appSettings;
/** /**
* Account manager instance. * Account manager instance.
* *
* @var null|AccountManager * @var AccountManager
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?AccountManager $accountManager = null; protected AccountManager $accountManager;
/** /**
* Cache instance. * Cache instance.
* *
* @var null|CachePool * @var CachePool
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?CachePool $cachePool = null; protected CachePool $cachePool;
/** /**
* ModuleManager instance. * ModuleManager instance.
* *
* @var null|ModuleManager * @var ModuleManager
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?ModuleManager $moduleManager = null; protected ModuleManager $moduleManager;
/** /**
* Router instance. * Router instance.
* *
* @var null|RouterInterface * @var RouterInterface
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?RouterInterface $router = null; protected RouterInterface $router;
/** /**
* Dispatcher instance. * Dispatcher instance.
* *
* @var null|Dispatcher * @var Dispatcher
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?Dispatcher $dispatcher = null; protected Dispatcher $dispatcher;
/** /**
* Session instance. * Session instance.
* *
* @var null|SessionInterface * @var SessionInterface
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?SessionInterface $sessionManager = null; protected SessionInterface $sessionManager;
/** /**
* Cookie instance. * Cookie instance.
* *
* @var null|CookieJar * @var CookieJar
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?CookieJar $cookieJar = null; protected CookieJar $cookieJar;
/** /**
* Server localization. * Server localization.
* *
* @var null|Localization * @var Localization
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?Localization $l11nServer = null; protected Localization $l11nServer;
/** /**
* Server localization. * Server localization.
* *
* @var null|FileLogger * @var FileLogger
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?FileLogger $logger = null; protected FileLogger $logger;
/** /**
* L11n manager. * L11n manager.
* *
* @var null|L11nManager * @var L11nManager
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?L11nManager $l11nManager = null; protected L11nManager $l11nManager;
/** /**
* Event manager. * Event manager.
* *
* @var null|EventManager * @var EventManager
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?EventManager $eventManager = null; protected EventManager $eventManager;
/** /**
* Set values * Set values
@ -219,6 +219,6 @@ class ApplicationAbstract
*/ */
public function __get($name) public function __get($name)
{ {
return $this->{$name}; return isset($this->{$name}) ? $this->{$name} : null;
} }
} }

View File

@ -37,10 +37,10 @@ abstract class ConnectionAbstract implements ConnectionInterface
* *
* This can be used externally to define queries and execute them. * This can be used externally to define queries and execute them.
* *
* @var null|\PDO * @var \PDO
* @since 1.0.0 * @since 1.0.0
*/ */
public ?\PDO $con = null; public \PDO $con;
/** /**
* Database prefix. * Database prefix.
@ -189,7 +189,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/ */
public function close() : void public function close() : void
{ {
$this->con = null; unset($this->con);
$this->status = DatabaseStatus::CLOSED; $this->status = DatabaseStatus::CLOSED;
} }
} }

View File

@ -74,6 +74,7 @@ final class MysqlConnection extends ConnectionAbstract
$this->status = DatabaseStatus::OK; $this->status = DatabaseStatus::OK;
} catch (\PDOException $e) { } catch (\PDOException $e) {
unset($this->con);
$this->status = DatabaseStatus::MISSING_DATABASE; $this->status = DatabaseStatus::MISSING_DATABASE;
throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata)); throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata));
} finally { } finally {

View File

@ -74,8 +74,8 @@ final class PostgresConnection extends ConnectionAbstract
$this->status = DatabaseStatus::OK; $this->status = DatabaseStatus::OK;
} catch (\PDOException $e) { } catch (\PDOException $e) {
unset($this->con);
$this->status = DatabaseStatus::MISSING_DATABASE; $this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
} finally { } finally {
$this->dbdata['password'] = '****'; $this->dbdata['password'] = '****';
} }

View File

@ -74,8 +74,8 @@ final class SQLiteConnection extends ConnectionAbstract
$this->status = DatabaseStatus::OK; $this->status = DatabaseStatus::OK;
} catch (\PDOException $e) { } catch (\PDOException $e) {
unset($this->con);
$this->status = DatabaseStatus::MISSING_DATABASE; $this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
} finally { } finally {
$this->dbdata['password'] = '****'; $this->dbdata['password'] = '****';
} }

View File

@ -74,8 +74,8 @@ final class SqlServerConnection extends ConnectionAbstract
$this->status = DatabaseStatus::OK; $this->status = DatabaseStatus::OK;
} catch (\PDOException $e) { } catch (\PDOException $e) {
unset($this->con);
$this->status = DatabaseStatus::MISSING_DATABASE; $this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
} finally { } finally {
$this->dbdata['password'] = '****'; $this->dbdata['password'] = '****';
} }

View File

@ -28,7 +28,7 @@ use phpOMS\Utils\RnG\StringUtils;
* *
* @SuppressWarnings(PHPMD.Superglobals) * @SuppressWarnings(PHPMD.Superglobals)
*/ */
class HttpSession implements SessionInterface final class HttpSession implements SessionInterface
{ {
/** /**
* Is session locked/already set. * Is session locked/already set.
@ -65,21 +65,21 @@ class HttpSession implements SessionInterface
/** /**
* Constructor. * Constructor.
* *
* @param int $liftetime Session life time * @param int $liftetime Session life time
* @param bool|int|string $sid Session id * @param string $sid Session id
* @param int $inactivityInterval Interval for session activity * @param int $inactivityInterval Interval for session activity
* *
* @throws LockException throws this exception if the session is alrady locked for further interaction * @throws LockException throws this exception if the session is alrady locked for further interaction
* *
* @since 1.0.0 * @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()) { if (\session_id()) {
\session_write_close(); // @codeCoverageIgnore \session_write_close(); // @codeCoverageIgnore
} }
if (!\is_bool($sid)) { if ($sid !== '') {
\session_id((string) $sid); \session_id((string) $sid);
} }

View File

@ -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. * Get request hash.
* *

View File

@ -33,14 +33,6 @@ use phpOMS\Uri\UriInterface;
*/ */
final class Request extends RequestAbstract final class Request extends RequestAbstract
{ {
/**
* Uri.
*
* @var UriInterface
* @since 1.0.0
*/
protected UriInterface $uri;
/** /**
* Request method. * 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. * Get request hash.
* *

View File

@ -26,6 +26,14 @@ use phpOMS\Uri\UriInterface;
*/ */
abstract class RequestAbstract implements MessageInterface abstract class RequestAbstract implements MessageInterface
{ {
/**
* Uri.
*
* @var UriInterface
* @since 1.0.0
*/
protected UriInterface $uri;
/** /**
* Request data. * Request data.
* *
@ -233,4 +241,16 @@ abstract class RequestAbstract implements MessageInterface
{ {
return $this->files; return $this->files;
} }
/**
* Get request uri.
*
* @return UriInterface
*
* @since 1.0.0
*/
public function getUri() : UriInterface
{
return $this->uri;
}
} }

View File

@ -91,10 +91,10 @@ abstract class ModuleAbstract
/** /**
* Application instance. * Application instance.
* *
* @var null|ApplicationAbstract * @var ApplicationAbstract
* @since 1.0.0 * @since 1.0.0
*/ */
protected ?ApplicationAbstract $app = null; protected ApplicationAbstract $app;
/** /**
* Constructor. * Constructor.
@ -105,7 +105,7 @@ abstract class ModuleAbstract
*/ */
public function __construct(ApplicationAbstract $app = null) public function __construct(ApplicationAbstract $app = null)
{ {
$this->app = $app; $this->app = $app ?? new class extends ApplicationAbstract {};
} }
/** /**

View File

@ -40,7 +40,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testInputOutput() : void public function testInputOutput() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
self::assertTrue($session->set('test', 'value')); self::assertTrue($session->set('test', 'value'));
self::assertEquals('value', $session->get('test')); self::assertEquals('value', $session->get('test'));
} }
@ -51,7 +51,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testInvalidOverwrite() : void public function testInvalidOverwrite() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->set('test', 'value'); $session->set('test', 'value');
self::assertFalse($session->set('test', 'value2')); self::assertFalse($session->set('test', 'value2'));
self::assertEquals('value', $session->get('test')); self::assertEquals('value', $session->get('test'));
@ -63,7 +63,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testOverwrite() : void public function testOverwrite() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->set('test', 'value'); $session->set('test', 'value');
self::assertTrue($session->set('test', 'value2', true)); self::assertTrue($session->set('test', 'value2', true));
self::assertEquals('value2', $session->get('test')); self::assertEquals('value2', $session->get('test'));
@ -75,7 +75,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testRemove() : void public function testRemove() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->set('test', 'value'); $session->set('test', 'value');
self::assertTrue($session->remove('test')); self::assertTrue($session->remove('test'));
} }
@ -86,7 +86,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testInvalidRemove() : void public function testInvalidRemove() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->set('test', 'value'); $session->set('test', 'value');
$session->remove('test'); $session->remove('test');
@ -99,7 +99,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testSessionIdInputOutput() : void public function testSessionIdInputOutput() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->setSID('abc'); $session->setSID('abc');
self::assertEquals('abc', $session->getSID()); self::assertEquals('abc', $session->getSID());
} }
@ -110,7 +110,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testLockInputOutput() : void public function testLockInputOutput() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->lock(); $session->lock();
self::assertTrue($session->isLocked()); self::assertTrue($session->isLocked());
@ -122,7 +122,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testLockInvalidSet() : void public function testLockInvalidSet() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
$session->lock(); $session->lock();
self::assertFalse($session->set('test', 'value')); self::assertFalse($session->set('test', 'value'));
@ -134,7 +134,7 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
*/ */
public function testLockInvalidRemove() : void public function testLockInvalidRemove() : void
{ {
$session = new HttpSession(1, false, 1); $session = new HttpSession(1, '', 1);
self::assertTrue($session->set('test', 'value')); self::assertTrue($session->set('test', 'value'));
$session->lock(); $session->lock();