GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 41736a...50a035 )
by Charlotte
02:02
created

Utility   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseParameters() 0 15 3
1
<?php
2
/**
3
 * Plasma Core component
4
 * Copyright 2018 PlasmaPHP, All Rights Reserved
5
 *
6
 * Website: https://github.com/PlasmaPHP
7
 * License: https://github.com/PlasmaPHP/core/blob/master/LICENSE
8
*/
9
10
namespace Plasma;
11
12
/**
13
 * Common utilities for components.
14
 */
15
class Utility {
16
    /**
17
     * Parses a query containing parameters into an array, and can replace them with a predefined replacement (can be a callable).
18
     * The callable is used to return numbered parameters (such as used in PostgreSQL), or any other kind of parameters supported by the DBMS.
19
     * @param string                $query
20
     * @param string|callable|null  $replaceParams  If `null` is passed, it will not replace the parameters.
21
     * @param string                $regex
22
     * @return array  `[ 'query' => string, 'parameters' => array ]`  The `parameters` array is an numeric array (= position, starting at 1), which map to the original parameter.
23
     */
24 2
    static function parseParameters(string $query, $replaceParams = '?', string $regex = '/(:[a-z]+)|\?|\$\d+/i'): array {
25 2
        $params = array();
26 2
        $position = 1;
27
        
28
        $query = \preg_replace_callback($regex, function (array $match) use ($replaceParams, &$params, &$position) {
29 2
            $params[($position++)] = $match[0];
30
            
31 2
            if($replaceParams !== null) {
32 2
                return (\is_callable($replaceParams) ? $replaceParams() : $replaceParams);
33
            }
34
            
35
            return $match[0];
36 2
        }, $query);
37
        
38 2
        return array('query' => $query, 'parameters' => $params);
39
    }
40
}
41