ReceivingFeature::describe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1.0019

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 8
cp 0.875
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1.0019
1
<?php
2
namespace PSB\Core\Transport;
3
4
5
use PSB\Core\Feature\Feature;
6
use PSB\Core\KnownSettingsEnum;
7
use PSB\Core\ObjectBuilder\BuilderInterface;
8
use PSB\Core\Pipeline\PipelineModifications;
9
use PSB\Core\Util\Settings;
10
11
class ReceivingFeature extends Feature
12
{
13
14
    /**
15
     * Method will always be executed and should be used to determine whether to enable or disable the feature,
16
     * configure default settings, configure dependencies, configure prerequisites and register startup tasks.
17
     */
18 1
    public function describe()
19
    {
20 1
        $this->enableByDefault();
21 1
        $this->dependsOn(TransportFeature::class);
22 1
        $this->registerPrerequisite(
23
            function (Settings $settings) {
24
                return !$settings->tryGet(KnownSettingsEnum::SEND_ONLY);
25 1
            },
26 1
            "Endpoint is configured as send only."
27
        );
28 1
    }
29
30
    /**
31
     * Method is called if all defined conditions are met and the feature is marked as enabled.
32
     * Use this method to configure and initialize all required components for the feature like
33
     * the steps in the pipeline or the instances/factories in the container.
34
     *
35
     * @param Settings              $settings
36
     * @param BuilderInterface      $builder
37
     * @param PipelineModifications $pipelineModifications
38
     */
39 1
    public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
40
    {
41
        /** @var QueueBindings $queueBindings */
42 1
        $queueBindings = $settings->get(QueueBindings::class);
43 1
        $queueBindings->bindReceiving($settings->get(KnownSettingsEnum::LOCAL_ADDRESS));
44
45
        /** @var InboundTransport $inboundTransport */
46 1
        $inboundTransport = $settings->get(InboundTransport::class);
47 1
        $receiveInfrastructure = $inboundTransport->configure($settings);
48
49 1
        $builder->defineSingleton(MessagePusherInterface::class, $receiveInfrastructure->getMessagePusherFactory());
50 1
        $builder->defineSingleton(QueueCreatorInterface::class, $receiveInfrastructure->getQueueCreatorFactory());
51
52 1
        $this->registerInstallTask(
53
            function () use ($builder, $settings) {
54
                return new QueueCreatorFeatureInstallTask($builder->build(QueueCreatorInterface::class), $settings);
55 1
            }
56
        );
57 1
    }
58
}
59