EnablerExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A beforeCallActionHandler() 0 11 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\Core\Extension;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Core\Extension 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 controlled 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 including 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` and `ping` will have the new theme set applied.
19
 */
20
class EnablerExtension extends Extension
21
{
22
    /**
23
     * @var array themes to use for log in page and related actions.
24
     * @config
25
     */
26
    private static $login_themes = [];
0 ignored issues
show
introduced by
The private property $login_themes is not used, and could be removed.
Loading history...
27
28
    /**
29
     * Aids in preventing themes from being overridden in the case of delegating handlers
30
     * e.g. if an extension adds a route that should not be styled by login-forms, this config
31
     * setting can be used to prevent the otherwise blanket override applying to all actions.
32
     * @var array {@see Security} actions that should not have the custom themes applied
33
     * @config
34
     */
35
    private static $excluded_actions = [
0 ignored issues
show
introduced by
The private property $excluded_actions is not used, and could be removed.
Loading history...
36
        'index',
37
        'ping',
38
    ];
39
40
    public function beforeCallActionHandler()
41
    {
42
        $config = Config::inst();
43
        /** @var Security $owner */
44
        $owner = $this->getOwner();
45
        $action = $owner->getAction();
46
        $allowedActions = $config->get(Security::class, 'allowed_actions');
47
        $excludedActions = $config->get(self::class, 'excluded_actions');
48
        $themeActions = array_diff($allowedActions, $excludedActions);
49
        if (in_array($action, $themeActions)) {
50
            SSViewer::set_themes($config->get(self::class, 'login_themes'));
51
        }
52
    }
53
}
54