1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of gpupo/similarity |
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
6
|
|
|
* For the information of copyright and license you should read the file |
7
|
|
|
* LICENSE which is distributed with this source code. |
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
12
|
|
|
* For more information, see <https://www.gpupo.com/>. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Gpupo\Similarity; |
16
|
|
|
|
17
|
|
|
use Gpupo\Similarity\Input\InputNumber; |
18
|
|
|
use Gpupo\Similarity\Input\InputString; |
19
|
|
|
|
20
|
|
|
class Similarity extends SimilarityAbstract implements SimilarInterface |
21
|
|
|
{ |
22
|
|
|
const MODE_STRING = 'text'; |
23
|
|
|
|
24
|
|
|
const MODE_NUMBER = 'number'; |
25
|
|
|
|
26
|
|
|
protected $mode; |
27
|
|
|
|
28
|
|
|
protected $expert; |
29
|
|
|
|
30
|
41 |
|
protected function getMode() |
31
|
|
|
{ |
32
|
41 |
|
if ($this->mode === self::MODE_NUMBER) { |
33
|
21 |
|
return self::MODE_NUMBER; |
34
|
|
|
} |
35
|
|
|
|
36
|
20 |
|
return self::MODE_STRING; |
37
|
|
|
} |
38
|
|
|
|
39
|
41 |
|
public function setMode($mode) |
40
|
|
|
{ |
41
|
41 |
|
$this->mode = $mode; |
42
|
41 |
|
$this->expert = null; |
43
|
|
|
|
44
|
41 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
20 |
View Code Duplication |
public function setValues($a, $b) |
|
|
|
|
48
|
|
|
{ |
49
|
20 |
|
$input = new InputString($a, $b); |
50
|
20 |
|
$this->input = $input; |
51
|
|
|
|
52
|
20 |
|
$this->setMode(self::MODE_STRING); |
53
|
|
|
|
54
|
20 |
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
public function setStopwords(array $list) |
58
|
|
|
{ |
59
|
2 |
|
$this->getInput()->setStopwords($list); |
60
|
|
|
|
61
|
2 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
21 |
View Code Duplication |
public function setNumberValues($a, $b) |
|
|
|
|
65
|
|
|
{ |
66
|
21 |
|
$input = new InputNumber($a, $b); |
67
|
21 |
|
$this->input = $input; |
68
|
|
|
|
69
|
21 |
|
$this->setMode(self::MODE_NUMBER); |
70
|
|
|
|
71
|
21 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
41 |
|
protected function getExpert() |
75
|
|
|
{ |
76
|
41 |
|
if (!$this->expert) { |
77
|
41 |
|
$this->expert = $this->factoryExpert($this->getMode()); |
78
|
|
|
} |
79
|
|
|
|
80
|
41 |
|
return $this->expert; |
81
|
|
|
} |
82
|
|
|
|
83
|
41 |
|
public function hasSimilarity() |
84
|
|
|
{ |
85
|
41 |
|
return $this->getExpert()->hasSimilarity(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function __toArray() |
89
|
|
|
{ |
90
|
|
|
return $this->getExpert()->__toArray(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
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.