JScriptTrait   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 15
eloc 18
c 2
b 0
f 1
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A checkInScript() 0 9 4
A treatScript() 0 12 4
A checkScriptNeed() 0 6 3
A checkCommentInScript() 0 7 4
1
<?php
2
3
namespace HnrAzevedo\Viewer;
4
5
trait JScriptTrait
6
{
7
8
    protected function checkInScript(bool $inScript, string $value): bool
9
    {
10
        if((substr(ltrim($value),0,8) === '<script>' && !strpos($value,'src'))){
11
            $inScript = true;
12
        }
13
        if((substr(ltrim($value),0,9) === '</script>')){
14
            $inScript = false;
15
        }
16
        return $inScript;
17
    }
18
19
    protected function checkCommentInScript(bool $inComment, string $value): bool
20
    {
21
        if(strpos($value,'/*') && !strpos($value,'*/')){
22
            return true;
23
        }
24
        
25
        return (strpos($value,'*/')) ? false : $inComment;
26
    }
27
28
    protected function checkScriptNeed(bool $inComment, string $value): bool
29
    {
30
        if(($inComment || strpos($value,'//'))){
31
            return false;
32
        } 
33
        return true;
34
    }
35
36
    protected function treatScript(string $value): string
37
    {
38
        while(  strpos($value,'/*') && strpos($value,'*/')  ){
39
            $replace = substr($value,strripos ($value,'/*'),strripos ($value,'*/')+2);
40
            $value = str_replace($replace,'',$value);
41
        }
42
43
        if(strpos($value,'*/')){
44
            $value = substr($value,strpos($value,'*/')+2);
45
        }
46
        
47
        return $value;
48
    }
49
50
}
51