MediaExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A media() 0 7 2
1
<?php
2
3
namespace Media\Twig;
4
5
use Media\Entity\MediaInterface;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
class MediaExtension extends \Twig_Extension
9
{
10
11
    /**
12
     *
13
     * @var RequestStack
14
     */
15
    private $request;
16
    
17
    public function __construct(RequestStack $request)
18
    {
19
        $this->request = $request;
20
    }
21
    
22
    /**
23
     * 
24
     * @return array
25
     */
26
    public function getFunctions()
27
    {
28
        return [
29
            new \Twig_SimpleFunction('media', [$this, 'media'])
30
        ];
31
    }
32
33
    /**
34
     * 
35
     * @param MediaInterface $media
36
     * 
37
     * @return string
38
     */
39
    public function media(MediaInterface $media = null)
40
    {
41
        if (empty($media)) {
42
            return true;
43
        }
44
        return sprintf('%s/uploads/%s/%s', $this->request->getCurrentRequest()->getBasePath(), $media->getContext(), $media->getFileName());
45
    }
46
47
}
48