Completed
Push — master ( 5e0312...0c80f2 )
by Davide
10:12 queued 05:07
created

QuoteFactory::setCookie()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace DavideCasiraghi\PhpResponsiveRandomQuote;
4
5
use DavideCasiraghi\PhpResponsiveRandomQuote\Models\Quote;
6
7
class QuoteFactory
8
{
9
    /***************************************************************************/
10
    
11
    /**
12
     * Return a random quote
13
     *
14
     * @return \DavideCasiraghi\PhpResponsiveRandomQuote\Models\Quote
15
     */
16 1
    public function getRandomQuote()
17
    {
18 1
        return Quote::inRandomOrder()->first();
19
    }
20
    
21
    /***************************************************************************/
22
    
23
    /**
24
     * Return the quote of the day 
25
     *
26
     * @return \DavideCasiraghi\PhpResponsiveRandomQuote\Models\Quote
27
     */
28
    public function getQuoteOfTheDay()
29
    {
30
        $numberOfQuotesInDB = Quote::count();
31
        $quoteOfTheDayNumber = rand(1,$numberOfQuotesInDB);
0 ignored issues
show
Bug introduced by
It seems like $numberOfQuotesInDB can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $max of rand() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $quoteOfTheDayNumber = rand(1,/** @scrutinizer ignore-type */ $numberOfQuotesInDB);
Loading history...
32
        
33
        $quotes = Quote::all();
34
        
35
        return  $quotes[$quoteOfTheDayNumber];
36
    }
37
    
38
    
39
    
40
    public function setCookie(Request $request){
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    public function setCookie(/** @scrutinizer ignore-unused */ Request $request){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Bug introduced by
The type DavideCasiraghi\PhpResponsiveRandomQuote\Request was not found. Did you mean Request? If so, make sure to prefix the type with \.
Loading history...
41
        $minutes = 60;
42
        $response = new Response('Set Cookie');
0 ignored issues
show
Bug introduced by
The type DavideCasiraghi\PhpResponsiveRandomQuote\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
43
        $response->withCookie(cookie('quoteOfTheDayId', 'MyValue', $minutes));
44
    return $response;
45
    }
46
47
    public function getCookie(Request $request){
48
        $value = $request->cookie('quoteOfTheDayId');
49
        echo $value;
50
    }
51
}
52