1 | <?php |
||||
2 | /** |
||||
3 | * Socializer plugin for Craft CMS 3.x |
||||
4 | * |
||||
5 | * @link https://enupal.com/ |
||||
6 | * @copyright Copyright (c) 2019 Enupal LLC |
||||
7 | */ |
||||
8 | |||||
9 | namespace enupal\socializer\services; |
||||
10 | |||||
11 | use Craft; |
||||
12 | use craft\elements\User; |
||||
13 | use enupal\socializer\elements\Provider; |
||||
14 | use enupal\socializer\elements\Token; |
||||
15 | use enupal\socializer\Socializer; |
||||
16 | use yii\base\Component; |
||||
17 | |||||
18 | class Tokens extends Component |
||||
19 | { |
||||
20 | /** |
||||
21 | * @param int $providerId |
||||
22 | * @param int $userId |
||||
23 | * @return array|\craft\base\ElementInterface|null |
||||
0 ignored issues
–
show
|
|||||
24 | */ |
||||
25 | public function getToken(int $providerId, int $userId) |
||||
26 | { |
||||
27 | $query = Token::find(); |
||||
28 | $query->providerId = $providerId; |
||||
29 | $query->userId = $userId; |
||||
30 | |||||
31 | return $query->one(); |
||||
32 | } |
||||
33 | |||||
34 | /** |
||||
35 | * @param User $user |
||||
36 | * @param Provider $provider |
||||
37 | * @return bool |
||||
38 | * @throws \Throwable |
||||
39 | * @throws \craft\errors\ElementNotFoundException |
||||
40 | * @throws \yii\base\Exception |
||||
41 | */ |
||||
42 | public function registerToken(User $user, Provider $provider) |
||||
43 | { |
||||
44 | $adapter = $provider->getAdapter(); |
||||
45 | $token = Socializer::$app->tokens->getToken($provider->id, $user->id); |
||||
46 | |||||
47 | if (is_null($token)){ |
||||
48 | $token = new Token(); |
||||
49 | $token->providerId = $provider->id; |
||||
50 | $token->userId = $user->id; |
||||
51 | } |
||||
52 | |||||
53 | $token->accessToken = $adapter->getAccessToken(); |
||||
0 ignored issues
–
show
It seems like
$adapter->getAccessToken() of type array is incompatible with the declared type string of property $accessToken .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||||
54 | |||||
55 | if (!Craft::$app->elements->saveElement($token)) { |
||||
0 ignored issues
–
show
The method
saveElement() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
56 | Craft::error("Unable to save token: ".json_encode($token->getErrors()), __METHOD__); |
||||
57 | return false; |
||||
58 | } |
||||
59 | |||||
60 | return true; |
||||
61 | } |
||||
62 | |||||
63 | /** |
||||
64 | * @param int $providerId |
||||
65 | * @return array|\craft\base\ElementInterface|null |
||||
66 | */ |
||||
67 | public function getCurrentUserToken(int $providerId) |
||||
68 | { |
||||
69 | $user = Craft::$app->getUser()->getIdentity(); |
||||
70 | |||||
71 | if ($user){ |
||||
0 ignored issues
–
show
|
|||||
72 | /** @var Token $token */ |
||||
73 | $token = $this->getToken($providerId, $user->id); |
||||
0 ignored issues
–
show
|
|||||
74 | if ($token){ |
||||
0 ignored issues
–
show
|
|||||
75 | return $token->accessToken; |
||||
0 ignored issues
–
show
|
|||||
76 | } |
||||
77 | } |
||||
78 | |||||
79 | return null; |
||||
80 | } |
||||
81 | } |
||||
82 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths