Passed
Push — develop ( 176c47...d119f8 )
by Andrea
14:57
created

UtilitaExtension::serviceExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\BiCoreBundle\Twig\Extension;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
7
class UtilitaExtension extends \Twig_Extension
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    protected $container;
13
14 19
    public function __construct(ContainerInterface $container)
15
    {
16 19
        $this->container = $container;
17 19
    }
18
19
    public function getFunctions()
20
    {
21
        return array(
22
            new \Twig_SimpleFunction('json_decode', array($this, 'jsonDecode', 'is_safe' => array('html'))),
23
            new \Twig_SimpleFunction('db2data', array($this, 'getDb2data', 'is_safe' => array('html'))),
24
            new \Twig_SimpleFunction('remote_file_exists', array($this, 'remoteFileExists', 'is_safe' => array('html'))),
25
            new \Twig_SimpleFunction('serviceExists', array($this, 'serviceExists')),
26
            new \Twig_SimpleFunction('getParameter', array($this, 'getParameter')),
27
        );
28
    }
29
    
30
    public function getParameter($parameter)
31
    {
32
        if ($this->container->hasParameter($parameter)) {
33
            return $this->container->getParameter($parameter);
34
        } else {
35
            return '';
36
        }
37
    }
38
39
    public function serviceExists($service)
40
    {
41
        return $this->container->has($service);
42
    }
43
    
44
    public function getDb2data($giorno)
45
    {
46
        // highlight_string highlights php code only if '<?php' tag is present.
47
48
        return FiUtilita::db2data($giorno, true);
0 ignored issues
show
Bug introduced by
The type Cdf\BiCoreBundle\Twig\Extension\FiUtilita was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
    }
50 6
    public function jsonDecode($string)
51
    {
52 6
        return json_decode($string);
53
    }
54
    /**
55
     * @param string $url
56
     *
57
     * @return bool
58
     */
59
    public function remoteFileExists($url)
60
    {
61
        $ch = curl_init($url);
62
        curl_setopt($ch, CURLOPT_NOBODY, true);
63
        curl_exec($ch);
64
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
65
        curl_close($ch);
66
        return $status === 200 ? true : false;
67
    }
68
}
69