ChecksToken   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkToken() 0 20 4
A checkTokenURL() 0 4 1
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