Analysis::getTrail()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
namespace PiedWeb\TextAnalyzer;
4
5
class Analysis
6
{
7
    private $expressions = [];
8
9
    private $wordNumber = 0;
10
11
    private $trail = [];
12
13 3
    public function __construct(
14
        array $expressions,
15
        int $wordNumber,
16
        array $trail
17
    ) {
18 3
        $this->expressions = $expressions;
19 3
        $this->wordNumber = $wordNumber;
20 3
        $this->trail = $trail;
21 3
    }
22
23 3
    public function getExpressionsByDensity()
24
    {
25 3
        $expressions = $this->expressions;
26 3
        foreach ($expressions as $k => $v) {
27 3
            $expressions[$k] = round(($v / $this->getWordNumber()) * 10000) / 100;
28
        }
29
30 3
        return $expressions;
31
    }
32
33 3
    public function getWordNumber()
34
    {
35 3
        return $this->wordNumber;
36
    }
37
38 3
    public function getExpressions(?int $number = null)
39
    {
40 3
        return ! $number ? $this->expressions : array_slice($this->getExpressions(), 0, $number);
41
    }
42
43
    /**
44
     * @return array containing sentence where we can find expresion
45
     */
46
    public function getTrail(string $expression)
47
    {
48
        if (isset($this->trail[$expression])) {
49
            return $this->trail[$expression];
50
        }
51
52
        return [];
53
    }
54
55 3
    public function getTrails()
56
    {
57 3
        return $this->trail;
58
    }
59
}
60