1 | <?php |
||
10 | class Finder |
||
11 | { |
||
12 | /** |
||
13 | * @var string Needle |
||
14 | */ |
||
15 | protected $needle; |
||
16 | |||
17 | /** |
||
18 | * @var array Haystack |
||
19 | */ |
||
20 | protected $haystack; |
||
21 | |||
22 | /** |
||
23 | * Hold the sorted comparison stack. |
||
24 | * |
||
25 | * @var array Haystack |
||
26 | */ |
||
27 | protected $sorted_haystack; |
||
28 | |||
29 | /** |
||
30 | * @var null|int Threshold |
||
31 | */ |
||
32 | protected $threshold; |
||
33 | |||
34 | /** |
||
35 | * Finder constructor. |
||
36 | * |
||
37 | * @param string $needle |
||
38 | * @param array $haystack |
||
39 | * @return void |
||
|
|||
40 | */ |
||
41 | 15 | public function __construct($needle, $haystack) |
|
46 | |||
47 | /** |
||
48 | * Sort Haystack. |
||
49 | * |
||
50 | * @return void |
||
51 | */ |
||
52 | 9 | protected function sortHaystack() |
|
70 | |||
71 | /** |
||
72 | * Apply threshold to filter only relevant results. The higher |
||
73 | * the threshold the more results there will be returned. |
||
74 | * |
||
75 | * @param int|null $threshold |
||
76 | * @return Finder |
||
77 | */ |
||
78 | 3 | public function threshold($threshold = null) |
|
84 | |||
85 | /** |
||
86 | * Return the highest match. |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | 6 | public function first() |
|
96 | |||
97 | /** |
||
98 | * Return all strings in sorted match order. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | 6 | public function all() |
|
107 | |||
108 | /** |
||
109 | * Return whether there is an exact match. |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | 6 | public function hasExactMatch() |
|
117 | |||
118 | /** |
||
119 | * Ensure a string only uses ascii characters. |
||
120 | * |
||
121 | * @param string $str |
||
122 | * @param array $map |
||
123 | * @return string |
||
124 | */ |
||
125 | 9 | protected function utf8ToExtendedAscii($str, &$map) |
|
143 | |||
144 | /** |
||
145 | * Calculate the levenshtein distance between two strings. |
||
146 | * |
||
147 | * @param string $string1 |
||
148 | * @param string $string2 |
||
149 | * @return int |
||
150 | */ |
||
151 | 9 | protected function levenshteinUtf8($string1, $string2) |
|
159 | } |
||
160 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.