Answer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAnswer() 0 3 1
A getCommand() 0 3 1
A getQuestion() 0 3 1
A __construct() 0 19 3
1
<?php
2
3
namespace Startwind\Forrest\Command\Answer;
4
5
use Startwind\Forrest\Command\Command;
6
use Startwind\Forrest\Command\CommandFactory;
7
8
class Answer
9
{
10
    private Command $command;
11
    private string $question;
12
    private string $answer;
13
14
    public function __construct(string|array $prompt, string $question, string $answer, string $name = '')
15
    {
16
        if (!$name) {
17
            $name = 'forrest-ai';
18
        }
19
20
        if (is_string($prompt)) {
0 ignored issues
show
introduced by
The condition is_string($prompt) is always false.
Loading history...
21
            $this->command = CommandFactory::fromArray([
22
                CommandFactory::CONFIG_FIELD_NAME => $name,
23
                CommandFactory::CONFIG_FIELD_DESCRIPTION => 'Answer to: ' . $question,
24
                CommandFactory::CONFIG_FIELD_PROMPT => $prompt
25
            ]);
26
        } else {
27
            $this->command = CommandFactory::fromArray($prompt);
28
        }
29
        $this->command->setFullyQualifiedIdentifier('forrest:' . $name);
30
31
        $this->question = $question;
32
        $this->answer = $answer;
33
    }
34
35
    public function getCommand(): Command
36
    {
37
        return $this->command;
38
    }
39
40
    public function getQuestion(): string
41
    {
42
        return $this->question;
43
    }
44
45
    public function getAnswer(): string
46
    {
47
        return $this->answer;
48
    }
49
}
50