Quote::lolify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Monolol\Lolifiers;
4
5
use Monolol\Lolifier;
6
use Monolol\Lolifiers\QuoteProvider;
7
8
class Quote implements Lolifier
9
{
10
    private
11
        $provider;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $provider.

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...
12
13 6
    public function __construct(QuoteProvider $provider)
14
    {
15 6
        $this->provider = $provider;
16 6
    }
17
18 1
    public function isHandling(array $record)
19
    {
20 1
        return true;
21
    }
22
23 5
    public function lolify(array $record)
24
    {
25 5
        $quote = $this->getRandomQuote();
26
27 5
        $record['message'] = $quote;
28
29 5
        return $record;
30
    }
31
32 5
    private function getRandomQuote()
33
    {
34 5
        $quotes = $this->provider->getQuotes();
35
36 5
        if(empty($quotes))
37 5
        {
38 1
            return null;
39
        }
40
41 4
        return $quotes[array_rand($quotes)];
42
    }
43
}
44