Completed
Push — master ( e2b1b5...0394bc )
by Ryan
02:27
created

UsersModulePlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 18
loc 56
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getFunctions() 5 28 1
A getFilters() 13 13 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 namespace Anomaly\UsersModule;
2
3
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
4
use Anomaly\Streams\Platform\Support\Decorator;
5
use Anomaly\UsersModule\Role\Command\GetRole;
6
use Anomaly\UsersModule\User\Command\GetUser;
7
use Anomaly\UsersModule\User\UserMentions;
8
9
/**
10
 * Class UsersModulePlugin
11
 *
12
 * @link          http://pyrocms.com/
13
 * @author        PyroCMS, Inc. <[email protected]>
14
 * @author        Ryan Thompson <[email protected]>
15
 */
16
class UsersModulePlugin extends Plugin
17
{
18
19
    /**
20
     * Get the functions.
21
     *
22
     * @return array
23
     */
24
    public function getFunctions()
25
    {
26
        return [
27
            new \Twig_SimpleFunction(
28
                'user',
29
                function ($identifier = null) {
30
                    return (new Decorator())->decorate($this->dispatch(new GetUser($identifier)));
31
                }
32
            ),
33
            new \Twig_SimpleFunction(
34
                'role',
35
                function ($identifier) {
36
                    return (new Decorator())->decorate($this->dispatch(new GetRole($identifier)));
37
                }
38
            ),
39
            new \Twig_SimpleFunction(
40
                'mentions_*',
41 View Code Duplication
                function ($name) {
0 ignored issues
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...
42
                    $arguments = array_slice(func_get_args(), 1);
43
44
                    return call_user_func_array([app(UserMentions::class), camel_case($name)], $arguments);
45
                },
46
                [
47
                    'is_safe' => ['html'],
48
                ]
49
            ),
50
        ];
51
    }
52
53
    /**
54
     * Get the filters.
55
     *
56
     * @return array
57
     */
58 View Code Duplication
    public function getFilters()
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...
59
    {
60
        return [
61
            new \Twig_SimpleFilter(
62
                'mentions_*',
63
                function ($name) {
64
                    $arguments = array_slice(func_get_args(), 1);
65
66
                    return call_user_func_array([app(UserMentions::class), camel_case($name)], $arguments);
67
                }
68
            ),
69
        ];
70
    }
71
}
72