UserProfile   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 74
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B getUserAvartar() 0 36 5
A __construct() 0 4 1
A getFunctions() 0 6 1
A getName() 0 4 1
1
<?php
2
3
namespace DoS\UserBundle\Twig;
4
5
use DoS\UserBundle\Model\UserInterface;
6
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
7
8
class UserProfile extends \Twig_Extension
9
{
10
    /**
11
     * @var CacheManager
12
     */
13
    private $cacheManager;
14
15
    public function __construct(CacheManager $cacheManager)
16
    {
17
        $this->cacheManager = $cacheManager;
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function getFunctions()
24
    {
25
        return array(
26
            new \Twig_SimpleFunction('ui_user_avatar', array($this, 'getUserAvartar')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
27
        );
28
    }
29
30
    /**
31
     * @param UserInterface $user
32
     * @param string        $filter
33
     * @param array         $runtimeConfig
34
     *
35
     * @return null|string
36
     */
37
    public function getUserAvartar(UserInterface $user = null, $filter = '70x70', array $runtimeConfig = array())
38
    {
39
        if (!$user) {
40
            return;
41
        }
42
43
        if ($avatar = $user->getProfilePicture()) {
44
            if (preg_match('/\/\//', $avatar)) {
45
                return $avatar;
46
            }
47
48
            if (empty($runtimeConfig)) {
49
                $runtimeConfig = array(
50
                    'thumbnail' => array(
51
                        "size" => explode('x', $filter),
52
                        "mode" => 'inset',
53
                    )
54
                );
55
            }
56
57
            /**
58
             * We must to define `sizing` filter first!
59
             * eg.
60
             *
61
             *   liip_imagine:
62
             *       filter_sets:
63
             *           sizing:
64
             *               data_loader: cmf_media_doctrine_phpcr
65
             *           filters:
66
             *               thumbnail: { size: [200, 200], mode: inset }
67
             */
68
            return $this->cacheManager->getBrowserPath($avatar, 'sizing', $runtimeConfig);
69
        }
70
71
        return;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public function getName()
78
    {
79
        return 'ui_user_profile';
80
    }
81
}
82