Thesaurus   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getWords() 0 24 4
1
<?php
2
3
namespace Hasantayyar\Synonyms\Services;
4
5
use Yangqi\Htmldom\Htmldom as Htmldom;
6
7
/**
8
 *  
9
 *
10
 * @author Hasan Tayyar BEŞİK <[email protected]>
11
 * @author Hasan Tayyar BEŞİK 
12
 * @version 0.1
13
 * @package Synonyms 
14
 */
15
class Thesaurus {
16
17
    /**
18
     * base url with slash "/" at the end
19
     * @var string
20
     */
21
    public $base_url = 'http://thesaurus.com/browse/';
22
23
    /**
24
     * 
25
     * @return array
26
     */
27
    public function getWords($word) {
28
        $suggestions = array();
29
        $html = new Htmldom($this->base_url . $word);
30
        $listDiv = $html->find('.relevancy-list', 0);
31
        for ($i = 0; $i <= 5; ++$i) {
32
            $list = $listDiv->find('ul', $i);
33
            if (!$list) {
34
                continue;
35
            }
36
            $suggestions[$i]['data'] = array();
37
            foreach ($list->find('li') as $element) {
38
                $data = array();
39
                $linkElement = $element->find('a', 0);
40
                $linkSpan = $element->find('a', 0)->find('span', 0);
41
                $linkHref = $linkElement->href;
42
                $dataCategory = html_entity_decode($linkElement->getAttribute('data-category'));
43
                $data['link'] = $linkHref;
44
                $data['word'] = $linkSpan->innertext;
45
                $data['extra_data'] = $dataCategory;
46
                $suggestions[$i]['data'][] = $data;
47
            }
48
        }
49
        return $suggestions;
50
    }
51
52
}
53