Passed
Push — main ( 976a1c...cb0b4a )
by Guillaume
03:00
created

JsUtils::removeQuotes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
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='/(("|\')'.self::$removeQuote['start'].')|('.self::$removeQuote['end'].'("|\'))/';
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 6
            return self::removeQuotes("function(".implode(",",$params)."){".$body."}");
19
        }
20 6
        return "function(".implode(",",$params)."){".$body."}";
21
    }
22
23 2
    public static function declareVariable(string $type, string $name, $value):string {
24 2
        return $type." ".$name." = ".$value.";\n";
25
    }
26
27
    public static function kebabToPascal(string $string){
28
        $string[0] = \strtoupper($string[0]);
29
        $pattern='/(-\w{1})/';
30
        return \preg_replace_callback($pattern,
31
            function ($matches) use ($string){
0 ignored issues
show
Unused Code introduced by
The import $string is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
32
                return \strtoupper($matches[1][1]);
33
34
        },$string);
35
    }
36
}
37
38