Quote::getRandomQuote()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2
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