TwigExtension::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
3
namespace FOA\CronBundle\Twig;
4
5
/**
6
 * @author Novikov Viktor
7
 */
8
class TwigExtension extends \Twig_Extension
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $wwwUser;
14
15
    /**
16
     * @var string
17
     */
18
    protected $logDir;
19
20
    /**
21
     * @var string
22
     */
23
    protected $symfonyCommand;
24
25
    /**
26
     * @param string $logDir
27
     * @param string $kernelDir
28
     */
29
    public function __construct($logDir, $kernelDir)
30
    {
31
        if (function_exists('posix_getpwuid')) {
32
            $this->wwwUser = posix_getpwuid(posix_geteuid());
33
        } else {
34
            $this->wwwUser = [
35
                'name' => get_current_user(),
36
                'dir'  => '-',
37
            ];
38
        }
39
        $this->logDir = $logDir;
40
        $this->symfonyCommand = 'php ' . $kernelDir . '/console';
41
    }
42
43
    /**
44
     * @return string[]
45
     */
46
    public function getGlobals()
47
    {
48
        return [
49
            'wwwUser'        => $this->wwwUser,
50
            'logDir'         => $this->logDir,
51
            'symfonyCommand' => $this->symfonyCommand,
52
        ];
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getName()
59
    {
60
        return 'bcc-cron-manager';
61
    }
62
}
63