Completed
Push — master ( f1f202...f49b06 )
by Iman
01:39
created

Normalizer::normalizeContextAs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\Widgets\Utils;
4
5
use Imanghafoori\Widgets\Utils\Normalizers\CacheNormalizer;
6
use Imanghafoori\Widgets\Utils\Normalizers\ContextAsNormalizer;
7
use Imanghafoori\Widgets\Utils\Normalizers\TemplateNormalizer;
8
use Imanghafoori\Widgets\Utils\Normalizers\PresenterNormalizer;
9
use Imanghafoori\Widgets\Utils\Normalizers\ControllerNormalizer;
10
11
class Normalizer
12
{
13
    private $presenterNormalizer;
14
15
    private $templateNormalizer;
16
17
    private $cacheNormalizer;
18
19
    private $controllerNormalizer;
20
21
    /**
22
     * Normalizer constructor which accepts dependencies.
23
     *
24
     * @param TemplateNormalizer $templateNormalizer
25
     * @param CacheNormalizer $cacheNormalizer
26
     * @param PresenterNormalizer $presenterNormalizer
27
     * @param ControllerNormalizer $controllerNormalizer
28
     * @param ContextAsNormalizer $contextAsNormalizer
29
     */
30
    public function __construct(
31
        TemplateNormalizer $templateNormalizer,
32
        CacheNormalizer $cacheNormalizer,
33
        PresenterNormalizer $presenterNormalizer,
34
        ControllerNormalizer $controllerNormalizer,
35
        ContextAsNormalizer $contextAsNormalizer
36
    ) {
37
        $this->presenterNormalizer = $presenterNormalizer;
38
        $this->controllerNormalizer = $controllerNormalizer;
39
        $this->templateNormalizer = $templateNormalizer;
40
        $this->cacheNormalizer = $cacheNormalizer;
41
        $this->contextAsNormalizer = $contextAsNormalizer;
0 ignored issues
show
Bug introduced by
The property contextAsNormalizer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
    }
43
44
    /**
45
     * Figures out and sets the widget configs according to conventions.
46
     *
47
     * @param object $widget
48
     */
49
    public function normalizeWidgetConfig($widget)
50
    {
51
        // to avoid normalizing a widget multiple times unnecessarily :
52
        if (isset($widget->isNormalized)) {
53
            return;
54
        }
55
56
        $this->controllerNormalizer->normalizeControllerMethod($widget);
57
        $this->presenterNormalizer->normalizePresenterName($widget);
58
        $this->templateNormalizer->normalizeTemplateName($widget);
59
        $this->cacheNormalizer->normalizeCacheLifeTime($widget);
60
        $this->cacheNormalizer->normalizeCacheTags($widget);
61
        $this->contextAsNormalizer->normalizeContextAs($widget);
62
        $widget->isNormalized = true;
63
    }
64
65
    /**
66
     * Figures out and sets json widget configs according to conventions.
67
     *
68
     * @param object $widget
69
     */
70
    public function normalizeJsonWidget($widget)
71
    {
72
        $this->controllerNormalizer->normalizeControllerMethod($widget);
73
        $this->cacheNormalizer->normalizeCacheLifeTime($widget);
74
        $this->cacheNormalizer->normalizeCacheTags($widget);
75
    }
76
}
77