TwigPage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 28
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A extractData() 0 14 2
1
<?php
2
/**
3
 * Yii2 Pages Module
4
 *
5
 * @link      https://github.com/hiqdev/yii2-module-pages
6
 * @package   yii2-module-pages
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\modules\pages\models;
12
13
use hiqdev\yii2\modules\pages\Module;
14
use Yii;
15
16
class TwigPage extends AbstractPage
17
{
18
    /**
19
     * @param array $params
20
     * @return string
21
     */
22
    public function render(array $params = []): string
23
    {
24
        $path = Module::getInstance()->getLocalPath($this->path);
0 ignored issues
show
Documentation Bug introduced by
The method getLocalPath does not exist on object<hiqdev\yii2\modules\pages\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
25
26
        return Yii::$app->getView()->renderFile($path, $params);
27
    }
28
29
    public function extractData($path)
30
    {
31
        $lines = static::getModule()->readArray($path);
32
        $matterLines = $this->readQuotedLines($lines, '/^{#/', '/#}$/');
33
        if (empty($matterLines)) {
34
            $data = [];
35
            $text = $lines;
36
        } else {
37
            $data = $this->readFrontMatter($matterLines);
38
            $text = array_slice($lines, count($matterLines));
39
        }
40
41
        return [$data, implode("\n", $text)];
42
    }
43
}
44