From 29707c42036199864c0ad3cad2de2da4857c4a87 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 7 May 2016 17:23:44 +0200 Subject: [PATCH] Formatting and bug fixes --- Account/Account.php | 14 +- DataStorage/Database/DataMapperAbstract.php | 2 + Math/Differential/FiniteDifference.php | 1 + Math/Function/Fibunacci.php | 3 +- Math/Parser/Evaluator.php | 60 ++++++ Math/Shape/D2/Polygon.php | 1 + Math/Shape/D3/Sphere.php | 2 +- Module/ModuleAbstract.php | 3 - Socket/Client/Client.php | 1 + Socket/Client/ClientConnection.php | 3 - Socket/Client/NullClientConnection.php | 3 - System/File/Directory.php | 1 + Utils/Converter/Currency.php | 8 +- Utils/IO/Csv/CsvDatabaseMapper.php | 3 +- Utils/Parser/Php/FunctionParser.php | 228 +++++++++++++++++++- Utils/TaskSchedule/CronJob.php | 2 +- 16 files changed, 315 insertions(+), 20 deletions(-) diff --git a/Account/Account.php b/Account/Account.php index 7b5503093..1b66e090e 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -295,7 +295,7 @@ class Account } /** - * Get last activity. + * Get created at. * * @return \DateTime * @@ -410,7 +410,7 @@ class Account } /** - * Get last activity. + * Update last activity. * * @return void * @@ -422,6 +422,16 @@ class Account $this->lastActive = new \DateTime('NOW'); } + /** + * Set created at. + * + * @param \DateTime $created Created at + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setCreatedAt(\DateTime $created) { $this->createdAt = $created; diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index dfb5a398c..d144815b6 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -314,6 +314,7 @@ abstract class DataMapperAbstract implements DataMapperInterface /* Create extended */ foreach (static::$isExtending as $member => $rel) { + /** @var DataMapperAbstract $mapper */ $mapper = new $rel['mapper']($this->db); $extendedIds[$member] = $mapper->create($obj, $relations); } @@ -599,6 +600,7 @@ abstract class DataMapperAbstract implements DataMapperInterface foreach (static::$isExtending as $member => $rel) { $reflectionProperty = $reflectionClass->getProperty($member); + /** @var DataMapperAbstract $mapper */ $mapper = new $rel['mapper']($this->db); $mapper->get($reflectionProperty->getValue($obj), $relations, $obj); } diff --git a/Math/Differential/FiniteDifference.php b/Math/Differential/FiniteDifference.php index 32938b145..039a48bbc 100644 --- a/Math/Differential/FiniteDifference.php +++ b/Math/Differential/FiniteDifference.php @@ -15,6 +15,7 @@ */ namespace phpOMS\Math\Differential; +use phpOMS\Math\Parser\Evaluator; /** * Chi square distribution. diff --git a/Math/Function/Fibunacci.php b/Math/Function/Fibunacci.php index 54b7e6e15..8ea15d2fa 100644 --- a/Math/Function/Fibunacci.php +++ b/Math/Function/Fibunacci.php @@ -15,6 +15,7 @@ */ namespace phpOMS\Math; +use phpOMS\Math\Number\Numbers; /** * Well known functions class. @@ -31,7 +32,7 @@ class Fibunacci { public static function isFibunacci(int $n) { - return Functions::isSquare(5 * $n ** 2 + 4) || Functions::isSquare(5 * $n ** 2 - 4); + return Numbers::isSquare(5 * $n ** 2 + 4) || Numbers::isSquare(5 * $n ** 2 - 4); } public static function fibunacci(int $n, int $start = 1) : int diff --git a/Math/Parser/Evaluator.php b/Math/Parser/Evaluator.php index e69de29bb..81cab216f 100644 --- a/Math/Parser/Evaluator.php +++ b/Math/Parser/Evaluator.php @@ -0,0 +1,60 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\Math\Parser; + +/** + * Shape interface. + * + * @category Framework + * @package phpOMS\Math + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Evaluator +{ + /** + * Evaluate function. + * + * Example: ('2*x^3-4x', ['x' => 99]) + * + * @param string $formula Formula to differentiate + * @param array $vars Variables to evaluate + * + * @return float + * + * @throws \Exception + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function evaluate(string $formula, array $vars) : float + { + // todo: do i need array_values here? + $formula = str_replace(array_keys($vars), array_values($vars), $formula); + + // todo: this is horrible in case things like mod etc. need to be supported + if (preg_match('#[^0-9\+\-\*\/\(\)]#', $formula)) { + throw new \Exception('Bad elements'); + } + + // todo: create parser + + return 0; + } +} diff --git a/Math/Shape/D2/Polygon.php b/Math/Shape/D2/Polygon.php index bf03cace8..39505cae3 100644 --- a/Math/Shape/D2/Polygon.php +++ b/Math/Shape/D2/Polygon.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\Math\Shape\D2; +use phpOMS\Math\Shape\ShapeInterface; /** diff --git a/Math/Shape/D3/Sphere.php b/Math/Shape/D3/Sphere.php index cece3c0e0..16260d77e 100644 --- a/Math/Shape/D3/Sphere.php +++ b/Math/Shape/D3/Sphere.php @@ -50,7 +50,7 @@ class Sphere $latTo = deg2rad($latEnd); $lonTo = deg2rad($longEnd); - $latDelta = $latTo - $latFrom; + //$latDelta = $latTo - $latFrom; $lonDelta = $lonTo - $lonFrom; $a = pow(cos($latTo) * sin($lonDelta), 2) + pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2); diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 98848a171..7fe5c3746 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -15,9 +15,6 @@ */ namespace phpOMS\Module; -use phpOMS\System\File\PathException; - - /** * Module abstraction class. * diff --git a/Socket/Client/Client.php b/Socket/Client/Client.php index 4be78e03c..14aae8a34 100644 --- a/Socket/Client/Client.php +++ b/Socket/Client/Client.php @@ -31,6 +31,7 @@ use phpOMS\Socket\SocketAbstract; */ class Client extends SocketAbstract { + private $commands; /** * Constructor. diff --git a/Socket/Client/ClientConnection.php b/Socket/Client/ClientConnection.php index e3f4205a6..9dce6201d 100644 --- a/Socket/Client/ClientConnection.php +++ b/Socket/Client/ClientConnection.php @@ -15,9 +15,6 @@ */ namespace phpOMS\Socket\Client; -use phpOMS\Socket\CommandManager; -use phpOMS\Socket\SocketAbstract; - /** * Client socket class. * diff --git a/Socket/Client/NullClientConnection.php b/Socket/Client/NullClientConnection.php index 56b5eff84..2f8b3db9d 100644 --- a/Socket/Client/NullClientConnection.php +++ b/Socket/Client/NullClientConnection.php @@ -15,9 +15,6 @@ */ namespace phpOMS\Socket\Client; -use phpOMS\Socket\CommandManager; -use phpOMS\Socket\SocketAbstract; - /** * Client socket class. * diff --git a/System/File/Directory.php b/System/File/Directory.php index 22128c0f5..71cd22b72 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -14,6 +14,7 @@ * @link http://orange-management.com */ namespace phpOMS\System\File; +use phpOMS\Validation\Validator; /** * Filesystem class. diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index 93aa675d3..0946f4480 100644 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -65,6 +65,8 @@ class Currency * * @return array * + * @throws \Exception + * * @since 1.0.0 * @author Dennis Eichhorn */ @@ -74,7 +76,11 @@ class Currency $xml = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'); $xml = new \SimpleXMLElement($xml); - $node = $xml->Cube->Cube->Cube; + if (isset($xml->Cube)) { + $node = $xml->Cube->Cube->Cube; + } else { + throw new \Exception('Invalid xml path'); + } self::$ecbCurrencies = []; foreach ($node as $key => $value) { diff --git a/Utils/IO/Csv/CsvDatabaseMapper.php b/Utils/IO/Csv/CsvDatabaseMapper.php index c28005e8e..eabab036b 100644 --- a/Utils/IO/Csv/CsvDatabaseMapper.php +++ b/Utils/IO/Csv/CsvDatabaseMapper.php @@ -15,6 +15,7 @@ */ namespace phpOMS\Utils\IO\Csv; +use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\Utils\IO\IODatabaseMapper; @@ -32,7 +33,7 @@ class CsvDatabaseMapper implements IODatabaseMapper private $autoIdentifyCsvSettings = false; - public function __construct($db) + public function __construct(ConnectionAbstract $db) { $this->db = $db; } diff --git a/Utils/Parser/Php/FunctionParser.php b/Utils/Parser/Php/FunctionParser.php index dc39586ae..2012022ea 100644 --- a/Utils/Parser/Php/FunctionParser.php +++ b/Utils/Parser/Php/FunctionParser.php @@ -30,77 +30,233 @@ namespace phpOMS\Utils\Parser\Php; */ class FunctionParser { + /** + * Function name. + * + * @var string + * @since 1.0.0 + */ private $name = ''; + /** + * Function visibility. + * + * @var string + * @since 1.0.0 + */ private $visibility = Visibility::_PUBLIC; + /** + * Is static? + * + * @var bool + * @since 1.0.0 + */ private $isStatic = false; + /** + * Is abstract? + * + * @var bool + * @since 1.0.0 + */ private $isAbstract = false; + /** + * Is final? + * + * @var bool + * @since 1.0.0 + */ private $isFinal = false; + /** + * Return type. + * + * @var string + * @since 1.0.0 + */ private $return = null; + /** + * Parameters. + * + * @var array + * @since 1.0.0 + */ private $parameters = []; + /** + * Function body. + * + * @var string + * @since 1.0.0 + */ private $body = ''; + /** + * Set function name. + * + * @param string $name Function name + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setName(string $name) { $this->name = $name; } + /** + * Get function name. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getName() : string { return $this->name; } + /** + * Set function body. + * + * @param string $body Function body + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function seBody(string $body) { $this->body = $body; } + /** + * Get function body. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getBody() : string { return $this->body; } + /** + * Remove body. + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeBody() { - $this->body = null; + $this->body = ''; } + /** + * Set visibility. + * + * @param string $visibility Function visibility + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setVisibility(string $visibility) { $this->visibility = $visibility; } + /** + * Get function visibility. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getVisibility() : string { return $this->visibility; } + /** + * Set static. + * + * @param bool $static Is static + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setStatic(bool $static) { $this->isStatic = $static; } + /** + * Is static? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isStatic() : bool { return $this->isStatic; } + /** + * Set final. + * + * @param bool $final Is final + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setFinal(bool $final) { $this->isFinal = $final; } + /** + * Is final? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isFinal() : bool { return $this->isFinal; } + /** + * Set abstract. + * + * @param bool $abstract Is abstract + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setAbstract(bool $abstract) { $this->isAbstract = $abstract; @@ -112,27 +268,73 @@ class FunctionParser } } + /** + * Is abstract? + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isAbstract() : bool { return $this->isAbstract; } + /** + * Set return type. + * + * @param string $return Return type + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setReturn(string $return) { $this->return = $return; } + /** + * Remove return type. + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function removeReturn() { $this->return = null; } - public function getReturn() + /** + * Get return type. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getReturn() : string { return $this->return; } - public function addParameter(string $name, string $typehint, $default = null) + /** + * Add parameter to function. + * + * @param string $name Parameter name + * @param string $typehint Typehint + * @param string $default Default value + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function addParameter(string $name, string $typehint = null, string $default = null) { $this->parameters[$name]['name'] = $name; $this->parameters[$name]['typehint'] = $typehint; @@ -146,7 +348,15 @@ class FunctionParser } } - public function parse() : string + /** + * Serialize function. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function serialize() { $function = ''; $function .= str_repeat(' ', ClassParser::INDENT); @@ -184,6 +394,16 @@ class FunctionParser return $function; } + /** + * Add indention for body. + * + * @param string $body Function body to indent + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private function addIndent(string $body) : string { $body = preg_split('/\r\n|\r|\n/', $body); diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php index cf3d6417e..426a6874f 100644 --- a/Utils/TaskSchedule/CronJob.php +++ b/Utils/TaskSchedule/CronJob.php @@ -41,7 +41,7 @@ class CronJob implements TaskInterface public function __construct(Interval $interval = null, $cmd = '') { $this->interval = $interval; - $this->cmd = $cmd; + $this->command = $cmd; } public function setInterval(Interval $interval)