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

JsUtils::removeQuotes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
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