1 | <?php |
||
7 | class Tourette implements Lolifier |
||
8 | { |
||
9 | private |
||
10 | $swearWordsProvider; |
||
|
|||
11 | |||
12 | 5 | public function __construct(SwearWordsProvider $swearWordsProvider) |
|
16 | |||
17 | 1 | public function isHandling(array $record) |
|
21 | |||
22 | 4 | public function lolify(array $record) |
|
23 | { |
||
24 | 4 | $messageArray = explode(' ', $record['message']); |
|
25 | 4 | $badWords = $this->swearWordsProvider->getSwearWords(); |
|
26 | |||
27 | 4 | $iterations = rand(1, 3); |
|
28 | 4 | for($i = 0; $i < $iterations; $i++) |
|
29 | { |
||
30 | 4 | $badWord = $this->chooseBadWordRandomly($badWords); |
|
31 | 4 | $this->insertSwearWordIntoMessage($messageArray, $badWord); |
|
32 | 4 | } |
|
33 | |||
34 | 4 | $record['message'] = implode(' ', $messageArray); |
|
35 | |||
36 | 4 | return $record; |
|
37 | } |
||
38 | |||
39 | 4 | private function chooseBadWordRandomly(array $badWords) |
|
40 | { |
||
41 | 4 | $index = array_rand($badWords); |
|
42 | |||
43 | 4 | return $badWords[$index]; |
|
44 | } |
||
45 | |||
46 | 4 | private function insertSwearWordIntoMessage(array &$messageArray, $badWord) |
|
50 | } |
||
51 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.