JScriptTrait::checkInScript()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
nc 4
nop 2
dl 0
loc 9
rs 10
c 1
b 0
f 0
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