Completed
Push — master ( cf2713...aee5ae )
by Sherif
02:07
created

OauthClientService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A revoke() 0 8 1
A unRevoke() 0 4 1
A accessTokenExpiredOrRevoked() 0 4 1
A revokeAccessToken() 0 4 1
1
<?php namespace App\Modules\OauthClients\Services;
2
3
use App\Modules\Core\BaseClasses\BaseService;
4
use App\Modules\OauthClients\Repositories\OauthClientRepository;
5
6
class OauthClientService extends BaseService
7
{
8
    /**
9
     * Init new object.
10
     *
11
     * @param   OauthClientRepository $repo
12
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
13
     */
14
    public function __construct(OauthClientRepository $repo)
15
    {
16
        parent::__construct($repo);
17
    }
18
19
    /**
20
     * Revoke the given client.
21
     *
22
     * @param  integer  $clientId
23
     * @return void
24
     */
25
    public function revoke($clientId)
0 ignored issues
show
Unused Code introduced by
The parameter $clientId is not used and could be removed.

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

Loading history...
26
    {
27
        \DB::transaction(function () use ($data) {
0 ignored issues
show
Bug introduced by
The variable $data does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
28
            $client = $this->repo->find($clientId);
0 ignored issues
show
Bug introduced by
The variable $clientId does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
29
            $this->repo->revokeClientTokens($client);
30
            $this->repo->save(['id'=> $clientId, 'revoked' => true]);
31
        });
32
    }
33
34
    /**
35
     * UnRevoke the given client.
36
     *
37
     * @param  integer  $clientId
38
     * @return void
39
     */
40
    public function unRevoke($clientId)
41
    {
42
        $this->repo->save(['id'=> $clientId, 'revoked' => false]);
43
    }
44
45
    /**
46
     * Ensure access token hasn't expired or revoked.
47
     *
48
     * @param  string $accessToken
49
     * @return boolean
50
     */
51
    public function accessTokenExpiredOrRevoked($accessToken)
52
    {
53
        return $this->oauthClientRepository->accessTokenExpiredOrRevoked($accessToken);
0 ignored issues
show
Bug introduced by
The property oauthClientRepository 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...
54
    }
55
56
    /**
57
     * Revoke the given access token and all
58
     * associated refresh tokens.
59
     *
60
     * @param  oject $accessToken
61
     * @return void
62
     */
63
    public function revokeAccessToken($accessToken)
64
    {
65
        return $this->oauthClientRepository->revokeAccessToken($accessToken);
66
    }
67
}
68