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

CwpCanonicalURLMiddleware::isEnabled()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
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