Tourette   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 44
ccs 21
cts 21
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isHandling() 0 4 1
A insertSwearWordIntoMessage() 0 4 1
A lolify() 0 16 2
A chooseBadWordRandomly() 0 6 1
1
<?php
2
3
namespace Monolol\Lolifiers;
4
5
use Monolol\Lolifier;
6
7
class Tourette implements Lolifier
8
{
9
    private
10
        $swearWordsProvider;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $swearWordsProvider.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
    
12 5
    public function __construct(SwearWordsProvider $swearWordsProvider)
13
    {
14 5
        $this->swearWordsProvider = $swearWordsProvider;
15 5
    }
16
    
17 1
    public function isHandling(array $record)
18
    {
19 1
        return true;
20
    }
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)
47
    {
48 4
        array_splice($messageArray, rand(0, count($messageArray)), 0, $badWord);
49 4
    }
50
}
51