GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ServiceMethod   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 121
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A setContainer() 0 4 1
A invoke() 0 4 1
A getReflectionMethod() 0 8 2
A getObject() 0 12 3
1
<?php
2
/**
3
 * This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * (c) fduch <[email protected]>
9
 *
10
 * Date: 14.09.16
11
 */
12
13
namespace Gtt\Bundle\WorkflowExtensionsBundle\Action\Reference;
14
15
use Gtt\Bundle\WorkflowExtensionsBundle\Exception\ActionException;
16
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
use ReflectionMethod;
19
20
/**
21
 * Reference to service method
22
 *
23
 * @author fduch <[email protected]>
24
 */
25
class ServiceMethod implements ActionReferenceInterface, ContainerAwareInterface
26
{
27
    /**
28
     * Service id of the object which method is used as an action
29
     *
30
     * @var string
31
     */
32
    private $serviceId;
33
34
    /**
35
     * Method name used as action
36
     *
37
     * @var string
38
     */
39
    private $methodName;
40
41
    /**
42
     * Action type
43
     *
44
     * @var string
45
     */
46
    private $type;
47
48
    /**
49
     * Action method reflection
50
     *
51
     * @var ReflectionMethod
52
     */
53
    private $reflectionMethod;
54
55
    /**
56
     * Target object object which method is used as an action
57
     * Used internally to invoke action
58
     *
59
     * @var object
60
     */
61
    private $object;
62
63
    /**
64
     * DI Container instance
65
     *
66
     * @var ContainerInterface
67
     */
68
    private $container;
69
70
    /**
71
     * ActionReference constructor.
72
     *
73
     * @param string $methodName method name
74
     * @param int    $serviceId  service id which method is used as an action
75
     * @param string $type       action reference type
76
     */
77
    public function __construct($methodName, $serviceId, $type = self::TYPE_REGULAR)
78
    {
79
        $this->methodName = $methodName;
80
        $this->serviceId  = $serviceId;
0 ignored issues
show
Documentation Bug introduced by
The property $serviceId was declared of type string, but $serviceId is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
81
        $this->type       = $type;
82
    }
83
84
    /**
85
     * Returns action type
86
     *
87
     * @return string
88
     */
89
    public function getType()
90
    {
91
        return $this->type;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function setContainer(ContainerInterface $container = null)
98
    {
99
        $this->container = $container;
100
    }
101
102
    /**
103
     * Invokes action
104
     *
105
     * @param array $args action args
106
     *
107
     * @return mixed
108
     */
109
    public function invoke(array $args)
110
    {
111
        return $this->getReflectionMethod()->invokeArgs($this->getObject(), $args);
112
    }
113
114
    /**
115
     * Returns reflection method
116
     *
117
     * @return ReflectionMethod
118
     */
119
    private function getReflectionMethod()
120
    {
121
        if (!$this->reflectionMethod) {
122
            $this->reflectionMethod = new ReflectionMethod($this->getObject(), $this->methodName);
123
        }
124
125
        return $this->reflectionMethod;
126
    }
127
128
    /**
129
     * Returns service object
130
     *
131
     * @return object
132
     */
133
    private function getObject()
134
    {
135
        if (!$this->object) {
136
            if (!$this->container) {
137
                throw ActionException::containerUnavailableForServiceMethodReference($this->serviceId);
138
            }
139
140
            $this->object = $this->container->get($this->serviceId);
141
        }
142
143
        return $this->object;
144
    }
145
}