Formatting and bug fixes

This commit is contained in:
Dennis Eichhorn 2016-05-07 17:23:44 +02:00
parent bfaa80e4ca
commit 29707c4203
16 changed files with 315 additions and 20 deletions

View File

@ -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 <d.eichhorn@oms.com>
*/
public function setCreatedAt(\DateTime $created)
{
$this->createdAt = $created;

View File

@ -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);
}

View File

@ -15,6 +15,7 @@
*/
namespace phpOMS\Math\Differential;
use phpOMS\Math\Parser\Evaluator;
/**
* Chi square distribution.

View File

@ -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

View File

@ -0,0 +1,60 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <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 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 <d.eichhorn@oms.com>
*/
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;
}
}

View File

@ -14,6 +14,7 @@
* @link http://orange-management.com
*/
namespace phpOMS\Math\Shape\D2;
use phpOMS\Math\Shape\ShapeInterface;
/**

View File

@ -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);

View File

@ -15,9 +15,6 @@
*/
namespace phpOMS\Module;
use phpOMS\System\File\PathException;
/**
* Module abstraction class.
*

View File

@ -31,6 +31,7 @@ use phpOMS\Socket\SocketAbstract;
*/
class Client extends SocketAbstract
{
private $commands;
/**
* Constructor.

View File

@ -15,9 +15,6 @@
*/
namespace phpOMS\Socket\Client;
use phpOMS\Socket\CommandManager;
use phpOMS\Socket\SocketAbstract;
/**
* Client socket class.
*

View File

@ -15,9 +15,6 @@
*/
namespace phpOMS\Socket\Client;
use phpOMS\Socket\CommandManager;
use phpOMS\Socket\SocketAbstract;
/**
* Client socket class.
*

View File

@ -14,6 +14,7 @@
* @link http://orange-management.com
*/
namespace phpOMS\System\File;
use phpOMS\Validation\Validator;
/**
* Filesystem class.

View File

@ -65,6 +65,8 @@ class Currency
*
* @return array
*
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
@ -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) {

View File

@ -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;
}

View File

@ -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 <d.eichhorn@oms.com>
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* Get function name.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName() : string
{
return $this->name;
}
/**
* Set function body.
*
* @param string $body Function body
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function seBody(string $body)
{
$this->body = $body;
}
/**
* Get function body.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getBody() : string
{
return $this->body;
}
/**
* Remove body.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function removeBody()
{
$this->body = null;
$this->body = '';
}
/**
* Set visibility.
*
* @param string $visibility Function visibility
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setVisibility(string $visibility)
{
$this->visibility = $visibility;
}
/**
* Get function visibility.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getVisibility() : string
{
return $this->visibility;
}
/**
* Set static.
*
* @param bool $static Is static
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setStatic(bool $static)
{
$this->isStatic = $static;
}
/**
* Is static?
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function isStatic() : bool
{
return $this->isStatic;
}
/**
* Set final.
*
* @param bool $final Is final
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setFinal(bool $final)
{
$this->isFinal = $final;
}
/**
* Is final?
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function isFinal() : bool
{
return $this->isFinal;
}
/**
* Set abstract.
*
* @param bool $abstract Is abstract
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public function isAbstract() : bool
{
return $this->isAbstract;
}
/**
* Set return type.
*
* @param string $return Return type
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setReturn(string $return)
{
$this->return = $return;
}
/**
* Remove return type.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function removeReturn()
{
$this->return = null;
}
public function getReturn()
/**
* Get return type.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
private function addIndent(string $body) : string
{
$body = preg_split('/\r\n|\r|\n/', $body);

View File

@ -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)