Condition::parse()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 15
rs 10
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\Responses;
12
13
use Axiom\Rivescript\Contracts\Response as ResponseContract;
14
15
/**
16
 * Condition class
17
 *
18
 * The Condition class determines the type of condition and
19
 * executes it.
20
 *
21
 * PHP version 7.4 and higher.
22
 *
23
 * @category Core
24
 * @package  Cortext\Responses
25
 * @author   Johnny Mast <[email protected]>
26
 * @license  https://opensource.org/licenses/MIT MIT
27
 * @link     https://github.com/axiom-labs/rivescript-php
28
 * @since    0.4.0
29
 */
30
class Condition extends Response implements ResponseContract
31
{
32
33
    /**
34
     * Handle Conditions, if the source is a Condition
35
     * then we need to handle the conditions.
36
     *
37
     * @return false|mixed
38
     */
39
    public function parse()
40
    {
41
        if ($this->responseQueueItem()->getCommand() === '*') {
42
            foreach (synapse()->conditions as $class) {
43
                $class = "\\Axiom\\Rivescript\\Cortex\\Conditions\\{$class}";
44
                $class = new $class();
45
46
                $result = $class->parse($this->source());
47
48
                if ($result !== false) {
49
                    return $result;
50
                }
51
            }
52
        }
53
        return false;
54
    }
55
56
    /**
57
     * Indicate the type of response this
58
     * class handles.
59
     *
60
     * @return string
61
     */
62
    public function getType(): string
63
    {
64
        return 'condition';
65
    }
66
}
67