Completed
Push — master ( c53dc7...f7fdc3 )
by
unknown
05:51
created

AbstractNetwork   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A invokeMethod() 0 7 1
A invokeProperty() 0 7 1
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
    public function invokeMethod(&$object,$methodName, array $parameters = array())
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
    public function invokeProperty(&$object,$propertyName)
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