RequirejsGlobal::getSourceFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 13
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 20
rs 9.8333
1
<?php
2
/**
3
 * @author Joppe Aarts <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\FrameworkExtraBundle\Twig;
8
9
/**
10
 * Class RequirejsGlobal
11
 * Helper twig global for zicht_requirejs configuration
12
 *
13
 * @package Zicht\Bundle\FrameworkExtraBundle\Twig
14
 */
15
class RequirejsGlobal
16
{
17
    /**
18
     * Constructor
19
     *
20
     * @param array $config
21
     * @param bool $debug
22
     */
23
    public function __construct($config, $debug = false)
24
    {
25
        $this->config = $config;
0 ignored issues
show
Bug Best Practice introduced by
The property config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        $this->debug = $debug;
0 ignored issues
show
Bug Best Practice introduced by
The property debug does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
    }
28
29
    /**
30
     * Set debugging flag. With debugging on, the source files are used as resources in stead of the target files.
31
     *
32
     * @param bool $debug
33
     * @return void
34
     */
35
    public function setDebug($debug)
36
    {
37
        $this->debug = (bool)$debug;
0 ignored issues
show
Bug Best Practice introduced by
The property debug does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
38
    }
39
40
    /**
41
     * @return null|string
42
     */
43
    public function getSourceFile()
44
    {
45
        $sourceFile = null;
46
47
        if ($this->debug) {
48
            $sourceFile = sprintf(
49
                '/%s/%s/%s',
50
                $this->config['src_dir'],
51
                $this->config['base_url'],
52
                $this->config['name']
53
            );
54
        } else {
55
            $sourceFile = sprintf(
56
                '/%s/%s',
57
                $this->config['target_dir'],
58
                $this->config['out']
59
            );
60
        }
61
62
        return $sourceFile;
63
    }
64
}
65