Passed
Push — master ( fbc72e...fd2e1d )
by Alexey
04:39
created

PointUserExtension::pointAvatarFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
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
}