Passed
Branch master (106872)
by Henri
02:03 queued 53s
created

CheckTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check_viewExist() 0 4 2
A check_importExist() 0 14 2
1
<?php
2
3
namespace HnrAzevedo\Viewer;
4
5
use Exception;
6
7
trait CheckTrait{
8
9
    protected function check_viewExist(string $viewfile){
10
        if(!file_exists($this->path . DIRECTORY_SEPARATOR . $viewfile . '.view.php')){
11
            $v = $this->path . DIRECTORY_SEPARATOR . $viewfile;
12
            throw new Exception("Preview file {$v} not found");
13
        }
14
    }
15
16
    protected function check_importExist($import): string
17
    {
18
        $tpl = str_replace('.',DIRECTORY_SEPARATOR,
19
                substr(
20
                    $import,
21
                    strpos($import,'\'')+1,
22
                    strlen($import)-11
23
                )
24
            );
25
26
        if(!file_exists($this->path . DIRECTORY_SEPARATOR . $tpl . '.tpl.php')){
27
            throw new Exception('Import \''.str_replace(['@import(\'','\')'],'',$import).'\' não encontrado.');
28
        }
29
        return $tpl;
30
    }
31
32
}