From ca0e03efc36e2bb185b2b5af444636f4cf4116e1 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 7 May 2016 23:58:31 +0200 Subject: [PATCH] More formatting and comment fixes --- Math/Function/Fibunacci.php | 37 +++++++++++- Utils/IO/Json/InvalidJsonException.php | 12 +++- Utils/TaskSchedule/Cron.php | 2 +- Utils/TaskSchedule/CronJob.php | 11 +++- Utils/TaskSchedule/Schedule.php | 13 ++++- Utils/TaskSchedule/ScheduleInterface.php | 2 +- Utils/TaskSchedule/TaskScheduler.php | 2 +- Validation/BitcoinValidator.php | 73 ++++++++++++++++++------ 8 files changed, 126 insertions(+), 26 deletions(-) diff --git a/Math/Function/Fibunacci.php b/Math/Function/Fibunacci.php index 8ea15d2fa..1ec0b103d 100644 --- a/Math/Function/Fibunacci.php +++ b/Math/Function/Fibunacci.php @@ -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 * @author Dennis Eichhorn * @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 + */ + 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 + */ 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 + */ public static function binet(int $n) : int { return (int) (((1 + sqrt(5)) ** $n - (1 - sqrt(5)) ** $n) / (2 ** $n * sqrt(5))); diff --git a/Utils/IO/Json/InvalidJsonException.php b/Utils/IO/Json/InvalidJsonException.php index 714199557..bb92c610d 100644 --- a/Utils/IO/Json/InvalidJsonException.php +++ b/Utils/IO/Json/InvalidJsonException.php @@ -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 * @author Dennis Eichhorn * @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 + */ public function __construct($message, $code = 0, \Exception $previous = null) { parent::__construct('Couldn\'t parse "' . $message . '" as valid json.', $code, $previous); diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php index 93ec83ea9..64b446cb1 100644 --- a/Utils/TaskSchedule/Cron.php +++ b/Utils/TaskSchedule/Cron.php @@ -16,7 +16,7 @@ namespace phpOMS\Utils\TaskSchedule; /** - * Array utils. + * Cron class. * * @category Framework * @package phpOMS\Utils\TaskSchedule diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php index ba314f425..dd91e8504 100644 --- a/Utils/TaskSchedule/CronJob.php +++ b/Utils/TaskSchedule/CronJob.php @@ -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 + */ public function __construct(Interval $interval = null, $cmd = '') { if (!isset($interval)) { diff --git a/Utils/TaskSchedule/Schedule.php b/Utils/TaskSchedule/Schedule.php index 608cfc6d5..8dc669eb5 100644 --- a/Utils/TaskSchedule/Schedule.php +++ b/Utils/TaskSchedule/Schedule.php @@ -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 + */ + public function __construct(Interval $interval = null, string $cmd = '') { if (!isset($interval)) { $this->interval = new Interval(); diff --git a/Utils/TaskSchedule/ScheduleInterface.php b/Utils/TaskSchedule/ScheduleInterface.php index a56bf97ec..98fed581a 100644 --- a/Utils/TaskSchedule/ScheduleInterface.php +++ b/Utils/TaskSchedule/ScheduleInterface.php @@ -16,7 +16,7 @@ namespace phpOMS\Utils\TaskSchedule; /** - * Array utils. + * Schedule Interface. * * @category Framework * @package phpOMS\Utils\TaskSchedule diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index 8e4891830..88bc34ee8 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -16,7 +16,7 @@ namespace phpOMS\Utils\TaskSchedule; /** - * Array utils. + * Task scheduler class. * * @category Framework * @package phpOMS\Utils\TaskSchedule diff --git a/Validation/BitcoinValidator.php b/Validation/BitcoinValidator.php index bed29dcad..86a227349 100644 --- a/Validation/BitcoinValidator.php +++ b/Validation/BitcoinValidator.php @@ -15,32 +15,71 @@ */ namespace phpOMS\Validation; -class BitcoinValidator +/** + * Bitcoin validator. + * + * @category Framework + * @package phpOMS\Utils\TaskSchedule + * @author OMS Development Team + * @author Dennis Eichhorn + * @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 + */ + 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 + */ + 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); }