Synonyms   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 65
Duplicated Lines 27.69 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 14
c 2
b 0
f 2
lcom 1
cbo 3
dl 18
loc 65
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getWords() 0 3 1
A getFormatted() 0 12 4
A getGoogleSuggestions() 0 3 1
A getThesaurus() 6 6 2
A getBighugelabs() 6 6 2
A getTurkishSynonyms() 6 6 2
A getWordnik() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Hasantayyar\Synonyms;
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 Synonyms {
16
17
    private $url;
18
    private $word;
19
    private $words;
20
    public $suggestions = array();
21
22
    public function __construct($word) {
23
        $this->word = $word;
24
    }
25
26
    public function getWords() {
27
        return $this->words;
28
    }
29
30
    public function getFormatted() {
31
        if (!is_array($this->words)) {
32
            return FALSE;
33
        }
34
        $formattedString = '';
35
        foreach ($this->words as $level) {
36
            foreach ($level['data'] as $item) {
37
                $formattedString.= $item['word'] . "\n";
38
            }
39
        }
40
        return $formattedString;
41
    }
42
43
    /**
44
     * get and get Thesaurus.com data
45
     */
46 View Code Duplication
    public function getThesaurus($word = NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
        $word = !$word ? $this->word : $word;
48
        $service = new Services\Thesaurus();
49
        $this->words = $service->getWords($word);
50
        return $this;
51
    }
52
53 View Code Duplication
    public function getBighugelabs($word = NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
        $word = !$word ? $this->word : $word;
55
        $service = new Services\Bighugelabs();
56
        $this->words = $service->getWords($word);
57
        return $this;
58
    }
59
60 View Code Duplication
    public function getTurkishSynonyms($word = NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
        $word = !$word ? $this->word : $word;
62
        $service = new Services\TurkishSynonyms();
63
        $this->words = $service->getWords($word);
64
        return $this;
65
    }
66
67
    public function getWordnik($word = NULL) {
0 ignored issues
show
Unused Code introduced by
The parameter $word is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
        //https://www.wordnik.com/fragments/tags/test
69
        return NULL;
70
    }
71
72
    /**
73
     * @todo get google suggestions
74
     */
75
    public function getGoogleSuggestions($word = NULL) {
0 ignored issues
show
Unused Code introduced by
The parameter $word is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
        return NULL;
77
    }
78
79
}
80