Completed
Push — master ( 4905bd...af6d05 )
by Andrii
03:36
created

TwigPage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 56 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 3
dl 14
loc 25
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() 14 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
use yii\base\InvalidConfigException;
16
17
class TwigPage extends AbstractPage
18
{
19
    public function render(array $params = [])
20
    {
21
        $path = Module::getInstance()->getLocalPath($this->path);
22
23
        return Yii::$app->getView()->renderFile($path);
24
    }
25
26 View Code Duplication
    public function extractData($path)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $lines = static::getModule()->readArray($path);
29
        $matterLines = $this->getQuoted($lines, '/^{#/', '/#}$/');
30
        if (empty($matterLines)) {
31
            $data = [];
32
            $text = $lines;
33
        } else {
34
            $data = $this->readFrontMatter($matterLines);
35
            $text = array_slice($lines, count($matterLines));
36
        }
37
38
        return [$data, implode("\n", $text)];
39
    }
40
41
}
42