Completed
Push — master ( e4d5a5...d16560 )
by Dawid
03:05
created

DataCollectorExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

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 10
cts 10
cp 1
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 16
    public function __construct(FileLocatorInterface $fileLocator)
21
    {
22 16
        $this->fileLocator = $fileLocator;
23 16
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function getFunctions()
29
    {
30
        return [
31 1
            new \Twig_SimpleFunction('schema_file_exists', [$this, 'schemaFileExists']),
32
        ];
33
    }
34
35
    /**
36
     * @param string $schemaLocation
37
     *
38
     * @return bool
39
     */
40 14
    public function schemaFileExists(string $schemaLocation): bool
41
    {
42
        try {
43 14
            $this->fileLocator->locate($schemaLocation);
44
45 14
            return true;
46 1
        } catch (FileLocatorFileNotFoundException $e) {
47 1
            return false;
48
        }
49
    }
50
}
51