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.
Completed
Push — master ( c0206e...9204a9 )
by Alex
05:38 queued 04:00
created

RoutingFeature::setup()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 37
CRAP Score 2.0587

Importance

Changes 0
Metric Value
dl 0
loc 77
ccs 37
cts 49
cp 0.7551
rs 8.5018
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2.0587

How to fix   Long Method   

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
namespace PSB\Core\Routing;
3
4
5
use PSB\Core\Feature\Feature;
6
use PSB\Core\KnownSettingsEnum;
7
use PSB\Core\ObjectBuilder\BuilderInterface;
8
use PSB\Core\Pipeline\Outgoing\OutgoingContextFactory;
9
use PSB\Core\Pipeline\PipelineModifications;
10
use PSB\Core\Routing\Pipeline\AttachReplyToAddressPipelineStep;
11
use PSB\Core\Routing\Pipeline\MulticastPublishRoutingConnector;
12
use PSB\Core\Routing\Pipeline\SubscribeTerminator;
13
use PSB\Core\Routing\Pipeline\UnicastReplyRoutingConnector;
14
use PSB\Core\Routing\Pipeline\UnicastSendRoutingConnector;
15
use PSB\Core\Routing\Pipeline\UnsubscribeTerminator;
16
use PSB\Core\Transport\Config\TransportInfrastructure;
17
use PSB\Core\Transport\SubscriptionManagerInterface;
18
use PSB\Core\Util\Settings;
19
20
class RoutingFeature extends Feature
21
{
22
23
    /**
24
     * Method will always be executed and should be used to determine whether to enable or disable the feature,
25
     * configure default settings, configure dependencies, configure prerequisites and register startup tasks.
26
     */
27 1
    public function describe()
28
    {
29 1
        $this->enableByDefault();
30 1
    }
31
32
    /**
33
     * Method is called if all defined conditions are met and the feature is marked as enabled.
34
     * Use this method to configure and initialize all required components for the feature like
35
     * the steps in the pipeline or the instances/factories in the container.
36
     *
37
     * @param Settings              $settings
38
     * @param BuilderInterface      $builder
39
     * @param PipelineModifications $pipelineModifications
40
     */
41 2
    public function setup(
42
        Settings $settings,
43
        BuilderInterface $builder,
44
        PipelineModifications $pipelineModifications
45
    ) {
46 2
        $localAddress = $settings->get(KnownSettingsEnum::LOCAL_ADDRESS);
47
48 2
        $builder->defineSingleton(
49 2
            UnicastRouterInterface::class,
50
            function () use ($localAddress, $builder, $settings) {
51
                return new UnicastRouter(
52
                    $localAddress,
53
                    $builder->build(UnicastRoutingTable::class),
54
                    $settings->get(TransportInfrastructure::class)
55
                );
56 2
            }
57
        );
58
59 2
        $pipelineModifications->registerStep(
60 2
            'UnicastSendRoutingConnector',
61 2
            UnicastSendRoutingConnector::class,
62
            function () use ($builder) {
63
                return new UnicastSendRoutingConnector(
64
                    $builder->build(UnicastRouterInterface::class),
65
                    $builder->build(OutgoingContextFactory::class)
66
                );
67 2
            }
68
        );
69 2
        $pipelineModifications->registerStep(
70 2
            'UnicastReplyRoutingConnector',
71 2
            UnicastReplyRoutingConnector::class,
72
            function () use ($builder) {
73
                return new UnicastReplyRoutingConnector($builder->build(OutgoingContextFactory::class));
74 2
            }
75
        );
76 2
        $pipelineModifications->registerStep(
77 2
            'MulticastPublishRoutingConnector',
78 2
            MulticastPublishRoutingConnector::class,
79
            function () use ($builder) {
80
                return new MulticastPublishRoutingConnector($builder->build(OutgoingContextFactory::class));
81 2
            }
82
        );
83
84 2
        $canReceive = !$settings->get(KnownSettingsEnum::SEND_ONLY);
85 2
        if ($canReceive) {
86 1
            $pipelineModifications->registerStep(
87 1
                'AttachReplyToAddressPipelineStep',
88 1
                AttachReplyToAddressPipelineStep::class,
89
                function () use ($localAddress) {
90
                    return new AttachReplyToAddressPipelineStep($localAddress);
91 1
                }
92
            );
93
94
            /** @var TransportInfrastructure $transportInfrastructure */
95 1
            $transportInfrastructure = $settings->get(TransportInfrastructure::class);
96 1
            $subscriptionManagerFactory = $transportInfrastructure->configureSubscriptionInfrastructure();
97 1
            $builder->defineSingleton(
98 1
                SubscriptionManagerInterface::class,
99 1
                $subscriptionManagerFactory->getSubscriptionManagerFactory()
100
            );
101
102 1
            $pipelineModifications->registerStep(
103 1
                'SubscribeTerminator',
104 1
                SubscribeTerminator::class,
105
                function () use ($builder) {
106
                    return new SubscribeTerminator($builder->build(SubscriptionManagerInterface::class));
107 1
                }
108
            );
109 1
            $pipelineModifications->registerStep(
110 1
                'UnsubscribeTerminator',
111 1
                UnsubscribeTerminator::class,
112
                function () use ($builder) {
113
                    return new UnsubscribeTerminator($builder->build(SubscriptionManagerInterface::class));
114 1
                }
115
            );
116
        }
117 2
    }
118
}
119