AbstractNetwork   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 24.14 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 14
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A invokeMethod() 7 7 1
A invokeProperty() 7 7 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 Padosoft\AffiliateNetwork;
4
5
/**
6
 * Class AbstractNetwork
7
 * @package Padosoft\AffiliateNetwork
8
 */
9
abstract class AbstractNetwork
10
{
11
    /**
12
     * username
13
     * @var string
14
     */
15
    protected $username = '';
16
17
    /**
18
     * password
19
     * @var string
20
     */
21
    protected $password = '';
22
23
    /**
24
     * AbstractNetwork constructor.
25
     * @param string $username
26
     * @param string $password
27
     */
28
    public function __construct(string $username, string $password)
29
    {
30
        $this->username = $username;
31
        $this->password = $password;
32
    }
33
34
    /**
35
     * Call protected/private method of a class.
36
     *
37
     * @param object &$object    Instantiated object that we will run method on.
38
     * @param string $methodName Method name to call
39
     * @param array  $parameters Array of parameters to pass into method.
40
     *
41
     * @return mixed Method return.
42
     */
43 View Code Duplication
    public function invokeMethod(&$object,$methodName, array $parameters = array())
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...
44
    {
45
        $reflection = new \ReflectionClass(get_class($object));
46
        $method = $reflection->getMethod($methodName);
47
        $method->setAccessible(true);
48
        return $method->invokeArgs($object, $parameters);
49
    }
50
51
    /**
52
     * Call protected/private property of a class.
53
     * @param $object
54
     * @param $propertyName
55
     *
56
     * @return mixed
57
     */
58 View Code Duplication
    public function invokeProperty(&$object,$propertyName)
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...
59
    {
60
        $reflection = new \ReflectionClass(get_class($object));
61
        $property = $reflection->getProperty($propertyName);
62
        $property->setAccessible(true);
63
        return $property->getValue($object);
64
    }
65
66
}
67