Completed
Push — master ( 3d6026...8dfc9c )
by Guy
12s queued 10s
created

BaseHandlerTrait::getSudoModeService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\MFA\RequestHandler;
4
5
use SilverStripe\Core\Injector\Injector;
6
use SilverStripe\MFA\Service\MethodRegistry;
7
use SilverStripe\MFA\Store\StoreInterface;
8
use SilverStripe\Security\Member;
9
use SilverStripe\SecurityExtensions\Service\SudoModeServiceInterface;
0 ignored issues
show
Bug introduced by
The type SilverStripe\SecurityExt...udoModeServiceInterface 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 SilverStripe\View\Requirements;
11
12
trait BaseHandlerTrait
13
{
14
    /**
15
     * A "session store" object that helps contain MFA specific session detail
16
     *
17
     * @var StoreInterface
18
     */
19
    protected $store;
20
21
    /**
22
     * Perform the necessary "Requirements" calls to ensure client side scripts are available in the response
23
     *
24
     * @param bool $frontEndRequirements Indicates dependencies usually provided by admin should also be required
25
     */
26
    protected function applyRequirements(bool $frontEndRequirements = true): void
27
    {
28
        // Run through requirements
29
        if ($frontEndRequirements) {
30
            Requirements::javascript('silverstripe/mfa: client/dist/js/injector.js');
31
            Requirements::javascript('silverstripe/admin: client/dist/js/i18n.js');
32
        }
33
34
        Requirements::add_i18n_javascript('silverstripe/mfa: client/lang');
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\View\Requir...::add_i18n_javascript() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

34
        /** @scrutinizer ignore-deprecated */ Requirements::add_i18n_javascript('silverstripe/mfa: client/lang');
Loading history...
35
36
        $suffix = $frontEndRequirements ? '' : '-cms';
37
        Requirements::javascript("silverstripe/mfa: client/dist/js/bundle{$suffix}.js");
38
        Requirements::css("silverstripe/mfa: client/dist/styles/bundle{$suffix}.css");
39
40
        // Plugin module requirements
41
        foreach (MethodRegistry::singleton()->getMethods() as $method) {
42
            $method->applyRequirements();
43
        }
44
    }
45
46
    /**
47
     * @return StoreInterface|null
48
     */
49
    protected function getStore(): ?StoreInterface
50
    {
51
        if (!$this->store) {
52
            $spec = Injector::inst()->getServiceSpec(StoreInterface::class);
53
            $class = is_string($spec) ? $spec : $spec['class'];
54
            $this->store = call_user_func([$class, 'load'], $this->getRequest());
0 ignored issues
show
Bug introduced by
It seems like getRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            $this->store = call_user_func([$class, 'load'], $this->/** @scrutinizer ignore-call */ getRequest());
Loading history...
55
        }
56
57
        return $this->store;
58
    }
59
60
    /**
61
     * @param StoreInterface $store
62
     * @return $this
63
     */
64
    public function setStore(StoreInterface $store): self
65
    {
66
        $this->store = $store;
67
        return $this;
68
    }
69
70
    /**
71
     * @param Member $member
72
     * @return StoreInterface
73
     */
74
    protected function createStore(Member $member): StoreInterface
75
    {
76
        $store = Injector::inst()->create(StoreInterface::class, $member);
77
        // Ensure use of the getter returns the new store
78
        $this->store = $store;
79
        return $store;
80
    }
81
82
    /**
83
     * Returns a sudo mode service instance
84
     *
85
     * @return SudoModeServiceInterface
86
     */
87
    protected function getSudoModeService(): SudoModeServiceInterface
88
    {
89
        return Injector::inst()->get(SudoModeServiceInterface::class);
90
    }
91
}
92