Trigger   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseTags() 0 10 1
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\Triggers;
12
13
use Axiom\Rivescript\Contracts\Trigger as TriggerContract;
14
use Axiom\Rivescript\Cortex\Input;
15
16
/**
17
 * Trigger class
18
 *
19
 * The trigger class is the base class for the trigger
20
 * detectors in this directory. It will contain the parseTags()
21
 * function that all trigger detectors use.
22
 *
23
 * PHP version 7.4 and higher.
24
 *
25
 * @category Core
26
 * @package  Cortext\Triggers
27
 * @author   Shea Lewis <[email protected]>
28
 * @license  https://opensource.org/licenses/MIT MIT
29
 * @link     https://github.com/axiom-labs/rivescript-php
30
 * @since    0.3.0
31
 */
32
abstract class Trigger implements TriggerContract
33
{
34
35
    /**
36
     * Parse the response through the available tags.
37
     *
38
     * @param string $trigger The trigger to parse tags on.
39
     * @param Input  $input   Input information.
40
     *
41
     * @return string
42
     */
43
    protected function parseTags(string $trigger, Input $input): string
44
    {
45
        synapse()->tags->each(function ($tag) use (&$trigger, $input) {
46
            $class = "\\Axiom\\Rivescript\\Cortex\\Tags\\$tag";
47
            $tagClass = new $class("trigger");
48
49
            $trigger = $tagClass->parse($trigger, $input);
50
        });
51
52
        return $trigger;
53
    }
54
}
55