From 3938f56f88eb69aed634af735ee720bb642e5e04 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 28 May 2023 03:56:49 +0000 Subject: [PATCH] cs fixes --- Account/Account.php | 15 ++ Api/Geocoding/Nominatim.php | 2 +- .../Database/Mapper/DataMapperFactory.php | 4 +- DataStorage/Database/Mapper/ReadMapper.php | 6 +- Localization/Money.php | 9 +- Message/Http/HttpHeader.php | 7 + Message/Http/Rest.php | 2 +- Message/RequestAbstract.php | 9 ++ Module/ModuleAbstract.php | 143 ++++++++++++++++++ Security/EncryptionHelper.php | 19 ++- Stdlib/Graph/Graph.php | 2 +- Utils/Barcode/QR.php | 12 +- Utils/Converter/Currency.php | 2 +- Utils/ImageUtils.php | 14 ++ Utils/NumericUtils.php | 6 +- Utils/RnG/Text.php | 2 +- 16 files changed, 230 insertions(+), 24 deletions(-) diff --git a/Account/Account.php b/Account/Account.php index e4ba4393d..dbb51dc10 100755 --- a/Account/Account.php +++ b/Account/Account.php @@ -147,6 +147,21 @@ class Account implements \JsonSerializable use PermissionHandlingTrait; + /** + * Has permission. + * + * @param int $permission Permission + * @param int|null $unit Unit + * @param int|null $app App + * @param string|null $module Module + * @param int|null $category Category + * @param int|null $element Element + * @param int|null $component Component + * + * @return bool + * + * @since 1.0.0 + */ public function hasPermission( int $permission, int $unit = null, diff --git a/Api/Geocoding/Nominatim.php b/Api/Geocoding/Nominatim.php index 1aa5de39a..12b4829bc 100644 --- a/Api/Geocoding/Nominatim.php +++ b/Api/Geocoding/Nominatim.php @@ -54,7 +54,7 @@ final class Nominatim \usleep((int) (1000000 - ($time - self::$lastRun) + 100)); } - $body = Rest::request($request)->getBody(); + $body = Rest::request($request)->getBody(); $result['body'] = $body; /** @var array $json */ diff --git a/DataStorage/Database/Mapper/DataMapperFactory.php b/DataStorage/Database/Mapper/DataMapperFactory.php index 4c978b19f..924c832a3 100755 --- a/DataStorage/Database/Mapper/DataMapperFactory.php +++ b/DataStorage/Database/Mapper/DataMapperFactory.php @@ -426,8 +426,8 @@ class DataMapperFactory /** * Get id of object * - * @param object $obj Model to create - * @param string $member Member name for the id, if it is not the primary key + * @param object $obj Model to create + * @param string $member Member name for the id, if it is not the primary key * * @return mixed * diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index 8b5c63d0c..32a86876c 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -570,9 +570,9 @@ final class ReadMapper extends DataMapperAbstract $path = \explode('/', \ltrim($def['internal'], '/')); $member = $path[0]; - $refProp = $refClass->getProperty($path[0]); + $refProp = $refClass->getProperty($path[0]); $isPublic = $refProp->isPublic(); - $aValue = $isPublic ? $obj->{$path[0]} : $refProp->getValue($obj); + $aValue = $isPublic ? $obj->{$path[0]} : $refProp->getValue($obj); \array_shift($path); $arrayPath = \implode('/', $path); @@ -683,7 +683,7 @@ final class ReadMapper extends DataMapperAbstract $arrayPath = \implode('/', $path); $aValue = $isPublic ? $obj->{$path[0]} : $refProp->getValue($obj); } else { - $refProp = $refClass->getProperty($member); + $refProp = $refClass->getProperty($member); $isPublic = $refProp->isPublic(); } diff --git a/Localization/Money.php b/Localization/Money.php index b0992de55..ebeca122d 100755 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -91,9 +91,16 @@ final class Money extends FloatInt return $this->symbol; } + /** + * Create Money from FloatInt. + * + * @param FloatInt $value FloatInt value + * + * @return self + */ public static function fromFloatInt(FloatInt $value) : self { - $money = new self(); + $money = new self(); $money->value = $value->value; return $money; diff --git a/Message/Http/HttpHeader.php b/Message/Http/HttpHeader.php index 832d98430..eda818f5b 100755 --- a/Message/Http/HttpHeader.php +++ b/Message/Http/HttpHeader.php @@ -53,6 +53,13 @@ final class HttpHeader extends HeaderAbstract */ public int $status = RequestStatusCode::R_200; + /** + * Init header from current request. + * + * @return void + * + * @since 1.0.0 + */ public function initCurrentRequest() : void { $this->header = self::getAllHeaders(); diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index a1fdc56ae..1ae3e5d5f 100755 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -122,7 +122,7 @@ final class Rest $response->header->set('', $line = \trim($header[0])); if (\stripos(\strtoupper($line), 'HTTP/') === 0) { - $statusCode = \explode(' ', $line, 3); + $statusCode = \explode(' ', $line, 3); $response->header->status = (int) $statusCode[1]; } diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index fc9f1bb1c..246863c02 100755 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -354,6 +354,15 @@ abstract class RequestAbstract implements MessageInterface return false; } + /** + * Create from data array + * + * @param array $data Data array + * + * @return void + * + * @since 1.0.0 + */ public function fromData(array $data) : void { $this->data = $data; diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 2a81542d8..0f1e792a3 100755 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -228,6 +228,17 @@ abstract class ModuleAbstract ]); } + /** + * Create standard model create response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createStandardCreateResponse( RequestAbstract $request, ResponseAbstract $response, @@ -243,6 +254,17 @@ abstract class ModuleAbstract ]); } + /** + * Create standard model update response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createStandardUpdateResponse( RequestAbstract $request, ResponseAbstract $response, @@ -258,6 +280,17 @@ abstract class ModuleAbstract ]); } + /** + * Create standard model delete response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createStandardDeleteResponse( RequestAbstract $request, ResponseAbstract $response, @@ -273,6 +306,17 @@ abstract class ModuleAbstract ]); } + /** + * Create standard model remove response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createStandardRemoveResponse( RequestAbstract $request, ResponseAbstract $response, @@ -288,6 +332,17 @@ abstract class ModuleAbstract ]); } + /** + * Create standard model return response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createStandardReturnResponse( RequestAbstract $request, ResponseAbstract $response, @@ -303,6 +358,17 @@ abstract class ModuleAbstract ]); } + /** + * Create standard model relation add response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createStandardAddResponse( RequestAbstract $request, ResponseAbstract $response, @@ -318,6 +384,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model create response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidCreateResponse( RequestAbstract $request, ResponseAbstract $response, @@ -333,6 +410,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model update response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidUpdateResponse( RequestAbstract $request, ResponseAbstract $response, @@ -348,6 +436,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model delete response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidDeleteResponse( RequestAbstract $request, ResponseAbstract $response, @@ -363,6 +462,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model relation remove response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidRemoveResponse( RequestAbstract $request, ResponseAbstract $response, @@ -378,6 +488,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model return response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidReturnResponse( RequestAbstract $request, ResponseAbstract $response, @@ -393,6 +514,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model relation create response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidAddResponse( RequestAbstract $request, ResponseAbstract $response, @@ -408,6 +540,17 @@ abstract class ModuleAbstract ]); } + /** + * Create invalid model permission response. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $obj Response object + * + * @return void + * + * @since 1.0.0 + */ public function createInvalidPermissionResponse( RequestAbstract $request, ResponseAbstract $response, diff --git a/Security/EncryptionHelper.php b/Security/EncryptionHelper.php index ccf033c84..01fd393a8 100755 --- a/Security/EncryptionHelper.php +++ b/Security/EncryptionHelper.php @@ -68,6 +68,17 @@ final class EncryptionHelper return $result; } + /** + * Encrypt a file with a shared key + * + * @param string $in File to encrypt + * @param string $out Encrypted file + * @param string $keyHex Shared key as hex string used for encryption + * + * @return bool + * + * @since 1.0.0 + */ public static function encryptFile(string $in, string $out, string $keyHex) : bool { $fpSource = \fopen($in, 'rb'); @@ -77,13 +88,13 @@ final class EncryptionHelper return false; } - $secretKey = \sodium_hex2bin($keyHex); - $nonce = \random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); + $secretKey = \sodium_hex2bin($keyHex); + $nonce = \random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); \fwrite($fpEncoded, $nonce); while (!\feof($fpSource)) { - $buffer = \fread($fpSource, 4096); + $buffer = \fread($fpSource, 4096); $ciphertext = \sodium_crypto_secretbox($buffer, $nonce, $secretKey); fwrite($fpEncoded, $ciphertext); @@ -155,7 +166,7 @@ final class EncryptionHelper } $secretKey = \sodium_hex2bin($keyHex); - $nonce = \fread($fpSource, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); + $nonce = \fread($fpSource, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); while (!\feof($fpSource)) { $buffer = \fread($fpSource, 4096); diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index 353df8cfe..b84798aeb 100755 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -1203,7 +1203,7 @@ class Graph $colors[$node->getId()] = 0; } - $node1 = \reset($this->nodes); + $node1 = \reset($this->nodes); $colors[$node1->getId()] = 1; $stack = [$node1]; diff --git a/Utils/Barcode/QR.php b/Utils/Barcode/QR.php index 6ddd7ebe5..13d972639 100755 --- a/Utils/Barcode/QR.php +++ b/Utils/Barcode/QR.php @@ -2167,7 +2167,7 @@ class QR extends TwoDAbstract for ($i = 0; $i < $bits; ++$i) { $bstream[$i] = (($num & $mask) !== 0) ? 1 : 0; - $mask >>= 1; + $mask >>= 1; } return $bstream; @@ -2190,7 +2190,7 @@ class QR extends TwoDAbstract for ($j = 0; $j < 8; ++$j) { $bstream[$p] = (($data[$i] & $mask) !== 0) ? 1 : 0; - $mask >>= 1; + $mask >>= 1; ++$p; } @@ -2278,7 +2278,7 @@ class QR extends TwoDAbstract for ($j = 0; $j < 8; ++$j) { $v <<= 1; - $v |= $bstream[$p]; + $v |= $bstream[$p]; ++$p; } @@ -2290,7 +2290,7 @@ class QR extends TwoDAbstract for ($j = 0; $j < ($size & 7); ++$j) { $v <<= 1; - $v |= $bstream[$p]; + $v |= $bstream[$p]; ++$p; } @@ -2579,7 +2579,7 @@ class QR extends TwoDAbstract for ($x = 0; $x<6; ++$x) { for ($y = 0; $y<3; ++$y) { $frame[($width - 11)+$y][$x] = \chr(0x88 | ($v & 1)); - $v >>= 1; + $v >>= 1; } } @@ -2587,7 +2587,7 @@ class QR extends TwoDAbstract for ($y = 0; $y < 6; ++$y) { for ($x = 0; $x < 3; ++$x) { $frame[$y][$x + ($width - 11)] = \chr(0x88 | ($v & 1)); - $v >>= 1; + $v >>= 1; } } } diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index 55984b164..8ad673a9e 100755 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -175,7 +175,7 @@ final class Currency if ((!isset($currencies[$from]) && $from !== ISO4217CharEnum::_EUR) || (!isset($currencies[$to]) && $to !== ISO4217CharEnum::_EUR) ) { - return -1.0; + return -1.0; } if ($from !== ISO4217CharEnum::_EUR) { diff --git a/Utils/ImageUtils.php b/Utils/ImageUtils.php index b90b30bd5..d4784f4fe 100755 --- a/Utils/ImageUtils.php +++ b/Utils/ImageUtils.php @@ -340,6 +340,20 @@ final class ImageUtils return $difference; } + /** + * Calculate the average color of an image at a specific position + * + * @param resource $src Image resource + * @param int $x X position + * @param int $y Y position + * @param int $width Image width + * @param int $height Image height + * @param int $area Area to calculate average color + * + * @return int + * + * @since 1.0.0 + */ private static function getAverageColor($src, $x, $y, $width, $height, $area = 10) : int { $colors = []; diff --git a/Utils/NumericUtils.php b/Utils/NumericUtils.php index a134ec9ef..8b3111170 100755 --- a/Utils/NumericUtils.php +++ b/Utils/NumericUtils.php @@ -47,7 +47,7 @@ final class NumericUtils public static function uRightShift(int $a, int $b) : int { if ($b >= 32 || $b < -32) { - $m = (int) ($b / 32); + $m = (int) ($b / 32); $b -= $m * 32; } @@ -61,8 +61,8 @@ final class NumericUtils if ($a < 0) { $a >>= 1; - $a &= 0x7fffffff; - $a |= 0x40000000; + $a &= 0x7fffffff; + $a |= 0x40000000; $a >>= $b - 1; } else { $a >>= $b; diff --git a/Utils/RnG/Text.php b/Utils/RnG/Text.php index 45fe3577f..6f6adc8e8 100755 --- a/Utils/RnG/Text.php +++ b/Utils/RnG/Text.php @@ -195,7 +195,7 @@ class Text } /* Handle comma */ - $posComma = []; + $posComma = []; if (\mt_rand(0, 100) <= $probComma * 100 && $sentenceLength >= 2 * $minCommaSpacing) { $posComma[] = \mt_rand($minCommaSpacing, $sentenceLength - $minCommaSpacing);