Completed
Push — master ( e41e91...2b4213 )
by Aleh
01:47 queued 01:39
created

FQCN   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 72
Duplicated Lines 13.89 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 24
c 1
b 0
f 0
lcom 2
cbo 1
dl 10
loc 72
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 8 3
C __construct() 0 23 13
A join() 10 10 2
A getClassName() 0 3 1
A getNamespace() 0 5 1
A toString() 0 7 2
A isArray() 0 3 1
A isScalar() 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 FQCN extends FQN {
6
7
    public function __get($key) {
8
        if ($key === "className") {
9
            return $this->getClassName();
10
        }
11
        elseif ($key === "namespace") {
12
            return $this->getNamespace();
13
        }
14
    }
15
    public function __construct($className, $namespace = "", $isArray = false) {
16
        parent::__construct($namespace);
17
        $this->_isArray = $isArray;
18
        $this->_isScalar = false;
19
        if (count($this->parts) === 0) {
0 ignored issues
show
Documentation introduced by
The property $parts is declared private in Padawan\Domain\Project\FQN. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
20
            switch ($className) {
21
            case "int":
22
            case "string":
23
            case "float":
24
            case "array":
25
            case "mixed":
26
            case "void":
27
            case "object":
28
            case "bool":
29
            case "null":
30
            case "false":
31
            case "true":
32
                $this->_isScalar = true;
33
                break;
34
            }
35
        }
36
        $this->addPart($className);
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 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...
43
        $result = new self($join->getLast());
44
        $resultParts = $this->getParts();
45
        $joiningParts = $join->getParts();
46
        if ($this->getLast() === $join->getFirst()) {
47
            array_shift($joiningParts);
48
        }
49
        $result->setParts(array_merge($resultParts, $joiningParts));
50
        return $result;
51
    }
52
    public function getClassName() {
53
        return $this->getLast();
54
    }
55
    public function getNamespace() {
56
        $parts = $this->getParts();
57
        array_pop($parts);
58
        return implode("\\", $parts);
59
    }
60
    public function toString() {
61
        $str = parent::toString();
62
        if ($this->isArray()) {
63
            $str .= '[]';
64
        }
65
        return $str;
66
    }
67
    public function isArray() {
68
        return $this->_isArray;
69
    }
70
    public function isScalar() {
71
        return $this->_isScalar;
72
    }
73
74
    private $_isArray;
75
    private $_isScalar;
76
}
77