Passed
Pull Request — 2.0 (#36)
by
unknown
15:38
created

CwpCanonicalURLMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A isEnabled() 0 9 3
1
<?php
2
3
namespace CWP\Core\Control;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Control\Middleware\CanonicalURLMiddleware;
7
8
/**
9
 * @internal Used to override CanonicalURLMiddleware to prevent canonical URL causing a redirect on CLI unless
10
 * explicitly enabled. See https://github.com/silverstripe/silverstripe-framework/pull/8158
11
 * Note, it is very likely that this class will deprecated after CWP 2.0.
12
 */
13
class CwpCanonicalURLMiddleware extends CanonicalURLMiddleware
14
{
15
    protected function isEnabled()
16
    {
17
        $enabledEnvs = $this->getEnabledEnvs();
18
19
        // If CLI, EnabledEnvs must contain CLI
20
        if (Director::is_cli() && !in_array('cli', $enabledEnvs)) {
0 ignored issues
show
Bug introduced by
It seems like $enabledEnvs can also be of type boolean; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

20
        if (Director::is_cli() && !in_array('cli', /** @scrutinizer ignore-type */ $enabledEnvs)) {
Loading history...
21
            return false;
22
        }
23
        return parent::isEnabled();
24
    }
25
}
26