FQN   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 69
Duplicated Lines 14.49 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 0
dl 10
loc 69
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 4
A join() 10 10 2
A getFirst() 0 4 1
A getLast() 0 4 1
A getTail() 0 5 1
A getParts() 0 6 2
A setParts() 0 3 1
A addPart() 0 3 1
A toString() 0 3 1
A __toString() 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
namespace Padawan\Domain\Project;
4
5
class FQN {
6
7
    public function __construct($namespace = "") {
8
        if ($namespace) {
9
            if ($namespace instanceof FQN) {
10
                $this->parts = $namespace->getParts();
11
            }
12
            elseif (!is_array($namespace)) {
13
                $this->parts = explode("\\", $namespace);
14
            }
15
            else {
16
                $this->parts = $namespace;
17
            }
18
        }
19
        else {
20
            $this->parts = [];
21
        }
22
    }
23
24
    /**
25
     * Joins FQN to the clone of the current FQN and returns it
26
     *
27
     * @return FQN
28
     */
29 View Code Duplication
    public function join(FQN $join) {
0 ignored issues
show
Duplication introduced by
This method 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...
30
        $result = new self();
31
        $resultParts = $this->getParts();
32
        $joiningParts = $join->getParts();
33
        if ($this->getLast() === $join->getFirst()) {
34
            array_shift($joiningParts);
35
        }
36
        $result->setParts(array_merge($resultParts, $joiningParts));
37
        return $result;
38
    }
39
    public function getFirst() {
40
        $parts = $this->getParts();
41
        return array_shift($parts);
42
    }
43
    public function getLast() {
44
        $parts = $this->getParts();
45
        return array_pop($parts);
46
    }
47
    public function getTail() {
48
        $parts = $this->getParts();
49
        array_pop($parts);
50
        return $parts;
51
    }
52
    public function getParts() {
53
        if (is_array($this->parts)) {
54
            return $this->parts;
55
        }
56
        return [];
57
    }
58
    public function setParts(array $parts) {
59
        $this->parts = $parts;
60
    }
61
    public function addPart($part) {
62
        $this->parts[] = $part;
63
    }
64
    public function toString() {
65
        return implode("\\", $this->getParts());
66
    }
67
    public function __toString() {
68
        return $this->toString();
69
    }
70
71
    public static $test;
72
    private $parts;
73
}
74