Test Failed
Push — main ( 77a5ed...f65f10 )
by Guillaume
02:41
created

JsUtils::generateFunction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 3
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
namespace PHPMV\utils;
3
4
class JsUtils{
5
    static private array $removeQuote = ["start"=>"!!%","end"=>"%!!"];
6 2
7 2
    public static function cleanJSONFunctions(string $json):string {
8 2
        $pattern='/(("|\')!!%)|(%!!("|\'))/';
9
        return \preg_replace($pattern, '', $json);
10
    }
11
12 2
    public static function removeQuotes(string $body):string{
13
        return self::$removeQuote["start"].$body.self::$removeQuote["end"];
14
    }
15
16
    public static function generateFunction(string $body, array $params = [], bool $needRemoveQuote = true):string {
17
        if($needRemoveQuote){
18
            return self::removeQuotes("function(".implode(",",$params)."){".$body."}");
19
        }
20
        return "function(".implode(",",$params)."){".$body."}";
21
    }
22
}
23
24