Total Complexity | 8 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 95.65% |
Changes | 0 |
1 | <?php |
||
7 | class Article |
||
8 | { |
||
9 | /* @var string $article */ |
||
10 | public $article = ''; |
||
11 | |||
12 | /* @var ArticleWord[] $words */ |
||
13 | public $words = array(); |
||
14 | |||
15 | /** |
||
16 | * @param string $text |
||
17 | */ |
||
18 | 4 | public function __construct($text) |
|
19 | { |
||
20 | 4 | $offset = 0; |
|
21 | 4 | $this->article = $text; |
|
22 | |||
23 | 4 | $stemmed = Mystem::stemm($text); |
|
24 | 4 | foreach ($stemmed as $part) { |
|
25 | 4 | $word = ArticleWord::newFromLexicalString($part, 1, $this->article); |
|
26 | 4 | $position = @mb_strpos($this->article, $word->original, $offset); |
|
27 | 4 | if ($position === false) { //Can't find original word |
|
28 | $position = $offset + 1; |
||
29 | } |
||
30 | 4 | $word->position = $position; |
|
31 | 4 | $offset = $word->position + mb_strlen($word->original); |
|
32 | 4 | $this->words[] = $word; |
|
33 | } |
||
34 | 4 | } |
|
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | 1 | public function getArticle() |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param bool $stopOnFirst |
||
46 | * @return array |
||
47 | */ |
||
48 | 2 | public function checkBadWords($stopOnFirst = false) |
|
62 |