BinarySearchTree   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 50 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 11
loc 22
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A createNode() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * DataStructures for PHP
4
 *
5
 * @link      https://github.com/SiroDiaz/DataStructures
6
 * @copyright Copyright (c) 2017 Siro Díaz Palazón
7
 * @license   https://github.com/SiroDiaz/DataStructures/blob/master/README.md (MIT License)
8
 */
9
namespace DataStructures\Trees;
10
11
use DataStructures\Trees\Nodes\BSTNode;
12
use DataStructures\Trees\BinaryTreeAbstract;
13
14
/**
15
 * BinarySearchTree
16
 * 
17
 * Represents a BST actions that can be realized. All the implementation
18
 * is in BinaryTreeAbstract class.
19
 * At the beginning root is null and it can grow up to a O(n) in search,
20
 * delete and insert (in worst case). In best cases it will be O(log n).
21
 *
22
 * @author Siro Diaz Palazon <[email protected]>
23
 */
24 View Code Duplication
class BinarySearchTree extends BinaryTreeAbstract {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
26
    public function __construct() {
27
        $this->root = null;
28
        $this->size = 0;
29
    }
30
31
    /**
32
     * Creates a BSTNode.
33
     *
34
     * @param int|string $key the key used to store.
35
     * @param mixed $data the data.
36
     * @param DataStructures\Trees\Nodes\BSTNode|null $parent the parent node.
37
     * @param DataStructures\Trees\Nodes\BSTNode|null $left the left child node.
38
     * @param DataStructures\Trees\Nodes\BSTNode|null $right the right child node.
39
     *
40
     * @return DataStructures\Trees\Nodes\BSTNode the new node created.
41
     */
42
    public function createNode($key, $data, $parent = null, $left = null, $right = null) {
43
        return new BSTNode($key, $data, $parent, $left, $right);
44
    }
45
}