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

JsUtils::generateFunction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
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