Blackout   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 31
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isHandling() 0 4 1
A lolify() 0 6 1
A forgotHalfSentence() 0 14 2
1
<?php
2
3
namespace Monolol\Lolifiers;
4
5
use Monolol\Lolifier;
6
7
class Blackout implements Lolifier
8
{
9
    const MESSAGE = '... ummm ... wait ... what were we talking about again ?';
10
11 1
    public function isHandling(array $record)
12
    {
13 1
        return true;
14
    }
15
16 8
    public function lolify(array $record)
17
    {
18 8
        $record['message'] = $this->forgotHalfSentence($record['message']);
19
20 8
        return $record;
21
    }
22
23 8
    private function forgotHalfSentence($message)
24
    {
25 8
        $nbWords = str_word_count($message);
26
27 8
        if($nbWords > 1)
28 8
        {
29 7
            $posHalfSentence = floor(strlen($message) / 2) + 1;
30 7
            $cut = substr($message, 0, $posHalfSentence);
31 7
            $cut = strrev(strpbrk(strrev($cut), " \t\n\r\0\x0B"));
32 7
            $message = $cut . self::MESSAGE;
33 7
        }
34
35 8
        return $message;
36
    }
37
}
38