for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Ptypes;
use Ptypes\TreeNode;
use Ptypes\Exceptions\UnexpectedType;
use Ptypes\Exceptions\InvalidArgument;
class BinaryTree
{
public const IN_ORDER = 0;
public const PRE_ORDER = 1;
public const POST_ORDER = 2;
public $root;
public function __construct()
$this->root = null;
}
public function insert($node) //$node is a treenode
$this->validate_parameter($node);
if($this->root == null)
$this->root = $node;
return $this;
$n = $this->root;
while(1)
if($node->value < $n->value)
if($n->left == null)
$n->left = $node;
$n = $n->left;
else if($node->value > $n->value)
if($n->right == null)
$n->right = $node;
$n = $n->right;
else if($node->value == $n->value) //node is already in the tree, we do not create duplicates!
public function search($value)
$value
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function search(/** @scrutinizer ignore-unused */ $value)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
public function traverse($order)
switch($order)
case self::IN_ORDER:
//TODO
break;
case self::PRE_ORDER:
case self::POST_ORDER:
default:
throw new InvalidArgument("Invalid order: " . $order . "! Valid orders: IN_ORDER (BinaryTree::IN_ORDER), PRE_ORDER (BinaryTree::PRE_ORDER), and POST_ORDER (BinaryTree::POST_ORDER).\n");
private function in_order_traversal($node, $results)
$node
private function in_order_traversal(/** @scrutinizer ignore-unused */ $node, $results)
in_order_traversal()
This check looks for private methods that have been defined, but are not used inside the class.
$results
private function in_order_traversal($node, /** @scrutinizer ignore-unused */ $results)
private function validate_parameter($node)
if(gettype($node) != "object")
throw new UnexpectedType("Expected a Ptypes\TreeNode, got: " . gettype($node));
if(get_class($node) != "Ptypes\TreeNode")
throw new UnexpectedType("Expected a Ptypes\TreeNode, got: " . get_class($node));
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.