Passed
Pull Request — master (#16)
by
unknown
02:10
created

ActionTemplateTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 78.26 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 18
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createActions() 18 18 4

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
/*
4
 * This file is part of the LineMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LineMob\Core\Template;
13
14
use LINE\LINEBot\TemplateActionBuilder\MessageTemplateActionBuilder;
15
use LINE\LINEBot\TemplateActionBuilder\PostbackTemplateActionBuilder;
16
use LINE\LINEBot\TemplateActionBuilder\UriTemplateActionBuilder;
17
18
/**
19
 * @author Ishmael Doss <[email protected]>
20
 *
21
 * @property array actions
22
 * @property string altText
23
 * @property string title
24
 */
25
trait ActionTemplateTrait
26
{
27
    /**
28
     * @return Action[]
29
     */
30 View Code Duplication
    private function createActions()
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...
31
    {
32
        $actions = [];
33
34
        foreach ($this->actions as $action) {
35
            switch (strtolower($action->type)) {
36
                case Action::TYPE_POSTBACK:
37
                    $actions[] = new PostbackTemplateActionBuilder($action->label, $action->value);
38
                    break;
39
                case Action::TYPE_URI:
40
                    $actions[] = new UriTemplateActionBuilder($action->label, $action->value);
41
                    break;
42
                default:
43
                    $actions[] = new MessageTemplateActionBuilder($action->label, $action->value);
44
            }
45
        }
46
47
        return $actions;
48
    }
49
}
50