From 17756362a1def47708f46cfa251f6eab60b21f1b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 21 Sep 2023 02:24:44 +0000 Subject: [PATCH] cs fixes --- Algorithm/Rating/Glicko2.php | 2 +- DataStorage/Database/Mapper/DeleteMapper.php | 2 +- DataStorage/Database/Mapper/WriteMapper.php | 2 +- Message/Cli/CliHeader.php | 8 ++- Message/HeaderAbstract.php | 7 ++ Message/Http/HttpHeader.php | 27 ++++++- Message/Http/ImpressionStat.php | 74 ++++++++++++++++++++ 7 files changed, 117 insertions(+), 5 deletions(-) diff --git a/Algorithm/Rating/Glicko2.php b/Algorithm/Rating/Glicko2.php index 173f255c5..ebdabbcb1 100644 --- a/Algorithm/Rating/Glicko2.php +++ b/Algorithm/Rating/Glicko2.php @@ -121,7 +121,7 @@ final class Glicko2 // Step 0: $rdOld /= self::Q; - $elo = ($elo - $this->DEFAULT_ELO) / self::Q; + $elo = ($elo - $this->DEFAULT_ELO) / self::Q; foreach ($oElo as $idx => $value) { $oElo[$idx] = ($value - $this->DEFAULT_ELO) / self::Q; diff --git a/DataStorage/Database/Mapper/DeleteMapper.php b/DataStorage/Database/Mapper/DeleteMapper.php index b3112cb0e..d155406ce 100755 --- a/DataStorage/Database/Mapper/DeleteMapper.php +++ b/DataStorage/Database/Mapper/DeleteMapper.php @@ -171,7 +171,7 @@ final class DeleteMapper extends DataMapperAbstract $objIds = []; $refProp = $refClass->getProperty($member); - $values = $refProp->isPublic() ? $obj->{$member} : $refProp->getValue($obj); + $values = $refProp->isPublic() ? $obj->{$member} : $refProp->getValue($obj); if (!\is_array($values)) { // conditionals diff --git a/DataStorage/Database/Mapper/WriteMapper.php b/DataStorage/Database/Mapper/WriteMapper.php index 9d10f2ef3..39bec061c 100755 --- a/DataStorage/Database/Mapper/WriteMapper.php +++ b/DataStorage/Database/Mapper/WriteMapper.php @@ -262,7 +262,7 @@ final class WriteMapper extends DataMapperAbstract } $property = $refClass->getProperty($propertyName); - $values = $property->isPublic() ? $obj->{$propertyName} : $property->getValue($obj); + $values = $property->isPublic() ? $obj->{$propertyName} : $property->getValue($obj); /** @var class-string $mapper */ $mapper = $this->mapper::HAS_MANY[$propertyName]['mapper']; diff --git a/Message/Cli/CliHeader.php b/Message/Cli/CliHeader.php index 4177b545d..ccd91f595 100755 --- a/Message/Cli/CliHeader.php +++ b/Message/Cli/CliHeader.php @@ -153,9 +153,15 @@ final class CliHeader extends HeaderAbstract */ public function generate(int $code) : void { - $this->generate500(); + switch ($code) { + default: + $this->generate500(); + } } + /** + * {@inheritdoc} + */ public function getRequestTime() : int { return $this->timestamp; diff --git a/Message/HeaderAbstract.php b/Message/HeaderAbstract.php index 933b70ab0..63523a4e8 100755 --- a/Message/HeaderAbstract.php +++ b/Message/HeaderAbstract.php @@ -150,6 +150,13 @@ abstract class HeaderAbstract */ abstract public function has(string $key) : bool; + /** + * Get time of the request + * + * @return int + * + * @since 1.0.0 + */ abstract public function getRequestTime() : int; /** diff --git a/Message/Http/HttpHeader.php b/Message/Http/HttpHeader.php index 19c62191f..9d765e278 100755 --- a/Message/Http/HttpHeader.php +++ b/Message/Http/HttpHeader.php @@ -145,22 +145,47 @@ final class HttpHeader extends HeaderAbstract return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1'; } + /** + * Get the referer link + * + * @return string + * + * @since 1.0.0 + */ public function getReferer() : string { return $_SERVER['HTTP_REFERER'] ?? ''; } + /** + * {@inheritdoc} + */ public function getRequestTime() : int { return (int) ($_SERVER['REQUEST_TIME'] ?? $this->timestamp); } + /** + * Get the ip of the requester + * + * @return string + * + * @since 1.0.0 + */ public function getRequestIp() : string { return $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? ''; } - public function getBrowserName(): string { + /** + * Get the browser/agent name of the request + * + * @return string + * + * @since 1.0.0 + */ + public function getBrowserName(): string + { $userAgent = $_SERVER['HTTP_USER_AGENT']; if (\strpos($userAgent, 'Opera') !== false || \strpos($userAgent, 'OPR/') !== false) { diff --git a/Message/Http/ImpressionStat.php b/Message/Http/ImpressionStat.php index 0040ed732..aeca5ccfe 100644 --- a/Message/Http/ImpressionStat.php +++ b/Message/Http/ImpressionStat.php @@ -27,26 +27,93 @@ use phpOMS\Localization\ISO639x1Enum; */ class ImpressionStat { + /** + * Request ip + * + * @var string + * @since 1.0.0 + */ public string $address = ''; + /** + * Request language + * + * @var string + * @since 1.0.0 + */ public string $language = ISO639x1Enum::_EN; + /** + * Request country + * + * @var string + * @since 1.0.0 + */ public string $country = ISO3166TwoEnum::_XXX; + /** + * Request time + * + * @var \DateTime + * @since 1.0.0 + */ public \DateTime $datetime; + /** + * Request host/domain + * + * @var string + * @since 1.0.0 + */ public string $host = ''; + /** + * Request path + * + * @var string + * @since 1.0.0 + */ public string $path = ''; + /** + * Request full uri + * + * @var string + * @since 1.0.0 + */ public string $uri = ''; + /** + * Request referer link + * + * @var string + * @since 1.0.0 + */ public string $referer = ''; + /** + * Request browser/agent + * + * @var string + * @since 1.0.0 + */ public string $userAgent = ''; + /** + * Additional custom meta data to be stored + * + * @var string + * @since 1.0.0 + */ public array $meta = []; + /** + * Constructor. + * + * @param HttpRequest $request Http request object + * + * @since 1.0.0 + */ public function __construct(HttpRequest $request) { $this->language = $request->header->l11n->language; @@ -60,6 +127,13 @@ class ImpressionStat $this->userAgent = $request->header->getBrowserName(); } + /** + * Turn object to array + * + * @return array + * + * @since 1.0.0 + */ public function toArray() : array { return [