diff --git a/Auth/Auth.php b/Auth/Auth.php index 468fd9aa2..103c8358c 100644 --- a/Auth/Auth.php +++ b/Auth/Auth.php @@ -94,6 +94,8 @@ class Auth * * @return int Login code * + * @todo move this to the admin accountMapper + * * @since 1.0.0 * @author Dennis Eichhorn */ diff --git a/Localization/Money.php b/Localization/Money.php index a54b6435a..0db8da76b 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -221,9 +221,7 @@ class Money implements \Serializable $this->value += $value; } elseif ($value instanceof Money) { $this->value += $value->getInt(); - } else { - throw new \InvalidArgumentException(); - } + } return $this; } @@ -259,10 +257,7 @@ class Money implements \Serializable $this->value -= $value; } elseif ($value instanceof Money) { $this->value -= $value->getInt(); - } else { - throw new \InvalidArgumentException(); - } - + } return $this; } diff --git a/Router/Router.php b/Router/Router.php index 2a05cca32..ec13665aa 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -100,12 +100,12 @@ class Router /** * Route request. * - * @param RequestAbstract $request Request to route + * @param string|RequestAbstract $request Request to route * @param int $verb Route verb * * @return string[] * - * @throws \Exception + * @throws \InvalidArgumentException * * @since 1.0.0 * @author Dennis Eichhorn @@ -118,7 +118,7 @@ class Router } elseif (is_string($request)) { $uri = $request; } else { - throw new \Exception(); + throw new \InvalidArgumentException(); } $bound = []; diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index 82a121be6..3e8f46fa0 100644 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -73,6 +73,34 @@ class StringUtils return false; } + /** + * Check if a string contains any of the provided needles. + * + * The validation is done case sensitive. + * + * @param string $haystack Haystack + * @param array $needles Needles to check if any of them are part of the haystack + * + * @example StringUtils::mb_contains('This string', ['This', 'test']); // true + * @example StringUtils::mb_contains('This string', 'is st'); // true + * @example StringUtils::mb_contains('This string', 'something'); // false + * + * @return bool The function returns true if any of the needles is part of the haystack, false otherwise. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function mb_contains(string $haystack, array $needles) : bool + { + foreach ($needles as $needle) { + if (mb_strpos($haystack, $needle) !== false) { + return true; + } + } + + return false; + } + /** * Tests if a string ends with a certain string. * @@ -334,4 +362,35 @@ class StringUtils return $count; } + + public static function getEntropy(string $value) : int + { + $entroy = 0; + $size = mb_strlen($value); + $countChars = self::mb_count_chars($value, 1); + + foreach ($countChars as $v) { + $p = $v / $size; + $entroy -= $p * log($p) / log(2); + } + + return $entroy; + } + + public static function mb_count_chars(string $input) { + $l = mb_strlen($input, 'UTF-8'); + $unique = []; + + for($i = 0; $i < $l; $i++) { + $char = mb_substr($input, $i, 1, 'UTF-8'); + + if(!array_key_exists($char, $unique)) { + $unique[$char] = 0; + } + + $unique[$char]++; + } + + return $unique; + } } diff --git a/Views/View.php b/Views/View.php index c1158c3bc..ef8e19c70 100644 --- a/Views/View.php +++ b/Views/View.php @@ -145,14 +145,20 @@ class View extends ViewAbstract * @param string $id Data ID * @param mixed $data Data * - * @return void + * @return bool * * @since 1.0.0 * @author Dennis Eichhorn */ - public function addData(string $id, $data) /* : void */ + public function addData(string $id, $data) : bool { + if(isset($this->data[$id])) { + return false; + } + $this->data[$id] = $data; + + return true; } /**