Completed
Push — master ( 651d7b...ccffc6 )
by Dawid
02:51
created

DataCollectorExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 60%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 41
ccs 6
cts 10
cp 0.6
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 6 1
A schemaFileExists() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Twig;
6
7
use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
8
use Symfony\Component\Config\FileLocatorInterface;
9
10
class DataCollectorExtension extends \Twig_Extension
11
{
12
    /**
13
     * @var FileLocatorInterface
14
     */
15
    protected $fileLocator;
16
17
    /**
18
     * @param FileLocatorInterface $fileLocator
19
     */
20 12
    public function __construct(FileLocatorInterface $fileLocator)
21
    {
22 12
        $this->fileLocator = $fileLocator;
23 12
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getFunctions()
29
    {
30
        return [
31
            new \Twig_SimpleFunction('schema_file_exists', [$this, 'schemaFileExists']),
32
        ];
33
    }
34
35
    /**
36
     * @param string $schemaLocation
37
     *
38
     * @return bool
39
     */
40 11
    public function schemaFileExists(string $schemaLocation): bool
41
    {
42
        try {
43 11
            $this->fileLocator->locate($schemaLocation);
44
45 11
            return true;
46
        } catch (FileLocatorFileNotFoundException $e) {
47
            return false;
48
        }
49
    }
50
}
51