Article   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 92.59%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 53
ccs 25
cts 27
cp 0.9259
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 3
A getArticle() 0 3 1
A checkBadWords() 0 12 4
1
<?php
2
namespace Mystem;
3
4
/**
5
 * Class MystemArticle
6
 */
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 4
        }
34 4
    }
35
36
    /**
37
     * @return string
38
     */
39 1
    public function getArticle()
40
    {
41 1
        return $this->article;
42
    }
43
44
    /**
45
     * @param bool $stopOnFirst
46
     * @return array
47
     */
48 2
    public function checkBadWords($stopOnFirst = false)
49
    {
50 2
        $result = array();
51 2
        foreach ($this->words as &$word) {
52 2
            if ($word->isBadWord()) {
53 1
                $result[$word->original] = $word->normalized();
54 1
                if ($stopOnFirst) {
55 1
                    break;
56
                }
57 1
            }
58 2
        }
59 2
        return $result;
60
    }
61
}
62