mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
More formatting and comment fixes
This commit is contained in:
parent
70170f0691
commit
ca0e03efc3
|
|
@ -15,13 +15,14 @@
|
|||
*/
|
||||
|
||||
namespace phpOMS\Math;
|
||||
|
||||
use phpOMS\Math\Number\Numbers;
|
||||
|
||||
/**
|
||||
* Well known functions class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @package phpOMS\Math\Function
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -30,11 +31,33 @@ use phpOMS\Math\Number\Numbers;
|
|||
*/
|
||||
class Fibunacci
|
||||
{
|
||||
public static function isFibunacci(int $n)
|
||||
|
||||
/**
|
||||
* Is fibunacci number.
|
||||
*
|
||||
* @param int $n Integer
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function isFibunacci(int $n) : bool
|
||||
{
|
||||
return Numbers::isSquare(5 * $n ** 2 + 4) || Numbers::isSquare(5 * $n ** 2 - 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get n-th fibunacci number.
|
||||
*
|
||||
* @param int $n n-th number
|
||||
* @param int $start Start value
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function fibunacci(int $n, int $start = 1) : int
|
||||
{
|
||||
if ($n < 2) {
|
||||
|
|
@ -56,6 +79,16 @@ class Fibunacci
|
|||
return $fib;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate n-th fibunacci with binets formula.
|
||||
*
|
||||
* @param int $n n-th number
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function binet(int $n) : int
|
||||
{
|
||||
return (int) (((1 + sqrt(5)) ** $n - (1 - sqrt(5)) ** $n) / (2 ** $n * sqrt(5)));
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace phpOMS\Utils\IO\Json;
|
|||
* Json decoding exception class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package IO
|
||||
* @package phpOMS\Utils\IO\Json
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
|
|
@ -28,6 +28,16 @@ namespace phpOMS\Utils\IO\Json;
|
|||
*/
|
||||
class InvalidJsonException extends \UnexpectedValueException
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct($message, $code = 0, \Exception $previous = null)
|
||||
{
|
||||
parent::__construct('Couldn\'t parse "' . $message . '" as valid json.', $code, $previous);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace phpOMS\Utils\TaskSchedule;
|
||||
|
||||
/**
|
||||
* Array utils.
|
||||
* Cron class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace phpOMS\Utils\TaskSchedule;
|
||||
|
||||
/**
|
||||
* Array utils.
|
||||
* CronJob class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
|
|
@ -29,6 +29,15 @@ namespace phpOMS\Utils\TaskSchedule;
|
|||
class CronJob extends TaskAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Interval $interval Interval
|
||||
* @param string $cmd Command to execute
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(Interval $interval = null, $cmd = '')
|
||||
{
|
||||
if (!isset($interval)) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace phpOMS\Utils\TaskSchedule;
|
||||
|
||||
/**
|
||||
* Array utils.
|
||||
* Schedule class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
|
|
@ -30,7 +30,16 @@ class Schedule extends TaskAbstract
|
|||
{
|
||||
private $name = '';
|
||||
|
||||
public function __construct(Interval $interval = null, $cmd = '')
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Interval $interval Interval
|
||||
* @param string $cmd Command to execute
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(Interval $interval = null, string $cmd = '')
|
||||
{
|
||||
if (!isset($interval)) {
|
||||
$this->interval = new Interval();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace phpOMS\Utils\TaskSchedule;
|
||||
|
||||
/**
|
||||
* Array utils.
|
||||
* Schedule Interface.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace phpOMS\Utils\TaskSchedule;
|
||||
|
||||
/**
|
||||
* Array utils.
|
||||
* Task scheduler class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
|
|
|
|||
|
|
@ -15,32 +15,71 @@
|
|||
*/
|
||||
namespace phpOMS\Validation;
|
||||
|
||||
class BitcoinValidator
|
||||
/**
|
||||
* Bitcoin validator.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BitcoinValidator extends ValidatorAbstract
|
||||
{
|
||||
public static function validate(string $addr) : bool
|
||||
/**
|
||||
* Validate bitcoin.
|
||||
*
|
||||
* @param string $addr Bitcoin address
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function isValid(string $addr) : bool
|
||||
{
|
||||
$decoded = self::decodeBase58($addr);
|
||||
try {
|
||||
$decoded = self::decodeBase58($addr);
|
||||
|
||||
$d1 = hash("sha256", substr($decoded, 0, 21), true);
|
||||
$d2 = hash("sha256", $d1, true);
|
||||
$d1 = hash("sha256", substr($decoded, 0, 21), true);
|
||||
$d2 = hash("sha256", $d1, true);
|
||||
|
||||
if (substr_compare($decoded, $d2, 21, 4)) {
|
||||
if (substr_compare($decoded, $d2, 21, 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(\Exception $e) {
|
||||
self::$msg = $e->getMessage();
|
||||
} finally {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function decodeBase58(string $input) : string
|
||||
/**
|
||||
* Decode base 58 bitcoin address.
|
||||
*
|
||||
* @param string $addr Bitcoin address
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function decodeBase58(string $addr) : string
|
||||
{
|
||||
$alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||
$alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
||||
|
||||
$out = array_fill(0, 25, 0);
|
||||
$len = strlen($input);
|
||||
$out = array_fill(0, 25, 0);
|
||||
$length = strlen($addr);
|
||||
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
if (($p = strpos($alphabet, $input[$i])) === false) {
|
||||
throw new \Exception("invalid character found");
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (($p = strpos($alphabet, $addr[$i])) === false) {
|
||||
throw new \Exception('Invalid character found in address.');
|
||||
}
|
||||
|
||||
$c = $p;
|
||||
|
|
@ -52,11 +91,11 @@ class BitcoinValidator
|
|||
}
|
||||
|
||||
if ($c !== 0) {
|
||||
throw new \Exception("address too long");
|
||||
throw new \Exception('Bitcoin address too long.');
|
||||
}
|
||||
}
|
||||
|
||||
$result = "";
|
||||
$result = '';
|
||||
foreach ($out as $val) {
|
||||
$result .= chr($val);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user