Sources::validateAppleUser()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 0
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Models;
6
7
use Phalcon\Di;
8
use Canvas\Exception\ModelException;
9
use Baka\ASDecoder;
0 ignored issues
show
Bug introduced by
The type Baka\ASDecoder 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...
10
use Canvas\Http\Exception\InternalServerErrorException;
11
12
13
/**
14
 * Class Resources
15
 *
16
 * @package Canvas\Models
17
 *
18
 * @property \Phalcon\Di $di
19
 */
20
class Sources extends AbstractModel
21
{
22
    /**
23
     *
24
     * @var integer
25
     */
26
    public $id;
27
28
    /**
29
     *
30
     * @var string
31
     */
32
    public $title;
33
34
    /**
35
     *
36
     * @var string
37
     */
38
    public $url;
39
40
    /**
41
     *
42
     * @var integer
43
     */
44
    public $language_id;
45
46
    /**
47
     *
48
     * @var string
49
     */
50
    public $created_at;
51
52
    /**
53
     *
54
     * @var string
55
     */
56
    public $updated_at;
57
58
    /**
59
     *
60
     * @var integer
61
     */
62
    public $is_deleted;
63
64
    /**
65
     * Initialize method for model.
66
     */
67
    public function initialize()
68
    {
69
        $this->setSource('sources');
70
    }
71
72
    /**
73
     * Returns table name mapped in the model.
74
     *
75
     * @return string
76
     */
77
    public function getSource(): string
78
    {
79
        return 'sources';
80
    }
81
82
    /**
83
     * Verify if source is Apple
84
     */
85
    public function isApple(): bool
86
    {
87
        return $this->title == 'apple';
88
    }
89
90
    /**
91
     * Validate Apple User.
92
     * @param string $identityToken
93
     * @return object
94
     */
95
    public function validateAppleUser(string $identityToken): object
96
    {
97
        $appleUserInfo = ASDecoder::getAppleSignInPayload($identityToken);
98
99
        if (!is_object($appleUserInfo)) {
100
            throw new InternalServerErrorException('Apple user not valid');
101
        }
102
103
        return $appleUserInfo;
104
    }
105
}
106