Completed
Push — develop ( 0e11fc...a4838f )
by Abdelrahman
19:20 queued 02:35
created

OAuth::actingAsClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\OAuth;
6
7
class OAuth
8
{
9
    /**
10
     * Get all of the defined scope IDs.
11
     *
12
     * @return array
13
     */
14
    public static function scopeIds()
15
    {
16
        return static::scopes()->pluck('id')->values()->all();
17
    }
18
19
    /**
20
     * Determine if the given scope has been defined.
21
     *
22
     * @param string $id
23
     *
24
     * @return bool
25
     */
26
    public static function hasScope($id)
27
    {
28
        return $id === '*' || array_key_exists($id, config('rinvex.oauth.scopes'));
29
    }
30
31
    /**
32
     * Get all of the scopes defined for the application.
33
     *
34
     * @return \Illuminate\Support\Collection
35
     */
36
    public static function scopes()
37
    {
38
        return collect(config('rinvex.oauth.scopes'))->map(function ($description, $id) {
39
            return new Scope($id, $description);
40
        })->values();
41
    }
42
43
    /**
44
     * Get all of the scopes matching the given IDs.
45
     *
46
     * @param array $ids
47
     *
48
     * @return array
49
     */
50
    public static function scopesFor(array $ids)
51
    {
52
        return collect($ids)->map(function ($id) {
53
            if (isset(config('rinvex.oauth.scopes')[$id])) {
54
                return new Scope($id, config('rinvex.oauth.scopes')[$id]);
55
            }
56
        })->filter()->values()->all();
57
    }
58
59
    /**
60
     * The location of the encryption keys.
61
     *
62
     * @param string $file
63
     *
64
     * @return string
65
     */
66
    public static function keyPath($file)
67
    {
68
        $file = ltrim($file, '/\\');
69
70
        return config('rinvex.oauth.key_path')
71
            ? rtrim(config('rinvex.oauth.key_path'), '/\\').DIRECTORY_SEPARATOR.$file
72
            : storage_path($file);
73
    }
74
}
75