mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-23 06:48:41 +00:00
remove stupid initializations and optimize types
This commit is contained in:
parent
aefd1e8cc5
commit
ca064b75d2
|
|
@ -106,7 +106,7 @@ final class Autoloader
|
|||
$class = \str_replace(['_', '\\'], '/', $class);
|
||||
|
||||
foreach (self::$paths as $path) {
|
||||
if (\file_exists($file = $path . $class . '.php')) {
|
||||
if (\file_exists($path . $class . '.php')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ final class CachePool implements DataStoragePoolInterface
|
|||
* @var DataStorageConnectionInterface[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?array $pool = null;
|
||||
private array $pool = [];
|
||||
|
||||
/**
|
||||
* Add database.
|
||||
|
|
|
|||
|
|
@ -55,10 +55,10 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
/**
|
||||
* Database data.
|
||||
*
|
||||
* @var null|string[]
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?array $dbdata = null;
|
||||
protected array $dbdata = [];
|
||||
|
||||
/**
|
||||
* Database type.
|
||||
|
|
@ -79,18 +79,18 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
/**
|
||||
* Database grammar.
|
||||
*
|
||||
* @var null|Grammar
|
||||
* @var Grammar
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?Grammar $grammar = null;
|
||||
protected Grammar $grammar;
|
||||
|
||||
/**
|
||||
* Database grammar.
|
||||
*
|
||||
* @var null|SchemaGrammar
|
||||
* @var SchemaGrammar
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?SchemaGrammar $schemaGrammar = null;
|
||||
protected SchemaGrammar $schemaGrammar;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -161,7 +161,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
*/
|
||||
public function getGrammar() : Grammar
|
||||
{
|
||||
return $this->grammar ?? new Grammar();
|
||||
return $this->grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -169,7 +169,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
*/
|
||||
public function getSchemaGrammar() : SchemaGrammar
|
||||
{
|
||||
return $this->schemaGrammar ?? new SchemaGrammar();
|
||||
return $this->schemaGrammar;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ final class MysqlConnection extends ConnectionAbstract
|
|||
*/
|
||||
public function connect(array $dbdata = null) : void
|
||||
{
|
||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||
$this->dbdata = $dbdata ?? $this->dbdata;
|
||||
|
||||
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])
|
||||
|| !DatabaseType::isValidValue($this->dbdata['db'])
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ final class PostgresConnection extends ConnectionAbstract
|
|||
*/
|
||||
public function connect(array $dbdata = null) : void
|
||||
{
|
||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||
$this->dbdata = $dbdata ?? $this->dbdata;
|
||||
|
||||
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])
|
||||
|| !DatabaseType::isValidValue($this->dbdata['db'])
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ final class SQLiteConnection extends ConnectionAbstract
|
|||
*/
|
||||
public function connect(array $dbdata = null) : void
|
||||
{
|
||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||
$this->dbdata = $dbdata ?? $this->dbdata;
|
||||
|
||||
if (!isset($this->dbdata['db'], $this->dbdata['database'])
|
||||
|| !DatabaseType::isValidValue($this->dbdata['db'])
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ final class SqlServerConnection extends ConnectionAbstract
|
|||
{
|
||||
$this->close();
|
||||
|
||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||
$this->dbdata = $dbdata ?? $this->dbdata;
|
||||
$this->prefix = $dbdata['prefix'];
|
||||
|
||||
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ use phpOMS\DataStorage\Database\Exception\InvalidMapperException;
|
|||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\QueryType;
|
||||
use phpOMS\DataStorage\DataMapperInterface;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Utils\ArrayUtils;
|
||||
use Throwable;
|
||||
|
||||
|
|
|
|||
|
|
@ -254,7 +254,11 @@ abstract class GrammarAbstract
|
|||
$fullSystem = '';
|
||||
|
||||
foreach ($split as $key => $system) {
|
||||
$fullSystem .= '.' . ($system !== '*' ? $identifier : '') . ($key === 0 && $system !== '*' ? $prefix : '') . $system . ($system !== '*' ? $identifier : '');
|
||||
$fullSystem .= '.'
|
||||
. ($system !== '*' ? $identifier : '')
|
||||
. ($key === 0 && $system !== '*' ? $prefix : '')
|
||||
. $system
|
||||
. ($system !== '*' ? $identifier : '');
|
||||
}
|
||||
|
||||
return \ltrim($fullSystem, '.');
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\DataStorage\Session;
|
||||
|
||||
use phpOMS\DataStorage\LockException;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
use phpOMS\Utils\RnG\StringUtils;
|
||||
|
||||
/**
|
||||
* Console session class.
|
||||
|
|
@ -49,10 +47,10 @@ class ConsoleSession implements SessionInterface
|
|||
/**
|
||||
* Session ID.
|
||||
*
|
||||
* @var null|int|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $sid = null;
|
||||
private string $sid;
|
||||
|
||||
/**
|
||||
* Inactivity Interval.
|
||||
|
|
@ -103,7 +101,7 @@ class ConsoleSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = false) : bool
|
||||
public function set(string $key, $value, bool $overwrite = false) : bool
|
||||
{
|
||||
if (!$this->isLocked && ($overwrite || !isset($this->sessionData[$key]))) {
|
||||
$this->sessionData[$key] = $value;
|
||||
|
|
@ -117,7 +115,7 @@ class ConsoleSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key)
|
||||
public function get(string $key)
|
||||
{
|
||||
return $this->sessionData[$key] ?? null;
|
||||
}
|
||||
|
|
@ -156,7 +154,7 @@ class ConsoleSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($key) : bool
|
||||
public function remove(string $key) : bool
|
||||
{
|
||||
if (!$this->isLocked && isset($this->sessionData[$key])) {
|
||||
unset($this->sessionData[$key]);
|
||||
|
|
@ -170,7 +168,7 @@ class ConsoleSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSID()
|
||||
public function getSID() : string
|
||||
{
|
||||
return $this->sid;
|
||||
}
|
||||
|
|
@ -178,7 +176,7 @@ class ConsoleSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSID($sid) : void
|
||||
public function setSID(string $sid) : void
|
||||
{
|
||||
$this->sid = $sid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ namespace phpOMS\DataStorage\Session;
|
|||
|
||||
use phpOMS\DataStorage\LockException;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
use phpOMS\Utils\RnG\StringUtils;
|
||||
|
||||
/**
|
||||
* Http session class.
|
||||
|
|
@ -49,10 +48,10 @@ final class HttpSession implements SessionInterface
|
|||
/**
|
||||
* Session ID.
|
||||
*
|
||||
* @var null|int|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $sid = null;
|
||||
private string $sid;
|
||||
|
||||
/**
|
||||
* Inactivity Interval.
|
||||
|
|
@ -114,7 +113,7 @@ final class HttpSession implements SessionInterface
|
|||
$this->set('UID', 0, false);
|
||||
|
||||
if (($csrf = $this->get('CSRF')) === null) {
|
||||
$csrf = StringUtils::generateString(10, 16);
|
||||
$csrf = \bin2hex(\random_bytes(32));
|
||||
$this->set('CSRF', $csrf, false);
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +123,7 @@ final class HttpSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = false) : bool
|
||||
public function set(string $key, $value, bool $overwrite = false) : bool
|
||||
{
|
||||
if (!$this->isLocked && ($overwrite || !isset($this->sessionData[$key]))) {
|
||||
$this->sessionData[$key] = $value;
|
||||
|
|
@ -138,7 +137,7 @@ final class HttpSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key)
|
||||
public function get(string $key)
|
||||
{
|
||||
return $this->sessionData[$key] ?? null;
|
||||
}
|
||||
|
|
@ -177,7 +176,7 @@ final class HttpSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function remove($key) : bool
|
||||
public function remove(string $key) : bool
|
||||
{
|
||||
if (!$this->isLocked && isset($this->sessionData[$key])) {
|
||||
unset($this->sessionData[$key]);
|
||||
|
|
@ -191,7 +190,7 @@ final class HttpSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSID()
|
||||
public function getSID() : string
|
||||
{
|
||||
return $this->sid;
|
||||
}
|
||||
|
|
@ -199,7 +198,7 @@ final class HttpSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setSID($sid) : void
|
||||
public function setSID(string $sid) : void
|
||||
{
|
||||
$this->sid = $sid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,37 +30,37 @@ interface SessionInterface
|
|||
/**
|
||||
* Get session variable by key.
|
||||
*
|
||||
* @param int|string $key Value key
|
||||
* @param string $key Value key
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get($key);
|
||||
public function get(string $key);
|
||||
|
||||
/**
|
||||
* Store session value by key.
|
||||
*
|
||||
* @param int|string $key Value key
|
||||
* @param mixed $value Value to store
|
||||
* @param bool $overwrite Overwrite existing values
|
||||
* @param string $key Value key
|
||||
* @param mixed $value Value to store
|
||||
* @param bool $overwrite Overwrite existing values
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = false) : bool;
|
||||
public function set(string $key, $value, bool $overwrite = false) : bool;
|
||||
|
||||
/**
|
||||
* Remove value from session by key.
|
||||
*
|
||||
* @param int|string $key Value key
|
||||
* @param string $key Value key
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function remove($key) : bool;
|
||||
public function remove(string $key) : bool;
|
||||
|
||||
/**
|
||||
* Save session.
|
||||
|
|
@ -72,20 +72,20 @@ interface SessionInterface
|
|||
public function save() : void;
|
||||
|
||||
/**
|
||||
* @return null|int|string
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getSID();
|
||||
public function getSID() : string;
|
||||
|
||||
/**
|
||||
* @param null|int|string $sid Session id
|
||||
* @param string $sid Session id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setSID($sid) : void;
|
||||
public function setSID(string $sid) : void;
|
||||
|
||||
/**
|
||||
* Lock session from further adjustments.
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ final class Dispatcher implements DispatcherInterface
|
|||
* @var null|ApplicationAbstract
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?ApplicationAbstract $app = null;
|
||||
private ?ApplicationAbstract $app;
|
||||
|
||||
/**
|
||||
* Controller.
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ final class L11nManager
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $appName = '';
|
||||
private string $appName;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ final class FileLogger implements LoggerInterface
|
|||
/**
|
||||
* Instance.
|
||||
*
|
||||
* @var null|FileLogger
|
||||
* @var FileLogger
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static ?FileLogger $instance = null;
|
||||
protected static FileLogger $instance;
|
||||
|
||||
/**
|
||||
* Verbose.
|
||||
|
|
@ -76,7 +76,7 @@ final class FileLogger implements LoggerInterface
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $path = '';
|
||||
private string $path;
|
||||
|
||||
/**
|
||||
* Is the logging file created
|
||||
|
|
@ -137,7 +137,7 @@ final class FileLogger implements LoggerInterface
|
|||
*/
|
||||
public static function getInstance(string $path = '', bool $verbose = false) : self
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
if (!isset(self::$instance)) {
|
||||
self::$instance = new self($path, $verbose);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,18 +44,10 @@ final class Request extends RequestAbstract
|
|||
/**
|
||||
* Request method.
|
||||
*
|
||||
* @var null|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?string $method = null;
|
||||
|
||||
/**
|
||||
* Request type.
|
||||
*
|
||||
* @var null|string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?string $type = null;
|
||||
protected string $method;
|
||||
|
||||
/**
|
||||
* Request hash.
|
||||
|
|
@ -65,21 +57,13 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
protected array $hash = [];
|
||||
|
||||
/**
|
||||
* Uploaded files.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected array $files = [];
|
||||
|
||||
/**
|
||||
* OS type.
|
||||
*
|
||||
* @var null|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?string $os = null;
|
||||
private string $os;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -173,7 +157,7 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
public function getOS() : string
|
||||
{
|
||||
if ($this->os === null) {
|
||||
if (!isset($this->os)) {
|
||||
$this->os = \strtolower(\PHP_OS);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +191,7 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
public function getMethod() : string
|
||||
{
|
||||
if ($this->method === null) {
|
||||
if (!isset($this->method)) {
|
||||
$temp = $this->uri->__toString();
|
||||
$found = \stripos($temp, ':');
|
||||
$method = $found !== false && $found > 3 && $found < 8 ? \substr($temp, 0, $found) : RequestMethod::GET;
|
||||
|
|
|
|||
|
|
@ -36,42 +36,34 @@ final class Request extends RequestAbstract
|
|||
/**
|
||||
* Request method.
|
||||
*
|
||||
* @var null|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?string $method = null;
|
||||
|
||||
/**
|
||||
* Request type.
|
||||
*
|
||||
* @var null|string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected ?string $type = null;
|
||||
protected string $method;
|
||||
|
||||
/**
|
||||
* Browser type.
|
||||
*
|
||||
* @var null|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?string $browser = null;
|
||||
private string $browser;
|
||||
|
||||
/**
|
||||
* OS type.
|
||||
*
|
||||
* @var null|string
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?string $os = null;
|
||||
private string $os;
|
||||
|
||||
/**
|
||||
* Request information.
|
||||
*
|
||||
* @var null|string[]
|
||||
* @var string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private ?array $info = null;
|
||||
private array $info;
|
||||
|
||||
/**
|
||||
* Request hash.
|
||||
|
|
@ -87,7 +79,7 @@ final class Request extends RequestAbstract
|
|||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected array $files = [];
|
||||
protected array $files;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -364,7 +356,7 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
public function getRequestInfo() : array
|
||||
{
|
||||
if ($this->info === null) {
|
||||
if (!isset($this->info)) {
|
||||
$this->info['browser'] = $this->getBrowser();
|
||||
$this->info['os'] = $this->getOS();
|
||||
}
|
||||
|
|
@ -381,7 +373,7 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
public function getBrowser() : string
|
||||
{
|
||||
if ($this->browser === null) {
|
||||
if (!isset($this->browser)) {
|
||||
$arr = BrowserType::getConstants();
|
||||
$httpUserAgent = \strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
|
||||
|
|
@ -422,7 +414,7 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
public function getOS() : string
|
||||
{
|
||||
if ($this->os === null) {
|
||||
if (!isset($this->os)) {
|
||||
$arr = OSType::getConstants();
|
||||
$httpUserAgent = \strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||
|
||||
|
|
@ -528,7 +520,7 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
public function getMethod() : string
|
||||
{
|
||||
if ($this->method === null) {
|
||||
if (!isset($this->method)) {
|
||||
$this->method = $_SERVER['REQUEST_METHOD'] ?? RequestMethod::GET;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ final class ModuleManager
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $modulePath = __DIR__ . '/../../Modules';
|
||||
private string $modulePath;
|
||||
|
||||
/**
|
||||
* All modules in the module directory.
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user