Passed
Push — main ( f5d3c8...cedc07 )
by Guillaume
02:48
created

JsUtils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cleanJSONFunctions() 0 3 1
A removeQuotes() 0 2 1
A generateFunction() 0 5 2
1
<?php
2
namespace PHPMV\utils;
3
4
class JsUtils{
5
    static private array $removeQuote = ["start"=>"!!%","end"=>"%!!"];
6
7 2
    public static function cleanJSONFunctions(string $json):string {
8 2
        $pattern='/(("|\')!!%)|(%!!("|\'))/';
9 2
        return \preg_replace($pattern, '', $json);
10
    }
11
12 8
    public static function removeQuotes(string $body):string{
13 8
        return self::$removeQuote["start"].$body.self::$removeQuote["end"];
14
    }
15
16 10
    public static function generateFunction(string $body, array $params = [], bool $needRemoveQuote = true):string {
17 10
        if($needRemoveQuote){
18 7
            return self::removeQuotes("function(".implode(",",$params)."){".$body."}");
19
        }
20 5
        return "function(".implode(",",$params)."){".$body."}";
21
    }
22
}
23
24