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.

ExpressionMatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 12 2
A canMatch() 0 4 2
1
<?php
2
3
namespace Coduo\PHPMatcher\Matcher;
4
5
use Coduo\ToString\StringConverter;
6
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
7
8
final class ExpressionMatcher extends Matcher
9
{
10
    const MATCH_PATTERN = "/^expr\((.*?)\)$/";
11
12
    /**
13
     * {@inheritDoc}
14
     */
15
    public function match($value, $pattern)
16
    {
17
        $language = new ExpressionLanguage();
18
        preg_match(self::MATCH_PATTERN, $pattern, $matches);
19
        $expressionResult = $language->evaluate($matches[1], array('value' => $value));
20
21
        if (!$expressionResult) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $expressionResult of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
22
            $this->error = sprintf("\"%s\" expression fails for value \"%s\".", $pattern, new StringConverter($value));
23
        }
24
25
        return (bool) $expressionResult;
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function canMatch($pattern)
32
    {
33
        return is_string($pattern) && 0 !== preg_match(self::MATCH_PATTERN, $pattern);
34
    }
35
}
36