Total Complexity | 12 |
Total Lines | 165 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | class LipsumDetector |
||
20 | { |
||
21 | private static array $words = array( |
||
22 | 'exercitationem', |
||
23 | 'reprehenderit', |
||
24 | 'perspiciatis', |
||
25 | 'exercitation', |
||
26 | 'consequuntur', |
||
27 | 'accusantium', |
||
28 | 'consectetur', |
||
29 | 'consequatur', |
||
30 | 'laudantium', |
||
31 | 'incididunt', |
||
32 | 'doloremque', |
||
33 | 'laboriosam', |
||
34 | 'voluptatem', |
||
35 | 'adipiscing', |
||
36 | 'aspernatur', |
||
37 | 'architecto', |
||
38 | 'cupidatat', |
||
39 | 'inventore', |
||
40 | 'explicabo', |
||
41 | 'Excepteur', |
||
42 | 'molestiae', |
||
43 | 'voluptate', |
||
44 | 'veritatis', |
||
45 | 'consequat', |
||
46 | 'proident', |
||
47 | 'adipisci', |
||
48 | 'incidunt', |
||
49 | 'deserunt', |
||
50 | 'quisquam', |
||
51 | 'nesciunt', |
||
52 | 'voluptas', |
||
53 | 'suscipit', |
||
54 | 'occaecat', |
||
55 | 'corporis', |
||
56 | 'pariatur', |
||
57 | 'aliquam', |
||
58 | 'laborum', |
||
59 | 'laboris', |
||
60 | 'numquam', |
||
61 | 'nostrum', |
||
62 | 'nostrud', |
||
63 | 'aliquid', |
||
64 | 'quaerat', |
||
65 | 'aperiam', |
||
66 | 'eiusmod', |
||
67 | 'dolores', |
||
68 | 'dolorem', |
||
69 | 'ullamco', |
||
70 | 'aliquip', |
||
71 | 'aliqua', |
||
72 | 'veniam', |
||
73 | 'cillum', |
||
74 | 'labore', |
||
75 | 'mollit', |
||
76 | 'beatae', |
||
77 | 'fugiat', |
||
78 | 'totam', |
||
79 | 'ullam', |
||
80 | 'velit', |
||
81 | 'dolor', |
||
82 | 'dicta', |
||
83 | 'culpa', |
||
84 | 'vitae', |
||
85 | 'autem', |
||
86 | 'sequi', |
||
87 | 'natus', |
||
88 | 'fugit', |
||
89 | 'Neque', |
||
90 | 'quasi', |
||
91 | 'ipsam', |
||
92 | 'ipsum', |
||
93 | 'porro', |
||
94 | 'irure', |
||
95 | 'Lorem', |
||
96 | 'magna', |
||
97 | 'magni', |
||
98 | 'minim', |
||
99 | 'nihil', |
||
100 | 'illum', |
||
101 | 'dolor', |
||
102 | 'sit', |
||
103 | 'amet', |
||
104 | 'elit' |
||
105 | ); |
||
106 | |||
107 | private int $minWords = 2; |
||
108 | private string $subject; |
||
109 | private bool $detected = false; |
||
110 | private int $count = 0; |
||
111 | |||
112 | /** |
||
113 | * @var string[] |
||
114 | */ |
||
115 | private array $found = array(); |
||
116 | |||
117 | public function __construct(string $subject) |
||
120 | } |
||
121 | |||
122 | public function setMinWords(int $min) : self |
||
123 | { |
||
124 | // Avoid a reset if the value is the same |
||
125 | if($this->minWords === $min) |
||
126 | { |
||
127 | return $this; |
||
128 | } |
||
129 | |||
130 | $this->minWords = $min; |
||
131 | |||
132 | $this->reset(); |
||
133 | |||
134 | return $this; |
||
135 | } |
||
136 | |||
137 | private function reset() : void |
||
138 | { |
||
139 | $this->found = array(); |
||
140 | $this->detected = false; |
||
141 | } |
||
142 | |||
143 | private function detect() : void |
||
144 | { |
||
145 | if($this->detected) { |
||
146 | return; |
||
147 | } |
||
148 | |||
149 | $this->detected = true; |
||
150 | $this->found = array(); |
||
151 | $this->count = 0; |
||
152 | |||
153 | foreach(self::$words as $word) |
||
154 | { |
||
155 | if(stripos($this->subject, $word) !== false) |
||
156 | { |
||
157 | $this->count++; |
||
158 | $this->found[] = $word; |
||
159 | } |
||
160 | |||
161 | if($this->count >= $this->minWords) { |
||
162 | break; |
||
163 | } |
||
164 | } |
||
165 | } |
||
166 | |||
167 | public function isDetected() : bool |
||
170 | } |
||
171 | |||
172 | public function getDetectedWords() : array |
||
173 | { |
||
174 | $this->detect(); |
||
175 | |||
176 | return $this->found; |
||
177 | } |
||
178 | |||
179 | public function countDetectedWords() : int |
||
184 | } |
||
185 | } |
||
186 |