CustomSet   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 15
c 1
b 0
f 0
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setWords() 0 4 1
A getPhrases() 0 3 1
A setPhrases() 0 4 1
A getWords() 0 3 1
A checkDict() 0 9 5
1
<?php
2
3
namespace detox\dataset;
4
5
6
use detox\exceptions\BadDictException;
7
8
class CustomSet implements SetContract
9
{
10
    private $words   = [];
11
    private $phrases = [];
12
13
    /**
14
     * @return array
15
     */
16
    public function getWords() : array
17
    {
18
        return $this->words;
19
    }
20
21
    /**
22
     * @param array $words
23
     * @throws BadDictException
24
     */
25
    public function setWords(array $words) : void
26
    {
27
        $this->checkDict($words);
28
        $this->words = $words;
29
    }
30
31
    /**
32
     * @return array
33
     */
34
    public function getPhrases() : array
35
    {
36
        return $this->phrases;
37
    }
38
39
    /**
40
     * @param array $phrases
41
     * @throws BadDictException
42
     */
43
    public function setPhrases(array $phrases) : void
44
    {
45
        $this->checkDict($phrases);
46
        $this->phrases = $phrases;
47
    }
48
49
    /**
50
     * @param array $dict
51
     * @throws BadDictException
52
     */
53
    private function checkDict(array $dict): void
54
    {
55
        foreach ($dict as $score => $words) {
56
            if (is_numeric($score) === false) {
57
                throw new BadDictException('Keys of dict array must be string representation of float number, ex.: 0.9, 1.0 etc');
58
            }
59
            foreach ($words as $word) {
60
                if (is_string($word) === false) {
61
                    throw new BadDictException('Values in dict sub-array must be of type string');
62
                }
63
            }
64
        }
65
    }
66
}