Completed
Pull Request — master (#32)
by
unknown
02:59
created

Blackout   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isHandling() 0 4 1
A lolify() 0 6 1
A forgotHalfSentence() 0 12 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 5
    public function lolify(array $record)
17
    {
18 5
        $record['message'] = $this->forgotHalfSentence($record['message']);
19
20 5
        return $record;
21
    }
22
23 5
    private function forgotHalfSentence($message)
24
    {
25 5
        $nbWords = str_word_count($message);
26
27 5
        if($nbWords > 1)
28 5
        {
29 4
            $posHalfSentence = floor(strlen($message) / 2);
30 4
            $message = substr($message, 0, strpos($message, ' ', $posHalfSentence)) . self::MESSAGE;
31 4
        }
32
33 5
        return $message;
34
    }
35
}
36