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']);
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']);
- Read upRead up
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;
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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>';
- Read upRead up
- Exclude checks
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']) .
- Read upRead up
- Exclude checks
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>';
- Read upRead up
- Exclude checks
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');
- Read upRead up
- Exclude checks
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') .
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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>'
- Read upRead up
- Exclude checks
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>';
- Read upRead up
- Exclude checks
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);
- Exclude checks
Call to method dumpAsString
from undeclared class \yii\helpers\VarDumper
Open
$errorsText .= PHP_EOL . " {$key} = " . \yii\helpers\VarDumper::dumpAsString($value['val']) .
- Exclude checks
Reference to undeclared property \App\SystemWarnings\Security\SecurityConf->linkTitle
Open
$this->linkTitle = \App\Language::translate('LBL_CONFIG_REPORT_LINK', 'Settings:SystemWarnings');
- Exclude checks
Call to method getErrors
from undeclared class \App\Utils\ConfReport
(Did you mean class \Tests\Settings\ConfReport) Open
$errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');
- Exclude checks
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') .
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $errorsWritableFilesAndFolders. Keep variable name length under 20. Open
$errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');
- Read upRead up
- Exclude checks
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} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsSecurity = \App\Utils\ConfReport::getErrors('security', true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsText = '<br>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
' (' . \App\Language::translate('LBL_RECOMMENDED_VALUE', 'Settings:SystemWarnings') .
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsText .= '</pre>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->link = 'https://doc.yetiforce.com/introduction/requirements/';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->linkTitle = \App\Language::translate('LBL_CONFIG_REPORT_LINK', 'Settings:SystemWarnings');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
) . $errorsText;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $priority = 7;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($errorsWritableFilesAndFolders)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->description = \App\Language::translateArgs(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $title = 'LBL_SECURITY_CONF';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
": '" . ($value['recommended'] ?? '') . "')";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->status = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($errorsSecurity as $key => $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
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>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->status) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($errorsSecurity['HTTPS']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsText .= '</pre><hr/>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsText .= '<h5>' . \App\Language::translate('LBL_SECURITY', 'Settings:SystemWarnings') . ':</h5><pre>';
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$errorsText .= '<h5>' . \App\Language::translate('LBL_NO_FILE_WRITE_RIGHTS', 'Settings:SystemWarnings') . ':</h5><pre>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsText .= PHP_EOL . " {$key}";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'LBL_SECURITY_CONF_DESC',
- Exclude checks
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>'
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsText .= PHP_EOL . " {$key} = " . \yii\helpers\VarDumper::dumpAsString($value['val']) .
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($errorsSecurity)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$errorsWritableFilesAndFolders = \App\Utils\ConfReport::getErrors('writableFilesAndFolders');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->status = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'Settings:SystemWarnings',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Checking whether there is a security configuration issue.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->status = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($errorsWritableFilesAndFolders as $key => $value) {
- Exclude checks
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>'
- Exclude checks