Response::parse()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 9.6111
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of Rivescript-php
4
 *
5
 * (c) Shea Lewis <[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\Commands;
12
13
use Axiom\Rivescript\Contracts\Command;
14
use Axiom\Rivescript\Cortex\Node;
15
16
/**
17
 * Response class
18
 *
19
 * This class handles the Response commands (> ..., * ..., ^ ...)
20
 * and stores the definition in memory.
21
 *
22
 * PHP version 7.4 and higher.
23
 *
24
 * @category Core
25
 * @package  Cortext\Commands
26
 * @author   Shea Lewis <[email protected]>
27
 * @license  https://opensource.org/licenses/MIT MIT
28
 * @link     https://github.com/axiom-labs/rivescript-php
29
 * @since    0.3.0
30
 */
31
class Response implements Command
32
{
33
    /**
34
     * Parse the command.
35
     *
36
     * @param Node $node The node is a line from the Rivescript file.
37
     *
38
     * @return void
39
     */
40
    public function parse(Node $node): void
41
    {
42
        if ($node->command() === '-' || $node->command() === '*' || $node->command() === '^') {
43
            $topic = synapse()->memory->shortTerm()->get('topic') ?: 'random';
44
            $key = synapse()->memory->shortTerm()->get('trigger');
45
            $trigger = synapse()->brain->topic($topic)->triggers()->get($key);
46
47
            $trigger['responses']->attach($node);
48
49
            synapse()->brain->topic($topic)->triggers()->put($key, $trigger);
50
        }
51
    }
52
}
53