FlightDeck   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 10 1
A checkToken() 0 11 2
1
<?php
2
3
namespace Yab\FlightDeck;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Facades\DB;
7
8
class FlightDeck
9
{
10
    /**
11
     * Generate an authorization token
12
     *
13
     * @param string $name
14
     * @param string $expires_at
15
     * @param integer $length
16
     * @return string
17
     */
18
    public static function generate(string $name, string $expires_at = null, int $length = 60) : string
19
    {
20
        $token = Str::random($length);
21
        DB::table('api_tokens')->insert([
22
            'name' => $name,
23
            'token' => $token,
24
            'expires_at' => $expires_at ?? now()->addDays(config('flightdeck.tokens.expire_days')),
25
        ]);
26
        return $token;
27
    }
28
29
    /**
30
     * Check if the token is valid
31
     *
32
     * @param string $token
0 ignored issues
show
Bug introduced by
There is no parameter named $token. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
     * @return boolean
34
     */
35
    public static function checkToken(string $api_token = null) : bool
36
    {
37
        $token = DB::table('api_tokens')
38
                    ->where('token', $api_token)
39
                    ->where('expires_at', '>', now()->toDateTimeString())
40
                    ->first();
41
        if ($token) {
42
            return true;
43
        }
44
        return false;
45
    }
46
}
47