Passed
Push — master ( fbc72e...1145e4 )
by Alexey
03:47
created

PointUserExtension   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 80
Duplicated Lines 27.5 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 22
loc 80
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 11 11 1
A getFilters() 11 11 1
A pointAvatarSmallFunction() 0 4 1
A pointAvatarMediumFunction() 0 4 1
A pointAvatarLargeFunction() 0 4 1
A pointAvatarFunction() 0 4 1
A pointUserUrl() 0 4 2
A pointUserBlogUrl() 0 4 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
namespace Skobkin\Bundle\PointToolsBundle\Twig;
4
5
use Skobkin\Bundle\PointToolsBundle\Service\UserApi;
6
7
class PointUserExtension extends \Twig_Extension
8
{
9
    const POINT_HOST = 'point.im';
10
11
    /**
12
     * @var UserApi
13
     */
14
    private $userApi;
15
16 12
    public function __construct(UserApi $userApi)
17
    {
18 12
        $this->userApi = $userApi;
19 12
    }
20
21 6 View Code Duplication
    public function getFunctions()
1 ignored issue
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...
22
    {
23
        return [
24 6
            new \Twig_SimpleFunction('point_avatar', [$this, 'pointAvatarFunction']),
25 6
            new \Twig_SimpleFunction('point_avatar_small', [$this, 'pointAvatarSmallFunction']),
26 6
            new \Twig_SimpleFunction('point_avatar_medium', [$this, 'pointAvatarMediumFunction']),
27 6
            new \Twig_SimpleFunction('point_avatar_large', [$this, 'pointAvatarLargeFunction']),
28 6
            new \Twig_SimpleFunction('point_user_url', [$this, 'pointUserUrl']),
29 6
            new \Twig_SimpleFunction('point_user_blog_url', [$this, 'pointUserBlogUrl']),
30
        ];
31
    }
32
33 6 View Code Duplication
    public function getFilters()
1 ignored issue
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...
34
    {
35
        return [
36 6
            new \Twig_SimpleFilter('point_avatar', [$this, 'pointAvatarFunction']),
37 6
            new \Twig_SimpleFilter('point_avatar_small', [$this, 'pointAvatarSmallFunction']),
38 6
            new \Twig_SimpleFilter('point_avatar_medium', [$this, 'pointAvatarMediumFunction']),
39 6
            new \Twig_SimpleFilter('point_avatar_large', [$this, 'pointAvatarLargeFunction']),
40 6
            new \Twig_SimpleFilter('point_user_url', [$this, 'pointUserUrl']),
41 6
            new \Twig_SimpleFilter('point_user_blog_url', [$this, 'pointUserBlogUrl']),
42
        ];
43
    }
44
45
    public function pointAvatarSmallFunction(string $login): string
46
    {
47
        return $this->pointAvatarFunction($login, UserApi::AVATAR_SIZE_SMALL);
48
    }
49
50
    public function pointAvatarMediumFunction(string $login): string
51
    {
52
        return $this->pointAvatarFunction($login, UserApi::AVATAR_SIZE_MEDIUM);
53
    }
54
55 1
    public function pointAvatarLargeFunction(string $login): string
56
    {
57 1
        return $this->pointAvatarFunction($login, UserApi::AVATAR_SIZE_LARGE);
58
    }
59
60 1
    public function pointAvatarFunction(string $login, $size): string
61
    {
62 1
        return $this->userApi->getAvatarUrlByLogin($login, $size);
63
    }
64
65
    /**
66
     * @param string $login
67
     * @param bool $forceHttps
68
     *
69
     * @return string
70
     */
71
    public function pointUserUrl(string $login, bool $forceHttps = false): string
72
    {
73
        return sprintf('%s//%s.%s/', $forceHttps ? 'https' : '', $login, self::POINT_HOST);
74
    }
75
76
    /**
77
     * @param string $login
78
     * @param bool $forceHttps
79
     *
80
     * @return string
81
     */
82 3
    public function pointUserBlogUrl(string $login, bool $forceHttps = false): string
83
    {
84 3
        return sprintf('%s//%s.%s/blog/', $forceHttps ? 'https' : '', $login, self::POINT_HOST);
85
    }
86
}