AutoSubscribeFeature   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 30
ccs 6
cts 13
cp 0.4615
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A describe() 0 10 1
A setup() 0 10 1
1
<?php
2
namespace PSB\Core\Routing\AutoSubscription;
3
4
5
use PSB\Core\Feature\Feature;
6
use PSB\Core\KnownSettingsEnum;
7
use PSB\Core\MessageHandlerRegistry;
8
use PSB\Core\ObjectBuilder\BuilderInterface;
9
use PSB\Core\Pipeline\PipelineModifications;
10
use PSB\Core\Util\Settings;
11
12
class AutoSubscribeFeature extends Feature
13
{
14
15 1
    public function describe()
16
    {
17 1
        $this->enableByDefault();
18 1
        $this->registerPrerequisite(
19
            function (Settings $settings) {
20
                return !$settings->tryGet(KnownSettingsEnum::SEND_ONLY);
21 1
            },
22 1
            "Send only endpoints can't autosubscribe."
23
        );
24 1
    }
25
26
    /**
27
     * @param Settings              $settings
28
     * @param BuilderInterface      $builder
29
     * @param PipelineModifications $pipelineModifications
30
     */
31
    public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
32
    {
33
        $this->registerStartupTask(
34
            function (BuilderInterface $builder) {
35
                /** @var MessageHandlerRegistry $handlerRegistry */
36
                $handlerRegistry = $builder->build(MessageHandlerRegistry::class);
37
                return new SubscriptionApplierStartupTask($handlerRegistry->getEventFqcns());
38
            }
39
        );
40
    }
41
}
42