FlyAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 8.11 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 5
Bugs 4 Features 0
Metric Value
wmc 4
c 5
b 4
f 0
lcom 0
cbo 0
dl 3
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setSubject() 0 6 1
A __call() 3 6 2

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 PEIP\Base;
4
5
/*
6
 * This file is part of the PEIP package.
7
 * (c) 2009-2016 Timo Michna <timomichna/yahoo.de>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
/*
14
 * FlyAdapter
15
 *
16
 * @author Timo Michna <timomichna/yahoo.de>
17
 * @package PEIP
18
 * @subpackage base
19
 */
20
21
22
use PEIP\Data\ArrayAccess;
23
24
class FlyAdapter
25
{
26
    /**
27
     * @param $methodMap
28
     *
29
     * @return
30
     */
31
    public function __construct(ArrayAccess $methodMap)
32
    {
33
        $this->methodMap = $methodMap;
0 ignored issues
show
Bug introduced by
The property methodMap does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
    }
35
36
    /**
37
     * @param $subject
38
     *
39
     * @return
40
     */
41
    public function setSubject($subject)
42
    {
43
        $this->subject = $subject;
0 ignored issues
show
Bug introduced by
The property subject does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param $method
50
     * @param $arguments
51
     *
52
     * @return
53
     */
54
    public function __call($method, $arguments)
55
    {
56 View Code Duplication
        if (array_key_exists($method, $this->methodMap)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
57
            return call_user_func_array([$this->subject, $this->methodMap[$method]], $arguments);
58
        }
59
    }
60
}
61