Merge pull request #145 from Orange-Management/scrutinizer-patch-1

Scrutinizer Auto-Fixes
This commit is contained in:
Dennis Eichhorn 2017-10-27 15:11:56 +02:00 committed by GitHub
commit 58c17101f0
7 changed files with 220 additions and 224 deletions

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Auth; namespace phpOMS\Auth;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Session\SessionInterface; use phpOMS\DataStorage\Session\SessionInterface;
/** /**

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace phpOMS\Message; namespace phpOMS\Message;
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
use phpOMS\Localization\Localization;
use phpOMS\Uri\UriInterface; use phpOMS\Uri\UriInterface;
/** /**

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace phpOMS\Module; namespace phpOMS\Module;
use phpOMS\System\File\PathException; use phpOMS\System\File\PathException;
use phpOMS\Utils\ArrayUtils;
use phpOMS\System\File\Local\File; use phpOMS\System\File\Local\File;
use phpOMS\System\File\Local\Directory; use phpOMS\System\File\Local\Directory;
use phpOMS\System\File\Local\LocalStorage; use phpOMS\System\File\Local\LocalStorage;

View File

@ -28,98 +28,98 @@ namespace phpOMS\Stdlib\Graph;
*/ */
class BinaryTree extends Tree class BinaryTree extends Tree
{ {
public static function invert($list) : BinaryTree public static function invert($list) : BinaryTree
{ {
if (empty($list->getNodes())) { if (empty($list->getNodes())) {
return $list; return $list;
} }
$left = $list->getLeft(); $left = $list->getLeft();
$list->setLeft($list->invert($list->nodes[1])); $list->setLeft($list->invert($list->nodes[1]));
$list->setRight($list->invert($left)); $list->setRight($list->invert($left));
return $list; return $list;
} }
/** /**
* Get left node of a node. * Get left node of a node.
* *
* @param Node $base Tree node * @param Node $base Tree node
* *
* @return Node Left node * @return Node Left node
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getLeft(Node $base) public function getLeft(Node $base)
{ {
$neighbors = $base->getNeighbors($base); $neighbors = $base->getNeighbors($base);
// todo: index can be wrong, see setLeft/setRight // todo: index can be wrong, see setLeft/setRight
return $neighbors[0] ?? null; return $neighbors[0] ?? null;
} }
/** /**
* Get right node of a node. * Get right node of a node.
* *
* @param Node $base Tree node * @param Node $base Tree node
* *
* @return Node Right node * @return Node Right node
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getRight(Node $base) public function getRight(Node $base)
{ {
$neighbors = $this->getNeighbors($base); $neighbors = $this->getNeighbors($base);
// todo: index can be wrong, see setLeft/setRight // todo: index can be wrong, see setLeft/setRight
return $neighbors[1] ?? null; return $neighbors[1] ?? null;
} }
/** /**
* Set left node of node. * Set left node of node.
* *
* @param Node $base Base node * @param Node $base Base node
* @param Node $left Left node * @param Node $left Left node
* *
* @return BinaryTree * @return BinaryTree
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setLeft(Node $base, Node $left) : BinaryTree public function setLeft(Node $base, Node $left) : BinaryTree
{ {
if($this->getLeft($base) === null) { if($this->getLeft($base) === null) {
$this->addNodeRelative($base, $left); $this->addNodeRelative($base, $left);
// todo: doesn't know that this is left // todo: doesn't know that this is left
// todo: maybe need to add numerics to edges? // todo: maybe need to add numerics to edges?
} else { } else {
// todo: replace node // todo: replace node
} }
return $this; return $this;
} }
/** /**
* Set right node of node. * Set right node of node.
* *
* @param Node $base Base node * @param Node $base Base node
* @param Node $right Right node * @param Node $right Right node
* *
* @return BinaryTree * @return BinaryTree
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setRight(Node $base, Node $right) /* : void */ public function setRight(Node $base, Node $right) /* : void */
{ {
if($this->getRight($base) === null) { if($this->getRight($base) === null) {
$this->addNodeRelative($base, $right); $this->addNodeRelative($base, $right);
// todo: doesn't know that this is right // todo: doesn't know that this is right
// todo: maybe need to add numerics to edges? // todo: maybe need to add numerics to edges?
} else { } else {
// todo: replace node // todo: replace node
} }
} }
/** /**
* Perform action on tree in in-order. * Perform action on tree in in-order.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -127,42 +127,42 @@ class BinaryTree extends Tree
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function inOrder(Node $node, \Closure $callback) public function inOrder(Node $node, \Closure $callback)
{ {
$this->inOrder($this->getLeft($node), $callback); $this->inOrder($this->getLeft($node), $callback);
$callback($node); $callback($node);
$this->inOrder($this->getRight($node), $callback); $this->inOrder($this->getRight($node), $callback);
} }
/** /**
* Get nodes in vertical order. * Get nodes in vertical order.
* *
* @param Node $node Tree node * @param Node $node Tree node
* @param int $horizontalDistance Horizontal distance * @param int $horizontalDistance Horizontal distance
* @param Node[] &$order Ordered nodes by horizontal distance * @param Node[] &$order Ordered nodes by horizontal distance
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private function getVerticalOrder(Node $node, int $horizontalDistance = 0, array &$order) private function getVerticalOrder(Node $node, int $horizontalDistance = 0, array &$order)
{ {
if(!isset($order[$horizontalDistance])) { if(!isset($order[$horizontalDistance])) {
$order[$horizontalDistance] = []; $order[$horizontalDistance] = [];
} }
$order[$horizontalDistance][] = $node; $order[$horizontalDistance][] = $node;
$left = $this->getLeft($node); $left = $this->getLeft($node);
$right = $this->getRight($node); $right = $this->getRight($node);
if(isset($left)) { if(isset($left)) {
$this->getVerticalOrder($left, $horizontalDistance-1, $order); $this->getVerticalOrder($left, $horizontalDistance-1, $order);
} }
if(isset($right)) { if(isset($right)) {
$this->getVerticalOrder($right, $horizontalDistance+1, $order); $this->getVerticalOrder($right, $horizontalDistance+1, $order);
} }
} }
/** /**
* Perform action on tree in vertical-order. * Perform action on tree in vertical-order.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -170,45 +170,45 @@ class BinaryTree extends Tree
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function verticalOrder(Node $node, \Closure $callback) public function verticalOrder(Node $node, \Closure $callback)
{ {
$order = []; $order = [];
$this->getVerticalOrder($node, 0, $order); $this->getVerticalOrder($node, 0, $order);
foreach($order as $level) { foreach($order as $level) {
foreach($level as $node) { foreach($level as $node) {
$callback($node); $callback($node);
} }
} }
} }
/** /**
* Check if tree is symmetric. * Check if tree is symmetric.
* *
* @param Node $node1 Tree node1 * @param Node $node1 Tree node1
* @param Node $node2 Tree node2 (optional, can be different tree) * @param Node $node2 Tree node2 (optional, can be different tree)
* *
* @return bool True if tree is symmetric, false if tree is not symmetric * @return bool True if tree is symmetric, false if tree is not symmetric
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function isSymmetric(Node $node1 = null, Node $node2 = null) : bool public function isSymmetric(Node $node1 = null, Node $node2 = null) : bool
{ {
if(!isset($node1) && !isset($node2)) { if(!isset($node1) && !isset($node2)) {
return true; return true;
} }
$left1 = $this->getLeft($node1); $left1 = $this->getLeft($node1);
$right1 = $this->getRight($node1); $right1 = $this->getRight($node1);
$left2 = isset($node2) ? $this->getLeft($node1) : $this->getLeft($node2); $left2 = isset($node2) ? $this->getLeft($node1) : $this->getLeft($node2);
$right2 = isset($node2) ? $this->getRight($node1) : $this->getRight($node2); $right2 = isset($node2) ? $this->getRight($node1) : $this->getRight($node2);
// todo: compare values? true symmetry requires the values to be the same // todo: compare values? true symmetry requires the values to be the same
if(isset($node1, $node2)) { if(isset($node1, $node2)) {
return $this->isSymmetric($left1, $right2) && $this->isSymmetric($right1, $left2); return $this->isSymmetric($left1, $right2) && $this->isSymmetric($right1, $left2);
} }
return false; return false;
} }
} }

View File

@ -26,26 +26,26 @@ namespace phpOMS\Stdlib\Graph;
*/ */
class Tree extends Graph class Tree extends Graph
{ {
/** /**
* Root node. * Root node.
* *
* @var Node * @var Node
* @since 1.0.0 * @since 1.0.0
*/ */
private $root = null; private $root = null;
/** /**
* Constructor. * Constructor.
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct() public function __construct()
{ {
$root = new Node(); $root = new Node();
parent::addNode($root); parent::addNode($root);
} }
/** /**
* Add a note relative to a node. * Add a note relative to a node.
* *
* @param Node $base Base node * @param Node $base Base node
@ -55,15 +55,15 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function addRelativeNode(Node $base, Node $node) : Tree public function addRelativeNode(Node $base, Node $node) : Tree
{ {
parent::addNode($node); parent::addNode($node);
parent::addEdge(new Edge($base, $node)); parent::addEdge(new Edge($base, $node));
return $this; return $this;
} }
/** /**
* Get maximum tree depth. * Get maximum tree depth.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -72,25 +72,25 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getMaxDepth(Node $node = null) : int public function getMaxDepth(Node $node = null) : int
{ {
$currentNode = $node ?? $this->root; $currentNode = $node ?? $this->root;
if(!isset($currentNode)) { if(!isset($currentNode)) {
return 0; return 0;
} }
$depth = 1; $depth = 1;
$neighbors = $this->getNeighbors($currentNode); $neighbors = $this->getNeighbors($currentNode);
foreach($neighbors as $neighbor) { foreach($neighbors as $neighbor) {
$depth = max($depth, $depth + $this->getMaxDepth($neighbor)); $depth = max($depth, $depth + $this->getMaxDepth($neighbor));
} }
return $depth; return $depth;
} }
/** /**
* Get minimum tree path. * Get minimum tree path.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -99,27 +99,27 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getMinDepth(Node $node = null) : int public function getMinDepth(Node $node = null) : int
{ {
$currentNode = $node ?? $this->root; $currentNode = $node ?? $this->root;
if(!isset($currentNode)) { if(!isset($currentNode)) {
return 0; return 0;
} }
$depth = []; $depth = [];
$neighbors = $this->getNeighbors($currentNode); $neighbors = $this->getNeighbors($currentNode);
foreach($neighbors as $neighbor) { foreach($neighbors as $neighbor) {
$depth[] = $this->getMaxDepth($neighbor); $depth[] = $this->getMaxDepth($neighbor);
} }
$depth = empty($depth) ? 0 : $depth; $depth = empty($depth) ? 0 : $depth;
return min($depth) + 1; return min($depth) + 1;
} }
/** /**
* Perform task on tree nodes in level order. * Perform task on tree nodes in level order.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -129,17 +129,17 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function levelOrder(Node $node, \Closure $callback) public function levelOrder(Node $node, \Closure $callback)
{ {
$depth = $this->getMaxDepth(); $depth = $this->getMaxDepth();
for($i = 1; $i < $depth; $i++) { for($i = 1; $i < $depth; $i++) {
$nodes = $this->getLevel($i); $nodes = $this->getLevel($i);
callback($nodes); callback($nodes);
} }
} }
/** /**
* Check if node is leaf. * Check if node is leaf.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -148,12 +148,12 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function isLeaf(Node $node) : bool public function isLeaf(Node $node) : bool
{ {
return count($this->getEdgesOfNode($node)) === 1; return count($this->getEdgesOfNode($node)) === 1;
} }
/** /**
* Get all nodes of a specific level. * Get all nodes of a specific level.
* *
* @param int $level Level to retrieve * @param int $level Level to retrieve
@ -163,24 +163,24 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getLevelNodes(int $level, Node $node) : array public function getLevelNodes(int $level, Node $node) : array
{ {
--$level; --$level;
$neighbors = $this->getNeighbors($node); $neighbors = $this->getNeighbors($node);
$nodes = []; $nodes = [];
if($level === 1) { if($level === 1) {
return $neighbors; return $neighbors;
} }
foreach($neighbors as $neighbor) { foreach($neighbors as $neighbor) {
array_merge($nodes, $this->getLevelNodes($level, $neighbor)); array_merge($nodes, $this->getLevelNodes($level, $neighbor));
} }
return $nodes; return $nodes;
} }
/** /**
* Check if the tree is full. * Check if the tree is full.
* *
* @param int $type Child nodes per non-leaf node * @param int $type Child nodes per non-leaf node
@ -189,24 +189,24 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function isFull(int $type) : bool public function isFull(int $type) : bool
{ {
if(count($this->edges) % $type !== 0) { if(count($this->edges) % $type !== 0) {
return false; return false;
} }
foreach($this->nodes as $node) { foreach($this->nodes as $node) {
$neighbors = count($this->getNeighbors($node)); $neighbors = count($this->getNeighbors($node));
if($neighbors !== $type && $neighbors !== 0) { if($neighbors !== $type && $neighbors !== 0) {
return false; return false;
} }
} }
return true; return true;
} }
/** /**
* Perform action on tree in pre-order. * Perform action on tree in pre-order.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -214,21 +214,21 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function preOrder(Node $node, \Closure $callback) { public function preOrder(Node $node, \Closure $callback) {
if(count($this->nodes) === 0) { if(count($this->nodes) === 0) {
return; return;
} }
$callback($node); $callback($node);
$neighbors = $this->getNeighbors($node); $neighbors = $this->getNeighbors($node);
foreach($neighbors as $neighbor) { foreach($neighbors as $neighbor) {
// todo: get neighbors needs to return in ordered way // todo: get neighbors needs to return in ordered way
$this->preOrder($neighbor, $callback); $this->preOrder($neighbor, $callback);
} }
} }
/** /**
* Perform action on tree in post-order. * Perform action on tree in post-order.
* *
* @param Node $node Tree node * @param Node $node Tree node
@ -236,18 +236,18 @@ class Tree extends Graph
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function postOrder(Node $node, \Closure $callback) { public function postOrder(Node $node, \Closure $callback) {
if(count($this->nodes) === 0) { if(count($this->nodes) === 0) {
return; return;
} }
$neighbors = $this->getNeighbors($node); $neighbors = $this->getNeighbors($node);
foreach($neighbors as $neighbor) { foreach($neighbors as $neighbor) {
// todo: get neighbors needs to return in ordered way // todo: get neighbors needs to return in ordered way
$this->postOrder($neighbor, $callback); $this->postOrder($neighbor, $callback);
} }
$callback($node); $callback($node);
} }
} }

View File

@ -29,7 +29,7 @@ namespace phpOMS\System\File;
interface FileInterface extends ContainerInterface interface FileInterface extends ContainerInterface
{ {
/** /**
* Save content to file. * Save content to file.
* *
* @param string $path File path to save the content to * @param string $path File path to save the content to
@ -106,7 +106,7 @@ interface FileInterface extends ContainerInterface
*/ */
public static function extension(string $path) : string; public static function extension(string $path) : string;
/** /**
* Save content to file. * Save content to file.
* *
* @param string $content Content to save in file * @param string $content Content to save in file

View File

@ -14,7 +14,6 @@
declare(strict_types=1); declare(strict_types=1);
namespace phpOMS\System\File\Local; namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\StorageAbstract; use phpOMS\System\File\StorageAbstract;
use phpOMS\System\File\PathException; use phpOMS\System\File\PathException;