AdditionalPage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 0
loc 65
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getId() 0 4 1
A getLabel() 0 4 1
A render() 0 8 2
1
<?php
2
3
namespace hiqdev\yii2\modules\pages\components;
4
5
use hipanel\helpers\ArrayHelper;
6
use hiqdev\yii2\modules\pages\interfaces\PageInterface;
7
use Yii;
8
use yii\helpers\Inflector;
9
10
/**
11
 * Class AdditionalPage
12
 * @package hiqdev\yii2\modules\pages\components
13
 */
14
class AdditionalPage implements PageInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    private $label;
20
21
    /**
22
     * @var string
23
     */
24
    private $dictionary;
25
26
    /**
27
     * @var string
28
     */
29
    private $pathToPage;
30
31
    /**
32
     * @var array
33
     */
34
    private $params;
35
36
    /**
37
     * AdditionalPage constructor.
38
     * @param string $label
39
     * @param array $label
40
     * @param array $params
41
     */
42
    public function __construct(string $label, array $params = [])
43
    {
44
        $this->label = $label;
45
        $this->dictionary = ArrayHelper::remove($params, 'dictionary');
46
        $this->pathToPage = ArrayHelper::remove($params, 'path');
47
        $this->params = ArrayHelper::remove($params, 'params', []);
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getId(): string
54
    {
55
        return Inflector::slug($this->label);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getLabel(): string
62
    {
63
        return Yii::t($this->dictionary, $this->label);
64
    }
65
66
    /**
67
     * @param array $params
68
     * @return string
69
     */
70
    public function render(array $params = []): string
71
    {
72
        if (is_file($this->pathToPage)) {
73
            return Yii::$app->view->renderFile($this->pathToPage, array_merge($this->params, $params));
74
        }
75
76
        return '';
77
    }
78
}
79