ChecksToken::checkToken()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 5
nop 1
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Acacha\ForgePublish\Commands\Traits;
4
5
/**
6
 * Trait ChecksToken.
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait ChecksToken
11
{
12
    /**
13
     * Check token.
14
     *
15
     * @param $token
16
     * @return bool
17
     */
18
    protected function checkToken($token)
19
    {
20
        try {
21
            $response = $this->http->get($this->checkTokenURL(), [
0 ignored issues
show
Bug introduced by
The property http does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
                'headers' => [
23
                    'X-Requested-With' => 'XMLHttpRequest',
24
                    'Authorization' => 'Bearer ' . $token
25
                ]
26
            ]);
27
            $content = json_decode($response->getBody()->getContents());
28
            if (isset($content->message)) {
29
                if ($content->message === 'Token is valid') {
30
                    return true;
31
                }
32
            }
33
        } catch (\Exception $e) {
34
            return false;
35
        }
36
        return false;
37
    }
38
39
    /**
40
     * Get api url endpoint.
41
     */
42
    protected function checkTokenURL()
43
    {
44
        return config('forge-publish.url') . config('forge-publish.get_check_token_uri');
45
    }
46
}
47