Passed
Push — master ( 51d08f...a6e528 )
by Henri
01:20
created

JScriptTrait::checkCommentInScript()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
nc 3
nop 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace HnrAzevedo\Viewer;
4
5
6
trait JScriptTrait{
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
            $inComment = true;
23
        }else{
24
            $inComment = (strpos($value,'*/')) ? false : $inComment;
25
        }
26
        return $inComment;
27
    }
28
29
    protected function checkScriptNeed(bool $inComment, string $value): bool
30
    {
31
        if(($inComment || strpos($value,'//'))){
32
            return false;
33
        } 
34
        return true;
35
    }
36
37
    protected function treatScript(string $value): string
38
    {
39
        while(  strpos($value,'/*') && strpos($value,'*/')  ){
40
            $replace = substr($value,strripos ($value,'/*'),strripos ($value,'*/')+2);
41
            $value = str_replace($replace,'',$value);
42
        }
43
        if(strpos($value,'*/')){
44
            $value = substr($value,strpos($value,'*/')+2);
45
        }
46
        return $value;
47
    }
48
49
}