Bighugelabs::getWords()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
rs 9.4285
cc 3
eloc 15
nc 3
nop 1
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 Bighugelabs {
16
17
    /**
18
     *
19
     * @var string
20
     */
21
    public $base_url = 'http://words.bighugelabs.com/';
22
23
    /**
24
     * 
25
     * @return array
26
     */
27
    public function getWords($word) {
28
        $suggestions = array();
29
        $html = new Htmldom($this->base_url . $word);
30
        $list = $html->find('ul[class=words]', 0);
31
        $suggestions[0]['data'] = array();
32
        if(!$list){
33
            return FALSE;
34
        }
35
        foreach ($list->find('li') as $element) {
36
            $data = array();
37
            $linkElement = $element->find('a', 0);
38
            $linkHref = $linkElement->href;
39
            $data['link'] = $linkHref;
40
            $data['word'] = $linkElement->innertext;
41
            $suggestions[0]['data'][] = $data;
42
        }
43
        return $suggestions;
44
    }
45
46
}
47