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.

Json   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 12 4
A isValidPattern() 0 8 2
A transformPattern() 0 4 1
1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher\Pattern\Assert;
4
5
final class Json
6
{
7
    const TRANSFORM_QUOTATION_PATTERN = '/([^"])@([a-zA-Z0-9\.]+)@([^"])/';
8
    const TRANSFORM_QUOTATION_REPLACEMENT = '$1"@$2@"$3';
9
10
    /**
11
     * @param string $value
12
     * @return bool
13
     */
14
    public static function isValid($value)
15
    {
16
        if (!is_string($value)) {
17
            return false;
18
        }
19
20
        if (null === json_decode($value) && JSON_ERROR_NONE !== json_last_error()) {
21
            return false;
22
        }
23
24
        return true;
25
    }
26
27
    /**
28
     * Before checking json it wraps type patterns (@type@) with quotes ("@type@")
29
     *
30
     * @param string $value
31
     * @return bool
32
     */
33
    public static function isValidPattern($value)
34
    {
35
        if (!is_string($value)) {
36
            return false;
37
        }
38
39
        return self::isValid(self::transformPattern($value));
40
    }
41
42
    /**
43
     * Wraps placeholders which arent wrapped with quotes yet
44
     *
45
     * @param $pattern
46
     * @return mixed
47
     */
48
    public static function transformPattern($pattern)
49
    {
50
        return preg_replace(self::TRANSFORM_QUOTATION_PATTERN, self::TRANSFORM_QUOTATION_REPLACEMENT, $pattern);
51
    }
52
}
53