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.

CheckSubjectManipulatorConfigPass::process()   C
last analyzed

Complexity

Conditions 11
Paths 8

Size

Total Lines 58
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 6.4179
c 0
b 0
f 0
cc 11
eloc 34
nc 8
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * @date   08.08.16
10
 */
11
12
namespace Gtt\Bundle\WorkflowExtensionsBundle\DependencyInjection\Compiler;
13
14
use Gtt\Bundle\WorkflowExtensionsBundle\Exception\RuntimeException;
15
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
/**
21
 * Checks that all necessary options for scheduler are set for classes supported by corresponding workflows
22
 */
23
class CheckSubjectManipulatorConfigPass implements CompilerPassInterface
24
{
25
    /**
26
     * Workflow registry definition id
27
     */
28
    const WORKFLOW_REGISTRY_ID= 'workflow.registry';
29
30
    /**
31
     * Workflow id prefix used in main workflow bundle
32
     */
33
    const WORKFLOW_ID_PREFIX = 'workflow.';
34
35
    /**
36
     * Name of the method used to register workflows in registry
37
     */
38
    const WORKFLOW_REGISTRY_ADD_WORKFLOW_METHOD_NAME = "add";
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function process(ContainerBuilder $container)
44
    {
45
        if (false === $container->hasDefinition(static::WORKFLOW_REGISTRY_ID)) {
46
            return;
47
        }
48
49
        if (false === $container->hasDefinition('gtt.workflow.transition_scheduler')) {
50
            return;
51
        }
52
53
        $subjectClassesWithSubjectFromDomain = $container->getParameter('gtt.workflow.subject_classes_with_subject_from_domain');
54
        $workflowsWithScheduling             = $container->getParameter('gtt.workflow.workflows_with_scheduling');
55
56
        $registryDefinition = $container->getDefinition(self::WORKFLOW_REGISTRY_ID);
57
        foreach ($registryDefinition->getMethodCalls() as $call) {
58
            if ($call[0] == self::WORKFLOW_REGISTRY_ADD_WORKFLOW_METHOD_NAME) {
59
                $callArgs = $call[1];
60
61
                if (count($callArgs) != 2 || !$callArgs[0] instanceof Reference || !is_string($callArgs[1])) {
62
                    throw new RuntimeException(
63
                        sprintf(
64
                            'Workflow registry service have unsupported signature for "%s" method',
65
                            self::WORKFLOW_REGISTRY_ADD_WORKFLOW_METHOD_NAME
66
                        )
67
                    );
68
                }
69
70
                /** @var Reference $workflowReference */
71
                $workflowReference      = $callArgs[0];
72
                $workflowSupportedClass = $callArgs[1];
73
74
                $workflowIdWithPrefix =  (string) $workflowReference;
75
                if (substr($workflowIdWithPrefix, 0, strlen(self::WORKFLOW_ID_PREFIX)) != self::WORKFLOW_ID_PREFIX) {
76
                    throw new RuntimeException(
77
                        sprintf(
78
                            "Workflow registry works with workflow id '%s'in unsupported format",
79
                            $workflowIdWithPrefix
80
                        )
81
                    );
82
                }
83
84
                $workflowId = substr($workflowIdWithPrefix, strlen(self::WORKFLOW_ID_PREFIX));
85
86
                if (in_array($workflowId, $workflowsWithScheduling) &&
87
                    !in_array(ltrim($workflowSupportedClass, "\\"), $subjectClassesWithSubjectFromDomain)) {
88
                    throw new InvalidConfigurationException(
89
                        sprintf(
90
                            'Workflow "%s" configured to use scheduler so all the supported subject classes for it'.
91
                            'must be configured with "subject_from_domain" option under "subject_manipulator". '.
92
                            'This option for "%s" class is missing.',
93
                            $workflowId,
94
                            $workflowSupportedClass
95
                        )
96
                    );
97
                }
98
            }
99
        }
100
    }
101
}