Passed
Pull Request — master (#12)
by
unknown
02:24
created

EnablerExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A beforeCallActionHandler() 0 12 2
1
<?php
2
3
namespace SilverStripe\LoginForms;
4
5
use SilverStripe\View\SSViewer;
0 ignored issues
show
Bug introduced by
The type SilverStripe\View\SSViewer 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...
6
use SilverStripe\ORM\DataExtension;
0 ignored issues
show
Bug introduced by
The type SilverStripe\ORM\DataExtension 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 SilverStripe\Security\Security;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Security\Security 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 SilverStripe\Core\Config\Config;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Core\Config\Config 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
/**
11
 * Applies to the {@see Security} controller in order to detect requests for actions related to
12
 * the log in process or other such credential management (such as the forgot password flow).
13
 * This is in order to replace the set {@see SSViewer} theme list with a conrolled set in order
14
 * to always show a consistent interface that relates more to the CMS than the website it is
15
 * loading on.
16
 * Particular actions can be set to be ignored by inlcuding them in the `excluded_actions` list
17
 * defined in yml _config for this class. By default all allowed actions on the Security controller
18
 * excepting `index`, `logout`, and `ping` will have the new theme set applied.
19
 */
20
class EnablerExtension extends DataExtension
21
{
22
    public function beforeCallActionHandler()
23
    {
24
        $config = Config::inst();
25
        /** @var Security */
26
        $owner = $this->owner;
27
        $action = $owner->getAction();
28
        $allowedActions = $config->get(Security::class, 'allowed_actions');
29
        $excludedActions = $config->get(self::class, 'excluded_actions');
30
        $themeActions = array_diff($allowedActions, $excludedActions);
31
        if (in_array($action, $themeActions)) 
32
        {
33
            SSViewer::set_themes($config->get(self::class, 'login_themes'));
34
        }
35
    }
36
}
37