Firesphere/silverstripe-csp-headers

View on GitHub

Showing 121 of 145 total issues

Avoid using static access to class '\SilverStripe\Control\Director' in method 'onBeforeWrite'.
Open

        if (!Director::is_site_url($this->File)) {
Severity: Minor
Found in src/Models/SRI.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

The method onBeforeWrite uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $folders = [
                Director::baseFolder(),
                Director::publicFolder(),
                Director::publicFolder() . '/resources',
Severity: Minor
Found in src/Models/SRI.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

The method insertHeadTags uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->customHeadTags[$uniquenessID] = $html;
        }
Severity: Minor
Found in src/View/CSPBackend.php by phpmd

ElseExpression

Since: 1.4.0

An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

Example

class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}

Source https://phpmd.org/rules/cleancode.html#elseexpression

Avoid using static access to class '\SilverStripe\View\HTML' in method 'getBaseHeadTags'.
Open

            $requirements[] = HTML::createTag(
                $type,
                $options,
                $content
            );
Severity: Minor
Found in src/Builders/BaseBuilder.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class 'Firesphere\CSPHeaders\Builders\BaseBuilder' in method 'buildTags'.
Open

        BaseBuilder::getNonce($htmlAttributes);
Severity: Minor
Found in src/Builders/CSSBuilder.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\Firesphere\CSPHeaders\Extensions\ControllerCSPExtension' in method 'buildTags'.
Open

        $cookieSet = $request ? ControllerCSPExtension::checkCookie($request) : false;
Severity: Minor
Found in src/Builders/JSBuilder.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\SilverStripe\Security\Permission' in method 'shouldUpdateSRI'.
Open

            (Permission::check('ADMIN', 'any') ||
Severity: Minor
Found in src/Builders/SRIBuilder.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\SilverStripe\Forms\CheckboxField' in method 'updateSettingsFields'.
Open

            CheckboxField::create('AllowCSSInline', _t(__CLASS__ . '.ALLOWCSSINLINE', 'Allow CSS inline')),
Severity: Minor
Found in src/Extensions/PageExtension.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid unused private fields such as '$belongs_many_many'.
Open

    private static $belongs_many_many = [
        'Pages' => Page::class
    ];
Severity: Minor
Found in src/Models/CSPDomain.php by phpmd

UnusedPrivateField

Since: 0.2

Detects when a private field is declared and/or assigned a value, but not used.

Example

class Something
{
    private static $FOO = 2; // Unused
    private $i = 5; // Unused
    private $j = 6;
    public function addOne()
    {
        return $this->j++;
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

Avoid using static access to class '\SilverStripe\Dev\Deprecation' in method 'includeInHTML'.
Open

            Deprecation::notice(
                '5.0',
                '$templateFile argument is deprecated. includeInHTML takes a sole $content parameter now.'
            );
Severity: Minor
Found in src/View/CSPBackend.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid unused private fields such as '$menu_title'.
Open

    private static $menu_title = 'SRI & CSP';
Severity: Minor
Found in src/Admins/SRIAdmin.php by phpmd

UnusedPrivateField

Since: 0.2

Detects when a private field is declared and/or assigned a value, but not used.

Example

class Something
{
    private static $FOO = 2; // Unused
    private $i = 5; // Unused
    private $j = 6;
    public function addOne()
    {
        return $this->j++;
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

Avoid using static access to class '\SilverStripe\Control\Controller' in method 'buildTags'.
Open

        $request = Controller::has_curr() ? Controller::curr()->getRequest() : null;
Severity: Minor
Found in src/Builders/JSBuilder.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

The method onBeforeInit() has an NPath complexity of 17280. The configured NPath complexity threshold is 200.
Open

    public function onBeforeInit()
    {
        if (self::$isTesting || !DB::is_active() || !ClassInfo::hasTable('Member') || Director::is_cli()) {
            return;
        }

NPathComplexity

Since: 0.1

The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

Example

class Foo {
    function bar() {
        // lots of complicated code
    }
}

Source https://phpmd.org/rules/codesize.html#npathcomplexity

Avoid unused private fields such as '$many_many'.
Open

    private static $many_many = [
        'CSPDomains' => CSPDomain::class
    ];
Severity: Minor
Found in src/Extensions/PageExtension.php by phpmd

UnusedPrivateField

Since: 0.2

Detects when a private field is declared and/or assigned a value, but not used.

Example

class Something
{
    private static $FOO = 2; // Unused
    private $i = 5; // Unused
    private $j = 6;
    public function addOne()
    {
        return $this->j++;
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

Avoid unused parameters such as '$member'.
Open

    public function canCreate($member = null, $context = array())
Severity: Minor
Found in src/Models/SRI.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid using static access to class '\Firesphere\CSPHeaders\Extensions\ControllerCSPExtension' in method 'buildTags'.
Open

        $cookieSet = $request ? ControllerCSPExtension::checkCookie($request) : false;
Severity: Minor
Found in src/Builders/CSSBuilder.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\SilverStripe\ORM\DB' in method 'onBeforeInit'.
Open

        if (self::$isTesting || !DB::is_active() || !ClassInfo::hasTable('Member') || Director::is_cli()) {

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\SilverStripe\Forms\Tab' in method 'updateSettingsFields'.
Open

        $fields->addFieldToTab('Root', Tab::create(
            'CSP',
            _t(__CLASS__ . '.CSP', 'Content Security Policies')
        ));
Severity: Minor
Found in src/Extensions/PageExtension.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid unused private fields such as '$table_name'.
Open

    private static $table_name = 'CSPDomain';
Severity: Minor
Found in src/Models/CSPDomain.php by phpmd

UnusedPrivateField

Since: 0.2

Detects when a private field is declared and/or assigned a value, but not used.

Example

class Something
{
    private static $FOO = 2; // Unused
    private $i = 5; // Unused
    private $j = 6;
    public function addOne()
    {
        return $this->j++;
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

Avoid unused private fields such as '$indexes'.
Open

    private static $indexes = [
        'Domain' => true
    ];
Severity: Minor
Found in src/Models/CSPDomain.php by phpmd

UnusedPrivateField

Since: 0.2

Detects when a private field is declared and/or assigned a value, but not used.

Example

class Something
{
    private static $FOO = 2; // Unused
    private $i = 5; // Unused
    private $j = 6;
    public function addOne()
    {
        return $this->j++;
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield

Severity
Category
Status
Source
Language