Completed
Push — dev ( 8a2d43...215a79 )
by James Ekow Abaka
08:03
created

Core   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __destruct() 0 13 5
A setData() 0 6 1
1
<?php
2
namespace ntentan\honam\engines\smarty;
3
4
use ntentan\honam\factories\HelperFactory;
5
use Smarty;
6
7
class Core extends Smarty
8
{
9
    private $temp;
10
    private $helperFactory;
11
    
12
    public function __construct(HelperFactory $helperFactory, string $tempDirectory)
13
    {
14
        parent::__construct();
15
        $this->temp = $tempDirectory;
16
        $this->helperFactory = $helperFactory;
17
        $this->setCompileDir("{$this->temp}/smarty_compiled_templates");
18
    }
19
    
20
    public function __destruct() 
21
    {
22
        if($this->temp === '.' && file_exists("./smarty_compiled_templates")) {
23
            $files = scandir("./smarty_compiled_templates");
24
            foreach($files as $file) {
25
                if($file == "." | $file == "..") {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: ($file == '.') | $file == '..', Probably Intended Meaning: $file == ('.' | $file == '..')

When comparing the result of a bit operation, we suggest to add explicit parenthesis and not to rely on PHP’s built-in operator precedence to ensure the code behaves as intended and to make it more readable.

Let’s take a look at these examples:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);
Loading history...
26
                    continue;
27
                }
28
                unlink("./smarty_compiled_templates/$file");
29
            }
30
            rmdir("./smarty_compiled_templates");
31
        }
32
    }
33
34
    public function setData($data)
35
    {
36
        $this->clearAllAssign();
37
        $this->assign($data);
38
        $this->assign('honam', $this->helperFactory);
39
    }
40
}
41