Test Failed
Push — main ( 77a5ed...f65f10 )
by Guillaume
02:41
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
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
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 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