Factory::Adverb()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * AnalyzerText package.
4
 *
5
 * @author  Peter Gribanov <[email protected]>
6
 */
7
8
namespace AnalyzerText\Filter;
9
10
use AnalyzerText\Analyzer\Analyzer;
11
use AnalyzerText\Filter\WordList\Adverb;
12
use AnalyzerText\Filter\WordList\Preposition;
13
use AnalyzerText\Filter\WordList\Pronoun;
14
use AnalyzerText\Filter\WordList\Union;
15
16
/**
17
 * Фабрика фильтров.
18
 *
19
 * @author  Peter Gribanov <[email protected]>
20
 */
21
class Factory
22
{
23
    /**
24
     * @var Analyzer
25
     */
26
    private $analyzer;
27
28
    /**
29
     * @param Analyzer $analyzer
30
     */
31 13
    public function __construct(Analyzer $analyzer)
32
    {
33 13
        $this->analyzer = $analyzer;
34 13
    }
35
36
    /**
37
     * Применяет фильтр Informative.
38
     *
39
     * @return Factory
40
     */
41 8
    public function Informative()
42
    {
43 8
        return $this->apply(new Informative($this->analyzer->getText()));
44
    }
45
46
    /**
47
     * Применяет фильтр Preposition.
48
     *
49
     * @return Factory
50
     */
51 1
    public function Preposition()
52
    {
53 1
        return $this->apply(new Preposition($this->analyzer->getText()));
54
    }
55
56
    /**
57
     * Применяет фильтр Pronoun.
58
     *
59
     * @return Factory
60
     */
61 1
    public function Pronoun()
62
    {
63 1
        return $this->apply(new Pronoun($this->analyzer->getText()));
64
    }
65
66
    /**
67
     * Применяет фильтр Union.
68
     *
69
     * @return Factory
70
     */
71 1
    public function Union()
72
    {
73 1
        return $this->apply(new Union($this->analyzer->getText()));
74
    }
75
76
    /**
77
     * Применяет фильтр Adverb.
78
     *
79
     * @return Factory
80
     */
81 1
    public function Adverb()
82
    {
83 1
        return $this->apply(new Adverb($this->analyzer->getText()));
84
    }
85
86
    /**
87
     * Применяет фильтр
88
     *
89
     * @param Filter $filter
90
     *
91
     * @return Factory
92
     */
93 12
    private function apply(Filter $filter)
94
    {
95 12
        if ($filter->getText()->count()) {
96 12
            $words = array();
97 12
            foreach ($filter as $word) {
98 10
                $words[] = $word->getWord();
99
            }
100 12
            $text_class = get_class($filter->getText());
101 12
            $this->analyzer->setText(new $text_class(implode(' ', $words)));
102
        }
103
104 12
        return $this;
105
    }
106
}
107