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.
*
* @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;
}
}

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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'] = '****';
}

View File

@ -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'] = '****';
}

View File

@ -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'] = '****';
}

View File

@ -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);
}

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.
*

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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 {};
}
/**

View File

@ -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();