1 | <?php |
||
2 | |||
3 | namespace App\Service\Paypal; |
||
4 | |||
5 | use PayPal\Api\OpenIdUserinfo; |
||
6 | use Psr\Log\LoggerInterface; |
||
7 | use Symfony\Component\HttpFoundation\Session\Session; |
||
8 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
||
9 | |||
10 | /** |
||
11 | * Class SessionService |
||
12 | * @package App\Service\PayPal |
||
13 | */ |
||
14 | class SessionService |
||
15 | { |
||
16 | /** |
||
17 | * @var Session |
||
18 | */ |
||
19 | public $session; |
||
20 | |||
21 | /** |
||
22 | * @var LoggerInterface |
||
23 | */ |
||
24 | private $logger; |
||
25 | |||
26 | /** |
||
27 | * SessionService constructor. |
||
28 | * @param SessionInterface $session |
||
29 | * @param LoggerInterface $logger |
||
30 | */ |
||
31 | public function __construct(SessionInterface $session, LoggerInterface $logger) |
||
32 | { |
||
33 | $this->session = $session; |
||
0 ignored issues
–
show
|
|||
34 | $this->logger = $logger; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return bool |
||
39 | */ |
||
40 | public function isActive(): bool |
||
41 | { |
||
42 | if (is_array($this->session->get('paypal'))) { |
||
43 | return true; |
||
44 | } |
||
45 | return false; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param OpenIdUserinfo $userinfo |
||
50 | * @param string $refreshToken |
||
51 | */ |
||
52 | public function login(OpenIdUserinfo $userinfo, string $refreshToken): void |
||
53 | { |
||
54 | $paypalUser = [ |
||
55 | 'email' => $userinfo->getEmail(), |
||
56 | 'name' => $userinfo->getName(), |
||
57 | 'userId' => $userinfo->getUserId(), |
||
58 | 'address_street' => $userinfo->getAddress()->getStreetAddress(), |
||
59 | 'address_locality' => $userinfo->getAddress()->getLocality(), |
||
60 | 'address_region' => $userinfo->getAddress()->getRegion(), |
||
61 | 'address_post_code' => $userinfo->getAddress()->getPostalCode(), |
||
62 | 'address_country' => $userinfo->getAddress()->getCountry(), |
||
63 | 'refresh-token' => $refreshToken, |
||
64 | ]; |
||
65 | $this->session->set('paypal', $paypalUser); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * LogOut from Connect with PayPal |
||
70 | */ |
||
71 | public function logout(): void |
||
72 | { |
||
73 | $this->session->remove('paypal'); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return string|null |
||
78 | */ |
||
79 | public function getRefreshToken(): ?string |
||
80 | { |
||
81 | return $this->session->get('paypal')['refresh-token']; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param string $clientId |
||
86 | * @param string $clientSecret |
||
87 | */ |
||
88 | public function updateCredentials(?string $clientId, ?string $clientSecret, ?string $extra): void |
||
89 | { |
||
90 | if ($clientId) { |
||
91 | $this->session->set('PAYPAL_SDK_CLIENT_ID', $clientId); |
||
92 | } |
||
93 | if ($clientSecret) { |
||
94 | $this->session->set('PAYPAL_SDK_CLIENT_SECRET', $clientSecret); |
||
95 | } |
||
96 | if ($extra) { |
||
97 | $this->session->set('PAYPAL_SDK_EXTRA', $extra); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Remove PayPal SandBox credentials |
||
103 | */ |
||
104 | public function removeCredentials(): void |
||
105 | { |
||
106 | $this->session->remove('PAYPAL_SDK_CLIENT_ID'); |
||
107 | $this->session->remove('PAYPAL_SDK_CLIENT_SECRET'); |
||
108 | $this->session->remove('PAYPAL_SDK_EXTRA'); |
||
109 | } |
||
110 | } |
||
111 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.