Passed
Pull Request — master (#9)
by Daniel
02:06
created

JwtResolver   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveJwt() 0 14 1
A __construct() 0 4 1
1
<?php
2
3
namespace CodeCloud\Bundle\ShopifyBundle\Service;
4
5
use CodeCloud\Bundle\ShopifyBundle\Model\Session;
6
use Firebase\JWT\JWT;
0 ignored issues
show
Bug introduced by
The type Firebase\JWT\JWT 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...
7
8
class JwtResolver
9
{
10
    /**
11
     * @var string
12
     */
13
    private $apiKey;
14
15
    /**
16
     * @var string
17
     */
18
    private $sharedSecret;
19
20
    /**
21
     * @param string $apiKey
22
     * @param string $sharedSecret
23
     */
24
    public function __construct(string $apiKey, string $sharedSecret)
25
    {
26
        $this->apiKey = $apiKey;
27
        $this->sharedSecret = $sharedSecret;
28
    }
29
30
    public function resolveJwt(string $jwt): Session
31
    {
32
        $decoded = JWT::decode($jwt, $this->sharedSecret, ['HS256']);
33
34
        // todo https://shopify.dev/tutorials/authenticate-your-app-using-session-tokens#obtain-session-details-manually
35
36
//        dump($decoded);
37
//        die();
38
39
        $session = new Session();
40
        $session->sessionId = $decoded->sid;
41
        $session->storeName = str_replace("https://", "", $decoded->dest);
42
43
        return $session;
44
    }
45
}
46