mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-09 13:38:41 +00:00
Fixes from tests
This commit is contained in:
parent
5c1fe7d40f
commit
eadc52d9d6
|
|
@ -94,6 +94,8 @@ class Auth
|
||||||
*
|
*
|
||||||
* @return int Login code
|
* @return int Login code
|
||||||
*
|
*
|
||||||
|
* @todo move this to the admin accountMapper
|
||||||
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -221,9 +221,7 @@ class Money implements \Serializable
|
||||||
$this->value += $value;
|
$this->value += $value;
|
||||||
} elseif ($value instanceof Money) {
|
} elseif ($value instanceof Money) {
|
||||||
$this->value += $value->getInt();
|
$this->value += $value->getInt();
|
||||||
} else {
|
}
|
||||||
throw new \InvalidArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -259,10 +257,7 @@ class Money implements \Serializable
|
||||||
$this->value -= $value;
|
$this->value -= $value;
|
||||||
} elseif ($value instanceof Money) {
|
} elseif ($value instanceof Money) {
|
||||||
$this->value -= $value->getInt();
|
$this->value -= $value->getInt();
|
||||||
} else {
|
}
|
||||||
throw new \InvalidArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,12 +100,12 @@ class Router
|
||||||
/**
|
/**
|
||||||
* Route request.
|
* Route request.
|
||||||
*
|
*
|
||||||
* @param RequestAbstract $request Request to route
|
* @param string|RequestAbstract $request Request to route
|
||||||
* @param int $verb Route verb
|
* @param int $verb Route verb
|
||||||
*
|
*
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \InvalidArgumentException
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
|
@ -118,7 +118,7 @@ class Router
|
||||||
} elseif (is_string($request)) {
|
} elseif (is_string($request)) {
|
||||||
$uri = $request;
|
$uri = $request;
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception();
|
throw new \InvalidArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$bound = [];
|
$bound = [];
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,34 @@ class StringUtils
|
||||||
return false;
|
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.
|
* Tests if a string ends with a certain string.
|
||||||
*
|
*
|
||||||
|
|
@ -334,4 +362,35 @@ class StringUtils
|
||||||
|
|
||||||
return $count;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,14 +145,20 @@ class View extends ViewAbstract
|
||||||
* @param string $id Data ID
|
* @param string $id Data ID
|
||||||
* @param mixed $data Data
|
* @param mixed $data Data
|
||||||
*
|
*
|
||||||
* @return void
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
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;
|
$this->data[$id] = $data;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user