SimpleMatcher   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getSubject() 0 4 1
A matches() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Greppy package.
5
 *
6
 * (c) Daniel Ribeiro <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Relax\Greppy;
13
14
/**
15
 * A basic regex matcher.
16
 *
17
 * @author Daniel Ribeiro <[email protected]>
18
 * @package Greppy
19
 */
20
final class SimpleMatcher implements Matcher
21
{
22
    /**
23
     * @var string
24
     */
25
    private $subject;
26
27
    /**
28
     * @param string $subject The subject to match against
29
     * @throws \InvalidArgumentException
30
     */
31
    public function __construct($subject)
32
    {
33
        if (!is_string($subject)) {
34
            throw new \InvalidArgumentException(sprintf("Expected string subject, got %s.", $subject));
35
        }
36
        
37
        $this->subject = $subject;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getSubject()
44
    {
45
        return $this->subject;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function matches(Pattern $pattern)
52
    {
53
        return (bool) preg_match((string) $pattern, $this->getSubject());
54
    }
55
}
56