Equals   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 15 5
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\Conditions;
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\Conditions
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 false|string
40
     */
41
    public function parse(string $source)
42
    {
43
        $pattern = "/^([\S]+) (==|eq) ([\S]+) =>\s(.*)$/";
44
45
        if ($this->matchesPattern($pattern, $source) === true) {
46
            $matches = $this->getMatchesFromPattern($pattern, $source);
47
48
            if (isset($matches[0]) === true and count($matches[0]) >= 2) {
49
                if ($matches[0][1] === $matches[0][3]) {
50
                    return $matches[0][4];
51
                }
52
            }
53
        }
54
55
        return false;
56
    }
57
}
58