DescriptionExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A getDescription() 0 6 1
A getName() 0 4 1
A getSubject() 0 8 2
1
<?php
2
3
namespace Psi\Bundle\Description\Twig;
4
5
use Psi\Component\Description\DescriptionFactory;
6
use Psi\Component\Description\Subject;
7
8
class DescriptionExtension extends \Twig_Extension
9
{
10
    private $descriptionFactory;
11
12
    public function __construct(DescriptionFactory $descriptionFactory)
13
    {
14
        $this->descriptionFactory = $descriptionFactory;
15
    }
16
17
    public function getFunctions()
18
    {
19
        return [
20
            new \Twig_SimpleFunction('psi_describe', [$this, 'getDescription']),
21
        ];
22
    }
23
24
    public function getDescription($classOrObject)
25
    {
26
        $subject = $this->getSubject($classOrObject);
27
28
        return $this->descriptionFactory->describe($subject);
29
    }
30
31
    public function getName()
32
    {
33
        return 'psi_resource_description';
34
    }
35
36
    private function getSubject($classOrObject)
37
    {
38
        if (is_object($classOrObject)) {
39
            return Subject::createFromObject($classOrObject);
40
        }
41
42
        return Subject::createFromClass($classOrObject);
43
    }
44
}
45