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

GreaterThanOrEqual::matches()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 15
rs 9.6111
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
 * GreaterThanOrEqual class
17
 *
18
 * This class handles >= greater than or equals 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 GreaterThanOrEqual extends Condition implements ConditionContract
30
{
31
32
    /**
33
     * Handle conditions '>=' also known as greater than or equal to.
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
            foreach ($matches as $match) {
0 ignored issues
show
Bug introduced by
The expression $matches of type false is not traversable.
Loading history...
47
                if ((is_array($match) === true && count($match) >= 2)) {
48
                    return $match[1] >= $match[3];
49
                }
50
            }
51
        }
52
53
        return false;
54
    }
55
}
56