Passed
Push — master ( e3ed84...3f53d8 )
by Dominic
02:49
created

TokenRepository::deleteState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
namespace tbclla\Revolut\Repositories;
4
5
use tbclla\Revolut\Auth\AccessToken;
6
use tbclla\Revolut\Auth\RefreshToken;
7
use tbclla\Revolut\Auth\State;
0 ignored issues
show
Bug introduced by
The type tbclla\Revolut\Auth\State was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class TokenRepository
10
{
11
	/**
12
	 * Get the latest active access token
13
	 *
14
	 * @return \tbclla\Revolut\Auth\AccessToken|null
15
	 */
16
	public function getAccessToken()
17
	{
18
		return AccessToken::active()->orderBy('id', 'desc')->first();
19
	}
20
21
	/**
22
	 * Get the latest refresh token
23
	 *
24
	 * @return \tbclla\Revolut\Auth\RefreshToken|null
25
	 */
26
	public function getRefreshToken()
27
	{
28
		return RefreshToken::orderBy('id', 'desc')->first();
29
	}
30
31
	/**
32
	 * Get the latest State
33
	 *
34
	 * @return null|\tbclla\Revolut\Auth\State
35
	 */
36
	public function getState()
37
	{
38
		return State::active()->orderBy('id', 'desc')->first();
39
	}
40
41
	/**
42
	 * Create a new access token
43
	 *
44
	 * @param string $value
45
	 * @return \tbclla\Revolut\Auth\AccessToken
46
	 */
47
	public function createAccessToken(string $value)
48
	{
49
		return AccessToken::create([
50
			'value' => $value
51
		]);
52
	}
53
54
	/**
55
	 * Create a new refresh token
56
	 *
57
	 * @param string $value
58
	 * @return \tbclla\Revolut\Auth\RefreshToken
59
	 */
60
	public function createRefreshToken(string $value)
61
	{
62
		return RefreshToken::create([
63
			'value' => $value
64
		]);
65
	}
66
67
	/**
68
	 * Create a new Oauth state token
69
	 *
70
	 * @param string $value
71
	 * @return \tbclla\Revolut\Auth\State
72
	 */
73
	public function createState(string $value)
74
	{
75
		return State::create([
76
			'value' => $value
77
		]);
78
	}
79
80
	/**
81
	 * Delete a state
82
	 *
83
	 * @param \tbclla\Revolut\Auth\State $state
84
	 * @return void
85
	 */
86
	public function deleteState(State $state)
87
	{
88
		$state->delete();
89
	}
90
}
91