Completed
Push — master ( 789e47...5266e6 )
by Ehsan
03:13
created

QA   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 48
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 20 4
A getQuestions() 0 8 2
A setQuestions() 0 4 1
1
<?php
2
3
namespace Botonomous\plugin\qa;
4
5
use Botonomous\plugin\AbstractPlugin;
6
use Botonomous\utility\StringUtility;
7
8
/**
9
 * Class QA.
10
 */
11
class QA extends AbstractPlugin
12
{
13
    private $questions;
14
15
    /**
16
     * @return string
17
     */
18 3
    public function index()
19
    {
20 3
        $questions = $this->getQuestions();
21 3
        $stringUtility = new StringUtility();
22
23 3
        if (empty($questions)) {
24 1
            return '';
25
        }
26
27 2
        foreach ($questions as $question => $questionInfo) {
28 2
            if ($stringUtility->findInString($question, $this->getSlackbot()->getListener()->getMessage())) {
29
                // found - return random answer
30 1
                $answers = $questionInfo['answers'];
31
32 2
                return $answers[array_rand($answers)];
33
            }
34
        }
35
36 1
        return '';
37
    }
38
39
    /**
40
     * @return array
41
     */
42 3
    public function getQuestions()
43
    {
44 3
        if (!isset($this->questions)) {
45 2
            $this->setQuestions($this->getDictionary()->get('question-answer'));
46
        }
47
48 3
        return $this->questions;
49
    }
50
51
    /**
52
     * @param array $questions
53
     */
54 3
    public function setQuestions(array $questions)
55
    {
56 3
        $this->questions = $questions;
57 3
    }
58
}
59