GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — filters ( 4ff9c7...c25ab7 )
by Alexander
10:29 queued 01:15
created

ContentBlock   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 14
loc 63
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B decorate() 14 37 4
A processChunks() 0 8 1

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
namespace app\modules\core\decorators;
4
5
use app;
6
7
use Yii;
8
use app\modules\core\helpers\ContentBlockHelper;
9
use yii\caching\TagDependency;
10
use devgroup\TagDependencyHelper\ActiveRecordHelper;
11
12
class ContentBlock extends PreDecorator
13
{
14
15
    /**
16
     * Handle decoration
17
     * @param \yii\base\Controller $controller
18
     * @param string $viewFile
19
     * @param array $params
20
     * @return void
21
     */
22
    public function decorate($controller, $viewFile, $params)
23
    {
24
        if (!Yii::$app->getModule("backend")->isBackend())
25
        {
26
            $baseContentKey = get_class($params['model']) . ":{$params['model']->id}:";
27
            $view = $controller->view;
28
            $dependency = new TagDependency([
29
                'tags' => [
30
                    ActiveRecordHelper::getCommonTag(app\modules\core\models\ContentBlock::className()),
31
                    ActiveRecordHelper::getCommonTag(get_class($params['model']))
32
                ]
33
            ]);
34
35
36
            $view->title = $this->processChunks(
37
                $view->title,
38
                $baseContentKey . "title",
39
                $dependency
40
            );
41
42 View Code Duplication
            if (!empty($view->blocks["content"])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
43
                $view->blocks["content"] = $this->processChunks(
44
                    $view->blocks["content"],
45
                    $baseContentKey . "content",
46
                    $dependency
47
                );
48
            }
49
50 View Code Duplication
            if (!empty($view->blocks["announce"])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
51
                $view->blocks["announce"] = $this->processChunks(
52
                    $view->blocks["announce"],
53
                    $baseContentKey . "announce",
54
                    $dependency
55
                );
56
            }
57
        }
58
    }
59
60
    /**
61
     * @param $content
62
     * @param $contentKey
63
     * @param $dependency
64
     * @return string
65
     */
66
    private function processChunks($content, $contentKey, $dependency)
67
    {
68
        return ContentBlockHelper::compileContentString(
69
            $content,
70
            $contentKey,
71
            $dependency
72
        );
73
    }
74
}