Passed
Push — master ( d44e36...c2d6d5 )
by Johnny
02:21
created

Equals   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A matches() 0 13 4
1
<?php
2
/*
3
 * This file is part of Rivescript-php
4
 *
5
 * (c) Johnny Mast <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Axiom\Rivescript\Cortex\Condition;
12
13
use Axiom\Rivescript\Contracts\Condition as ConditionContract;
14
15
/**
16
 * Equals class
17
 *
18
 * This class handles == equals condition.
19
 *
20
 * aliases:
21
 *  - eq
22
 *
23
 * PHP version 7.4 and higher.
24
 *
25
 * @category Core
26
 * @package  Cortext\Condition
27
 * @author   Johnny Mast <[email protected]>
28
 * @license  https://opensource.org/licenses/MIT MIT
29
 * @link     https://github.com/axiom-labs/rivescript-php
30
 * @since    0.4.0
31
 */
32
class Equals extends Condition implements ConditionContract
33
{
34
    /**
35
     * Handle conditions '==' or its alias 'eq'.
36
     *
37
     * @param string $source The source to parse.
38
     *
39
     * @return bool
40
     */
41
    public function matches(string $source): bool
42
    {
43
        $pattern = "/^([\S]+) (==|eq) ([\S]+) =>/";
44
45
        if ($this->matchesPattern($pattern, $source) === true) {
46
            $matches = $this->getMatchesFromPattern($pattern, $source);
47
48
            if (isset($matches[0]) === true && count($matches[0]) >= 2) {
49
                return ($matches[0][1] === $matches[0][3]);
50
            }
51
        }
52
53
        return false;
54
    }
55
}
56