Passed
Push — master ( de3d61...be839c )
by Alec
13:42 queued 13s
created

WidgetSettingsFactory::createFromConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Factory;
6
7
use AlecRabbit\Spinner\Core\Builder\Settings\Contract\IWidgetSettingsBuilder;
8
use AlecRabbit\Spinner\Core\Config\Contract\IWidgetConfig;
9
use AlecRabbit\Spinner\Core\Contract\ISettingsProvider;
10
use AlecRabbit\Spinner\Core\Factory\Contract\IWidgetSettingsFactory;
11
use AlecRabbit\Spinner\Core\Settings\Contract\IWidgetSettings;
12
13
final class WidgetSettingsFactory implements IWidgetSettingsFactory
14
{
15
    public function __construct(
16
        protected ISettingsProvider $settingsProvider,
17
        protected IWidgetSettingsBuilder $widgetSettingsBuilder,
18
    ) {
19
    }
20
21
    public function createFromConfig(IWidgetConfig $config): IWidgetSettings
22
    {
23
        $config = $config->merge($this->settingsProvider->getWidgetConfig());
24
25
        return
26
            $this->widgetSettingsBuilder
27
                ->withLeadingSpacer($config->getLeadingSpacer())
0 ignored issues
show
Bug introduced by
It seems like $config->getLeadingSpacer() can also be of type null; however, parameter $frame of AlecRabbit\Spinner\Core\...er::withLeadingSpacer() does only seem to accept AlecRabbit\Spinner\Contract\IFrame, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
                ->withLeadingSpacer(/** @scrutinizer ignore-type */ $config->getLeadingSpacer())
Loading history...
28
                ->withTrailingSpacer($config->getTrailingSpacer())
0 ignored issues
show
Bug introduced by
It seems like $config->getTrailingSpacer() can also be of type null; however, parameter $frame of AlecRabbit\Spinner\Core\...r::withTrailingSpacer() does only seem to accept AlecRabbit\Spinner\Contract\IFrame, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
                ->withTrailingSpacer(/** @scrutinizer ignore-type */ $config->getTrailingSpacer())
Loading history...
29
                ->withStylePattern($config->getStylePattern())
0 ignored issues
show
Bug introduced by
It seems like $config->getStylePattern() can also be of type null; however, parameter $pattern of AlecRabbit\Spinner\Core\...der::withStylePattern() does only seem to accept AlecRabbit\Spinner\Core\...\Contract\IStylePattern, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
                ->withStylePattern(/** @scrutinizer ignore-type */ $config->getStylePattern())
Loading history...
30
                ->withCharPattern($config->getCharPattern())
0 ignored issues
show
Bug introduced by
It seems like $config->getCharPattern() can also be of type null; however, parameter $pattern of AlecRabbit\Spinner\Core\...lder::withCharPattern() does only seem to accept AlecRabbit\Spinner\Contract\Pattern\IPattern, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
                ->withCharPattern(/** @scrutinizer ignore-type */ $config->getCharPattern())
Loading history...
31
                ->build()
32
        ;
33
    }
34
35
}
36