YetiForceCompany/YetiForceCRM

View on GitHub
app/SystemWarnings/Security/SecurityConf.php

Summary

Maintainability
B
4 hrs
Test Coverage
B
84%

Method process has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(): void
    {
        $this->status = 1;
        $errorsSecurity = \App\Utils\ConfReport::getErrors('security', true);
        unset($errorsSecurity['HTTPS']);
Severity: Minor
Found in app/SystemWarnings/Security/SecurityConf.php - About 1 hr to fix

    Function process has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        public function process(): void
        {
            $this->status = 1;
            $errorsSecurity = \App\Utils\ConfReport::getErrors('security', true);
            unset($errorsSecurity['HTTPS']);
    Severity: Minor
    Found in app/SystemWarnings/Security/SecurityConf.php - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid using static access to class '\App\Language' in method 'process'.
    Open

                $this->description = \App\Language::translateArgs(
                    'LBL_SECURITY_CONF_DESC',
                    'Settings:SystemWarnings',
                    '<a target="_blank" rel="noreferrer noopener" href="https://doc.yetiforce.com/introduction/requirements/"><u>' . \App\Language::translate('LBL_CONFIG_DOC_URL_LABEL', 'Settings:SystemWarnings') . '</u></a>'
                ) . $errorsText;

    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 '\App\Language' in method 'process'.
    Open

                $this->linkTitle = \App\Language::translate('LBL_CONFIG_REPORT_LINK', 'Settings:SystemWarnings');

    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 '\App\Language' in method 'process'.
    Open

                $errorsText .= '<h5>' . \App\Language::translate('LBL_SECURITY', 'Settings:SystemWarnings') . ':</h5><pre>';

    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 '\yii\helpers\VarDumper' in method 'process'.
    Open

                    $errorsText .= PHP_EOL . "  {$key} = " . \yii\helpers\VarDumper::dumpAsString($value['val']) .

    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 '\App\Language' in method 'process'.
    Open

                $errorsText .= '<h5>' . \App\Language::translate('LBL_NO_FILE_WRITE_RIGHTS', 'Settings:SystemWarnings') . ':</h5><pre>';

    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 '\App\Utils\ConfReport' in method 'process'.
    Open

            $errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');

    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 '\App\Language' in method 'process'.
    Open

                        ' (' . \App\Language::translate('LBL_RECOMMENDED_VALUE', 'Settings:SystemWarnings') .

    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 '\App\Utils\ConfReport' in method 'process'.
    Open

            $errorsSecurity = \App\Utils\ConfReport::getErrors('security', true);

    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 '\App\Language' in method 'process'.
    Open

                    '<a target="_blank" rel="noreferrer noopener" href="https://doc.yetiforce.com/introduction/requirements/"><u>' . \App\Language::translate('LBL_CONFIG_DOC_URL_LABEL', 'Settings:SystemWarnings') . '</u></a>'

    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

    Define a constant instead of duplicating this literal "Settings:SystemWarnings" 6 times.
    Open

                $errorsText .= '<h5>' . \App\Language::translate('LBL_SECURITY', 'Settings:SystemWarnings') . ':</h5><pre>';

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Call to method getErrors from undeclared class \App\Utils\ConfReport (Did you mean class \Tests\Settings\ConfReport)
    Open

            $errorsSecurity = \App\Utils\ConfReport::getErrors('security', true);

    Call to method dumpAsString from undeclared class \yii\helpers\VarDumper
    Open

                    $errorsText .= PHP_EOL . "  {$key} = " . \yii\helpers\VarDumper::dumpAsString($value['val']) .

    Reference to undeclared property \App\SystemWarnings\Security\SecurityConf->linkTitle
    Open

                $this->linkTitle = \App\Language::translate('LBL_CONFIG_REPORT_LINK', 'Settings:SystemWarnings');

    Call to method getErrors from undeclared class \App\Utils\ConfReport (Did you mean class \Tests\Settings\ConfReport)
    Open

            $errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

            if (!empty($errorsSecurity)) {
                $errorsText .= '<h5>' . \App\Language::translate('LBL_SECURITY', 'Settings:SystemWarnings') . ':</h5><pre>';
                foreach ($errorsSecurity as $key => $value) {
                    $errorsText .= PHP_EOL . "  {$key} = " . \yii\helpers\VarDumper::dumpAsString($value['val']) .
                        ' (' . \App\Language::translate('LBL_RECOMMENDED_VALUE', 'Settings:SystemWarnings') .
    Severity: Major
    Found in app/SystemWarnings/Security/SecurityConf.php and 2 other locations - About 2 hrs to fix
    app/SystemWarnings/SystemRequirements/Configuration.php on lines 38..47
    app/SystemWarnings/SystemRequirements/Configuration.php on lines 49..58

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 129.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Avoid excessively long variable names like $errorsWritableFilesAndFolders. Keep variable name length under 20.
    Open

            $errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');

    LongVariable

    Since: 0.2

    Detects when a field, formal or local variable is declared with a long name.

    Example

    class Something {
        protected $reallyLongIntName = -3; // VIOLATION - Field
        public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
            $otherReallyLongName = -5; // VIOLATION - Local
            for ($interestingIntIndex = 0; // VIOLATION - For
                 $interestingIntIndex < 10;
                 $interestingIntIndex++ ) {
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#longvariable

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $errorsSecurity = \App\Utils\ConfReport::getErrors('security', true);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $errorsText = '<br>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        ' (' . \App\Language::translate('LBL_RECOMMENDED_VALUE', 'Settings:SystemWarnings') .

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $errorsText .= '</pre>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->link = 'https://doc.yetiforce.com/introduction/requirements/';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->linkTitle = \App\Language::translate('LBL_CONFIG_REPORT_LINK', 'Settings:SystemWarnings');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ) . $errorsText;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $priority = 7;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!empty($errorsWritableFilesAndFolders)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->description = \App\Language::translateArgs(

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $title = 'LBL_SECURITY_CONF';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        ": '" . ($value['recommended'] ?? '') . "')";

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->status = 1;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($errorsSecurity as $key => $value) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $errorsText .= '<h5>' . \App\Language::translate('LBL_NO_FILE_WRITE_RIGHTS', 'Settings:SystemWarnings') . ':</h5><pre>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!$this->status) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            unset($errorsSecurity['HTTPS']);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $errorsText .= '</pre><hr/>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $errorsText .= '<h5>' . \App\Language::translate('LBL_SECURITY', 'Settings:SystemWarnings') . ':</h5><pre>';

    Line exceeds 120 characters; contains 132 characters
    Open

                $errorsText .= '<h5>' . \App\Language::translate('LBL_NO_FILE_WRITE_RIGHTS', 'Settings:SystemWarnings') . ':</h5><pre>';

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $errorsText .= PHP_EOL . "  {$key}";

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'LBL_SECURITY_CONF_DESC',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    '<a target="_blank" rel="noreferrer noopener" href="https://doc.yetiforce.com/introduction/requirements/"><u>' . \App\Language::translate('LBL_CONFIG_DOC_URL_LABEL', 'Settings:SystemWarnings') . '</u></a>'

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $errorsText .= PHP_EOL . "  {$key} = " . \yii\helpers\VarDumper::dumpAsString($value['val']) .

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function process(): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!empty($errorsSecurity)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->status = 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    'Settings:SystemWarnings',

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Checking whether there is a security configuration issue.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $this->status = 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($errorsWritableFilesAndFolders as $key => $value) {

    Line exceeds 120 characters; contains 221 characters
    Open

                    '<a target="_blank" rel="noreferrer noopener" href="https://doc.yetiforce.com/introduction/requirements/"><u>' . \App\Language::translate('LBL_CONFIG_DOC_URL_LABEL', 'Settings:SystemWarnings') . '</u></a>'

    There are no issues that match your filters.

    Category
    Status