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

LessThan   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 23
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
 * LessThan class
17
 *
18
 * This class handles < or less than condition.
19
 *
20
 * PHP version 7.4 and higher.
21
 *
22
 * @category Core
23
 * @package  Cortext\Condition
24
 * @author   Johnny Mast <[email protected]>
25
 * @license  https://opensource.org/licenses/MIT MIT
26
 * @link     https://github.com/axiom-labs/rivescript-php
27
 * @since    0.4.0
28
 */
29
class LessThan extends Condition implements ConditionContract
30
{
31
32
    /**
33
     * Handle conditions '<' also known as less than.
34
     *
35
     * @param string $source The source to parse.
36
     *
37
     * @return bool
38
     */
39
    public function matches(string $source): bool
40
    {
41
        $pattern = "/^([\S]+) (<) ([\S]+) =>/";
42
43
        if ($this->matchesPattern($pattern, $source) === true) {
44
            $matches = $this->getMatchesFromPattern($pattern, $source);
45
46
            if (isset($matches[0]) === true && count($matches[0]) >= 2) {
47
                return ($matches[0][1] < $matches[0][3]);
48
            }
49
        }
50
51
        return false;
52
    }
53
}
54