From 3ec569fa9e592523eb7450071b7c77fa95bd6b98 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 15 Nov 2016 21:25:39 +0100 Subject: [PATCH] Comments --- Account/Group.php | 17 ++ DataStorage/Database/GrammarAbstract.php | 40 +++ DataStorage/Database/Query/Builder.php | 140 ++++++++++ .../Database/Query/Grammar/Grammar.php | 15 ++ DataStorage/Session/HttpSession.php | 28 +- Log/FileLogger.php | 10 +- Math/Functions/Functions.php | 44 +++ Stdlib/Collection/Collection.php | 127 ++++++++- Stdlib/Graph/BinaryTree.php | 87 +++++- Stdlib/Graph/Graph.php | 254 ++++++++++++++++-- Stdlib/Graph/Tree.php | 112 +++++++- System/File/Storage.php | 6 + Utils/TaskSchedule/TaskScheduler.php | 47 +++- 13 files changed, 890 insertions(+), 37 deletions(-) diff --git a/Account/Group.php b/Account/Group.php index b2681635a..159698ade 100644 --- a/Account/Group.php +++ b/Account/Group.php @@ -179,13 +179,30 @@ class Group implements ArrayableInterface, \JsonSerializable $this->description = $description; } + /** + * Get group status. + * + * @return int Group status + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getStatus() : int { return $this->status; } + /** + * Set group status. + * + * @param int $status Group status + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setStatus(int $status) { + // todo: check valid $this->status = $status; } diff --git a/DataStorage/Database/GrammarAbstract.php b/DataStorage/Database/GrammarAbstract.php index d101ae81f..1c91395c3 100644 --- a/DataStorage/Database/GrammarAbstract.php +++ b/DataStorage/Database/GrammarAbstract.php @@ -69,6 +69,12 @@ abstract class GrammarAbstract */ protected $or = 'OR'; + /** + * Table prefix. + * + * @var string + * @since 1.0.0 + */ protected $tablePrefix = ''; /** @@ -95,18 +101,52 @@ abstract class GrammarAbstract ) . ';'; } + /** + * Compile query components. + * + * @param BuilderAbstract $query Builder + * + * @return array Parsed query components + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ abstract protected function compileComponents(BuilderAbstract $query) : array; + /** + * Get date format. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDateFormat() : string { return 'Y-m-d H:i:s'; } + /** + * Get table prefix. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getTablePrefix() : string { return $this->tablePrefix; } + /** + * Set table prefix. + * + * @param string $prefix Table prefix + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setTablePrefix(string $prefix) { $this->tablePrefix = $prefix; diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 3ae96bb4a..ffa6ce35e 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -704,43 +704,103 @@ class Builder extends BuilderAbstract return $this; } + /** + * Lock query. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function lock() { } + /** + * Lock for update query. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function lockUpdate() { } + /** + * Create query string. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __toString() { return $this->grammar->compileQuery($this); } + /** + * Find query. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function find() { } + /** + * Count results. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function count() { } + /** + * Check if exists. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function exists() { } + /** + * Select minimum. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function min() { } + /** + * Select maximum. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function max() { } + /** + * Select sum. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function sum() { } + /** + * Select average. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function avg() { } @@ -821,6 +881,16 @@ class Builder extends BuilderAbstract return $this; } + /** + * Update columns. + * + * @param array $columns Column names to update + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function update(...$columns) : Builder { $this->type = QueryType::UPDATE; @@ -832,44 +902,106 @@ class Builder extends BuilderAbstract return $this; } + /** + * Increment value. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function increment() { } + /** + * Decrement value. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function decrement() { } + /** + * Join. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function join($table1, $table2, $column1, $opperator, $column2) { return $this; } + /** + * Join where. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function joinWhere() { } + /** + * Left join. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function leftJoin() { } + /** + * Left join where. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function leftJoinWhere() { } + /** + * Right join. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function rightJoin() { } + /** + * Right join where. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function rightJoinWhere() { } + /** + * Rollback. + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function rollback() { return $this; } + /** + * On. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function on() { @@ -892,6 +1024,14 @@ class Builder extends BuilderAbstract return clone($this); } + /** + * Execute query. + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function execute() { $sth = $this->connection->con->prepare($this->toSql()); diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index adfc0af90..91a5a99e1 100644 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -214,6 +214,18 @@ class Grammar extends GrammarAbstract return 'WHERE ' . $expression; } + /** + * Compile where element. + * + * @param array $element Element data + * @param Builder $query Query builder + * @param bool $first Is first element (usefull for nesting) + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ protected function compileWhereElement(array $element, Builder $query, bool $first = true) : string { $expression = ''; @@ -265,6 +277,9 @@ class Grammar extends GrammarAbstract return $value; } + // todo: fix for injection + // todo: implement binding + return $this->valueQuotes . $value . $this->valueQuotes; } elseif (is_int($value)) { return $value; diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 926439333..1514d4c03 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -129,12 +129,26 @@ class HttpSession implements SessionInterface return $this->sessionData[$key] ?? null; } + /** + * Lock session from further adjustments. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function lock() { self::$isLocked = true; } - public static function isLocked() + /** + * Check if session is locked. + * + * @return bool Lock status + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function isLocked() : bool { return self::$isLocked; } @@ -177,10 +191,18 @@ class HttpSession implements SessionInterface $this->sid = $sid; } + /** + * Destruct session. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __destruct() { - $_SESSION = $this->sessionData; - session_write_close(); + if(!self::$isLocked) { + $_SESSION = $this->sessionData; + session_write_close(); + } } } diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 216fd62c0..93a32da8a 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -119,9 +119,17 @@ class FileLogger implements LoggerInterface $this->path = $path; } + /** + * Create logging file. + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private function createFile() { - if (!file_exists($this->path) && !$this->created) { + if (!$this->created && !file_exists($this->path)) { File::create($this->path); $this->created = true; } diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index 2728e6e2b..5ea36b9fd 100644 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -206,6 +206,17 @@ class Functions return $t; } + /** + * Modular implementation for negative values. + * + * @param int $a + * @param int $b + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function mod($a, $b) { if ($a < 0) { @@ -215,6 +226,16 @@ class Functions return $a % $b; } + /** + * Check if value is odd. + * + * @param int $a Value to test + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function isOdd($a) : bool { if ($a & 1) { @@ -224,6 +245,16 @@ class Functions return false; } + /** + * Check if value is even. + * + * @param int $a Value to test + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function isEven($a) : bool { if ($a & 1) { @@ -233,6 +264,19 @@ class Functions return true; } + /** + * Gets the relative position on a circular construct. + * + * @example The relative fiscal month (August) in a company where the fiscal year starts in July. + * @example 2 = getRelativeDegree(8, 12, 7); + * + * @param int $a Value to test + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function getRelativeDegree($value, $length, $start = 0) { return abs(self::mod($value - $start, $length)); diff --git a/Stdlib/Collection/Collection.php b/Stdlib/Collection/Collection.php index 5367be1d8..3ccb31be9 100644 --- a/Stdlib/Collection/Collection.php +++ b/Stdlib/Collection/Collection.php @@ -18,7 +18,7 @@ namespace phpOMS\Stdlib\Collection; use phpOMS\Utils\ArrayUtils; /** - * Multimap utils. + * Collection. * * @category Framework * @package phpOMS\Stdlib @@ -30,28 +30,78 @@ use phpOMS\Utils\ArrayUtils; */ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializable { + /** + * Collection. + * + * @var array + * @since 1.0.0 + */ private $collection = []; + /** + * Create collection from array. + * + * @param array $data Collection data + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __construct(array $data) { $this->collection = $data; } + /** + * Turn collection to array. + * + * @return array Collection array representation + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function toArray() : array { return $this->collection; } + /** + * Json serialize. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function jsonSerialize() { return json_encode($this->collection); } + /** + * Get average of collection data. + * + * @param mixed $filter Filter for average calculation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function avg($filter = null) { return $this->sum($filter) / $this->count(); } + /** + * Get sum of collection data. + * + * @param mixed $filter Filter for sum calculation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function sum($filter = null) { $sum = 0; @@ -77,16 +127,51 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab return $sum; } + /** + * Get collection count. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function count() { return count($this->collection); } - public function chunk(int $size) : Collection + /** + * Chunk collection. + * + * Creates new collection in the specified size. + * + * @param int $size Chunk size + * + * @return Collection[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function chunk(int $size) : array { - return new self(array_chunk($this->collection, $size)); + $arrays = array_chunk($this->collection, $size); + $collections = []; + + foreach($arrays as $array) { + $collections[] = new self($array); + } + + return $collections; } + /** + * Collapse collection. + * + * @return Collection + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function collapse() : Collection { $return = []; @@ -116,12 +201,22 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab return $this; } + /** + * Check if collection contains a value. + * + * @param string|int|float|\Closure $find Needle + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function contains($find) : bool { foreach ($this->collection as $key => $value) { if (is_string($find) && ((is_string($value) && $find === $value) || (is_array($value) && in_array($find, $value)))) { return true; - } elseif ($find instanceof Collection) { + } elseif ($find instanceof \Closure) { $result = $find($value, $key); if ($result) { @@ -133,13 +228,23 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab return false; } - public function diff(array $compare) : array + /** + * Diff of collection. + * + * @param Collection|array $compare To compare with + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function diff($compare) : array { $diff = []; foreach ($this->collection as $key => $value) { if ($value !== current($compare)) { - $diff = $value; + $diff[] = $value; } next($compare); @@ -163,6 +268,16 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab return $diff; } + /** + * Get collection that contains every n-th element. + * + * @param $int $n Every n-th element + * + * @return Collection + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function every(int $n) : Collection { $values = array_values($this->collection); diff --git a/Stdlib/Graph/BinaryTree.php b/Stdlib/Graph/BinaryTree.php index e84bf8736..1255068eb 100644 --- a/Stdlib/Graph/BinaryTree.php +++ b/Stdlib/Graph/BinaryTree.php @@ -43,6 +43,16 @@ class BinaryTree extends Tree return $list; } + /** + * Get left node of a node. + * + * @param Node $node Tree node + * + * @return Node Left node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getLeft(Node $base) { $neighbors = $base->getNeighbors($base); @@ -51,6 +61,16 @@ class BinaryTree extends Tree return $neighbors[0] ?? null; } + /** + * Get right node of a node. + * + * @param Node $node Tree node + * + * @return Node Right node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getRight(Node $base) { $neighbors = $base->getNeighbors($base); @@ -59,7 +79,18 @@ class BinaryTree extends Tree return $neighbors[1] ?? null; } - public function setLeft(Node $base, Node $left) + /** + * Set left node of node. + * + * @param Node $base Base node + * @param Node $left Left node + * + * @return BinaryTree + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setLeft(Node $base, Node $left) : BinaryTree { if($this->getLeft($base) === null) { $this->addNode($base, $left); @@ -68,8 +99,21 @@ class BinaryTree extends Tree } else { // todo: replace node } + + return $this; } + /** + * Set right node of node. + * + * @param Node $base Base node + * @param Node $right Right node + * + * @return BinaryTree + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setRight(Node $base, Node $right) { if($this->getRight($base) === null) { @@ -81,17 +125,32 @@ class BinaryTree extends Tree } } + /** + * Perform action on tree in in-order. + * + * @param Node $node Tree node + * @param \Closure $callback Task to perform on node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function inOrder(Node $node, \Closure $callback) { - if(count($this->nodes) === 0) { - return; - } - $this->inOrder($this->getLeft($node), $callback); $callback($node); $this->inOrder($this->getRight($node), $callback); } + /** + * Get nodes in vertical order. + * + * @param Node $node Tree node + * @param int $horizontalDistance Horizontal distance + * @param Node[] &$order Ordered nodes by horizontal distance + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private function getVerticalOrder(Node $node, int $horizontalDistance = 0, array &$order) { if(!isset($order[$horizontalDistance])) { @@ -111,6 +170,15 @@ class BinaryTree extends Tree } } + /** + * Perform action on tree in vertical-order. + * + * @param Node $node Tree node + * @param \Closure $callback Task to perform on node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function verticalOrder(Node $node, \Closure $callback) { $order = []; @@ -123,6 +191,15 @@ class BinaryTree extends Tree } } + /** + * Check if tree is symmetric. + * + * @param Node $node1 Tree node1 + * @param Node $node2 Tree node2 (optional, can be different tree) + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isSymmetric(Node $node1 = null, Node $node2 = null) : bool { if(!isset($node1) && !isset($node2)) { diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index c300429ee..fdb493e7e 100644 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -28,31 +28,85 @@ namespace phpOMS\Stdlib\Graph; */ class Graph { + /** + * Nodes. + * + * @var array + * @since 1.0.0 + */ protected $nodes = []; + /** + * Edges. + * + * @var array + * @since 1.0.0 + */ protected $edges = []; - public function addNode(Node $node) + /** + * Add node to graph. + * + * @param Node $node Graph node + * + * @return Graph + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function addNode(Node $node) : Graph { $this->nodes[] = $node; return $this; } - public function setNode($key, Node $node) + /** + * Set node in graph. + * + * @param mixed $key Key of node + * @param Node $node Graph node + * + * @return Graph + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setNode($key, Node $node) : Graph { $this->nodes[$key] = $node; return $this; } - public function addEdge(Edge $edge) + /** + * Add edge to graph. + * + * @param Edge $edge Graph edge + * + * @return Graph + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function addEdge(Edge $edge) : Graph { $this->edges[] = $edge; return $this; } + /** + * Set edge in graph. + * + * @param mixed $key Edge key + * @param Edge $edge Edge to set + * + * @return Graph + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function setEdge($key, Edge $edge) { $this->edges[$key] = $edge; @@ -60,16 +114,46 @@ class Graph return $this; } + /** + * Get graph node + * + * @param mixed $key Node key + * + * @return Node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getNode($key) : Node { return $this->nodes[$key]; } + /** + * Get graph edge. + * + * @param mixed $key Edge key + * + * @return Edge + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getEdge($key) : Edge { return $this->edges[$key]; } + /** + * Get all edges of a node + * + * @param mixed $node Node + * + * @return Edge[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getEdgesOfNode($node) : array { if(!($node instanceof Node)) { @@ -88,6 +172,16 @@ class Graph return $edges; } + /** + * Get all node neighbors. + * + * @param Node $node Graph node + * + * @return Node[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getNeighbors($node) : array { if(!($node instanceof Node)) { @@ -110,71 +204,196 @@ class Graph return $neighbors; } + /** + * Get graph dimension. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDimension() : int { + // todo: implement return 0; } + /** + * Get all bridges. + * + * @return Edge[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getBridges() : array { + // todo: implement return []; } + /** + * Get minimal spanning tree using Kruskal's algorithm. + * + * @return Tree + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getKruskalMinimalSpanningTree() : Tree { + // todo: implement return new Tree(); } + /** + * Get minimal spanning tree using Prim's algorithm + * + * @return Tree + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getPrimMinimalSpanningTree() : Tree { + // todo: implement return new Tree(); } + /** + * Get circles in graph. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getCircle() : array { - + // todo: implement } + /** + * Get shortest path using Floyd Warschall algorithm. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getFloydWarshallShortestPath() : array { - + // todo: implement } + /** + * Get shortest path using Dijkstra algorithm. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDijkstraShortestPath() : array { - + // todo: implement } + /** + * Perform depth first traversal. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function depthFirstTraversal() : array { - + // todo: implement } + /** + * Perform breadth first traversal. + * + * @return array + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function breadthFirstTraversal() : array { - + // todo: implement } + /** + * Get longest path in graph. + * + * @return Node[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function longestPath() : array { - + // todo: implement } - public function longestPathBetweenNodes() : array + /** + * Get longest path between two nodes. + * + * @param Node $node1 Graph node + * @param Node $node2 Graph node + * + * @return Node[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function longestPathBetweenNodes(Node $node1, Node $node2) : array { - + // todo: implement } + /** + * Get order of the graph. + * + * The order of a graph is the amount of nodes it contains. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getOrder() : int { return count($this->nodes); } + /** + * Get size of the graph. + * + * The size of the graph is the amount of edges it contains. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getSize() : int { return count($this->edges); } + /** + * Get diameter of graph. + * + * The diameter of a graph is the longest shortest path between two nodes. + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getDiameter() : int { $diameter = 0; @@ -194,46 +413,51 @@ class Graph public function getGirth() : int { - + // todo: implement } public function getCircuitRank() : int { - + // todo: implement } public function getNodeConnectivity() : int { - + // todo: implement } public function getEdgeConnectivity() : int { - + // todo: implement } public function isConnected() : bool { + // todo: implement return true; } public function getUnconnected() : array { + // todo: implement // get all unconnected sub graphs } public function isBipartite() : bool { + // todo: implement return true; } public function isTriangleFree() : bool { + // todo: implement return true; } public function isCircleFree() : bool { + // todo: implement return true; } } \ No newline at end of file diff --git a/Stdlib/Graph/Tree.php b/Stdlib/Graph/Tree.php index 2797ae0ec..2fcb61dc9 100644 --- a/Stdlib/Graph/Tree.php +++ b/Stdlib/Graph/Tree.php @@ -28,20 +28,55 @@ namespace phpOMS\Stdlib\Graph; */ class Tree extends Graph { + /** + * Root node. + * + * @var Node + * @since 1.0.0 + */ private $root = null; + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function __construct() { $root = new Node(); parent::addNode($root); } - public function addRelativeNode(Node $base, Node $node) + /** + * Add a note relative to a node. + * + * @param Node $base Base node + * @param Node $node Node to add + * + * @return Tree + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function addRelativeNode(Node $base, Node $node) : Tree { parent::addNode($node); parent::addEdge(new Edge($base, $node)); + + return $this; } + /** + * Get maximum tree depth. + * + * @param Node $node Tree node + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getMaxDepth(Node $node = null) : int { $currentNode = $node ?? $this->root; @@ -60,6 +95,16 @@ class Tree extends Graph return $depth; } + /** + * Get minimum tree path. + * + * @param Node $node Tree node + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getMinDepth(Node $node = null) : int { $currentNode = $node ?? $this->root; @@ -80,7 +125,18 @@ class Tree extends Graph return min($depth) + 1; } - public function levelOrder(\Closure $callback) + /** + * Perform task on tree nodes in level order. + * + * @param Node $node Tree node + * @param \Closure $callback Task to perform + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function levelOrder(Node $node, \Closure $callback) { $depth = $this->getMaxDepth(); @@ -90,11 +146,32 @@ class Tree extends Graph } } + /** + * Check if node is leaf. + * + * @param Node $node Tree node + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function isLeaf(Node $node) : bool { return count($this->getEdgesOfNode($node)) === 1; } + /** + * Get all nodes of a specific level. + * + * @param int $level Level to retrieve + * @param Node $node Tree node + * + * @return Node[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function getLevelNodes(int $level, Node $node) : array { --$level; @@ -112,7 +189,18 @@ class Tree extends Graph return $nodes; } - public function isFull(int $type) : bool { + /** + * Check if the tree is full. + * + * @param int $type Child nodes per non-leaf node + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function isFull(int $type) : bool + { if(count($this->edges) % $type !== 0) { return false; } @@ -128,6 +216,15 @@ class Tree extends Graph return true; } + /** + * Perform action on tree in pre-order. + * + * @param Node $node Tree node + * @param \Closure $callback Task to perform on node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function preOrder(Node $node, \Closure $callback) { if(count($this->nodes) === 0) { return; @@ -142,6 +239,15 @@ class Tree extends Graph } } + /** + * Perform action on tree in post-order. + * + * @param Node $node Tree node + * @param \Closure $callback Task to perform on node + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function postOrder(Node $node, \Closure $callback) { if(count($this->nodes) === 0) { return; diff --git a/System/File/Storage.php b/System/File/Storage.php index 11886e068..7b9c0caa8 100644 --- a/System/File/Storage.php +++ b/System/File/Storage.php @@ -38,6 +38,12 @@ final class Storage */ private static $registered = []; + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private function __construct() { diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index e37378a3f..e9055b63d 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -30,6 +30,9 @@ use phpOMS\Validation\Base\DateTime; */ class TaskScheduler extends SchedulerAbstract { + /** + * {@inheritdoc} + */ public function save() { @@ -74,12 +77,33 @@ class TaskScheduler extends SchedulerAbstract return trim($stdout); } + /** + * Normalize run result for easier parsing + * + * @param string $raw Raw command output + * + * @return string Normalized string for parsing + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private function normalize(string $raw) : string { return str_replace("\r\n", "\n", $raw); } - private function parseJobList(array $jobData) { + /** + * Parse a list of jobs + * + * @param array $jobData Csv data containing the job information + * + * @return TaskAbstract Parsed job + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + private function parseJobList(array $jobData) : TaskAbstract + { $job = TaskFactory::create($jobData[1], ''); $job->setRun($jobData[8]); @@ -109,6 +133,9 @@ class TaskScheduler extends SchedulerAbstract return $job; } + /** + * {@inheritdoc} + */ public function getAll() : array { $lines = explode("\n", $this->normalize($this->run('/query /v /fo CSV'))); @@ -122,16 +149,25 @@ class TaskScheduler extends SchedulerAbstract return $jobs; } + /** + * {@inheritdoc} + */ public function get(string $id) { - + // todo: implement } + /** + * {@inheritdoc} + */ public function getByName(string $name) : Schedule { - + // todo: implement } + /** + * {@inheritdoc} + */ public function getAllByName(string $name, bool $exact = true) : array { if($exact) { @@ -160,8 +196,11 @@ class TaskScheduler extends SchedulerAbstract return $jobs; } + /** + * {@inheritdoc} + */ public function create(Schedule $task) { - + // todo: implement } }