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

ShopifyAdminUserProvider::setDevStore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace CodeCloud\Bundle\ShopifyBundle\Security;
4
5
use CodeCloud\Bundle\ShopifyBundle\Model\ShopifyStoreManagerInterface;
6
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...ernameNotFoundException 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
use Symfony\Component\Security\Core\User\UserInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\User\UserInterface 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...
8
use Symfony\Component\Security\Core\User\UserProviderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...r\UserProviderInterface 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...
9
10
class ShopifyAdminUserProvider implements UserProviderInterface
11
{
12
    const ROLE_SHOPIFY_ADMIN = 'ROLE_SHOPIFY_ADMIN';
13
14
    /**
15
     * @var ShopifyStoreManagerInterface
16
     */
17
    private $storeManager;
18
19
    /**
20
     * @var string
21
     */
22
    private $devStore;
23
24
    public function __construct(ShopifyStoreManagerInterface $storeManager)
25
    {
26
        $this->storeManager = $storeManager;
27
    }
28
29
    public function setDevStore(string $devStore)
30
    {
31
        $this->devStore = $devStore;
32
    }
33
34
    public function loadUserByUsername($sessionId)
35
    {
36
        $storeName = $this->devStore ?? $this->storeManager->findStoreNameBySession($sessionId);
37
38
        if (!$storeName) {
39
            throw new UsernameNotFoundException();
40
        }
41
42
        return new ShopifyAdminUser($storeName, [self::ROLE_SHOPIFY_ADMIN]);
43
    }
44
45
    public function refreshUser(UserInterface $user)
46
    {
47
        return $user;
48
    }
49
50
    public function supportsClass($class)
51
    {
52
        return is_a($class, ShopifyAdminUser::class, true);
53
    }
54
}
55