Function renderCompressedResources
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function renderCompressedResources(array $types = ['*'])
{
// Reset compressors
$this->_compressors = [];
$linkCode = [
- 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
Function addResource
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function addResource(Ajde_Resource $resource, $position = self::RESOURCE_POSITION_DEFAULT)
{
if ($position == self::RESOURCE_POSITION_TOP) {
$resource->setPosition(self::RESOURCE_POSITION_FIRST);
} else {
- 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
Function autoAddResources
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function autoAddResources(Ajde_Template $template)
{
$position = $template->getDefaultResourcePosition();
foreach ($this->getResourceTypes() as $resourceType) {
// default resource
- 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
The method renderCompressedResources uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$linkCode[$resource->getPosition()] .= $resource->getLinkCode().PHP_EOL;
}
- Read upRead up
- Exclude checks
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 'UserModel' in method 'setupExternalPageCache'. Open
if (!UserModel::getLoggedIn() && Ajde::app()->getRequest()->method() === 'get' && config('layout.cache.externalPageCache')) {
- 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 'Ajde_Resource_Local' in method 'autoAddResources'. Open
$actionResource = Ajde_Resource_Local::lazyCreate($resourceType, $template->getBase(),
$template->getAction(), $template->getFormat())
- 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 assigning values to variables in if clauses and the like (line '197', column '17'). Open
public function autoAddResources(Ajde_Template $template)
{
$position = $template->getDefaultResourcePosition();
foreach ($this->getResourceTypes() as $resourceType) {
// default resource
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method addResource uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$resource->setPosition($position);
}
- Read upRead up
- Exclude checks
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 'Ajde_Event' in method '__construct'. Open
Ajde_Event::register('Ajde_Application', 'onAfterDocumentRendered', [$this, 'setupExternalPageCache']);
- 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 'Ajde_Event' in method '__construct'. Open
Ajde_Event::register('Ajde_Template', 'beforeGetContents', [$this, 'autoAddResources']);
- 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 'Ajde_Resource_Local_Compressor' in method 'renderCompressedResources'. Open
Ajde_Resource_Local_Compressor::fromType($resource->getType());
- 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 assigning values to variables in if clauses and the like (line '211', column '17'). Open
public function autoAddResources(Ajde_Template $template)
{
$position = $template->getDefaultResourcePosition();
foreach ($this->getResourceTypes() as $resourceType) {
// default resource
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '204', column '17'). Open
public function autoAddResources(Ajde_Template $template)
{
$position = $template->getDefaultResourcePosition();
foreach ($this->getResourceTypes() as $resourceType) {
// default resource
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class 'Ajde_Resource_Local' in method 'autoAddResources'. Open
if ($defaultResource = Ajde_Resource_Local::lazyCreate($resourceType, $template->getBase(), 'default',
$template->getFormat())
- 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 'Ajde_Resource_Local' in method 'autoAddResources'. Open
$actionDefaultResource = Ajde_Resource_Local::lazyCreate($resourceType, $template->getBase(),
$this->_getTemplateActionDefault($template), $template->getFormat())
- 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
The method addResource uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->_resources[$position][] = $resource;
}
- Read upRead up
- Exclude checks
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
TODO found Open
// TODO: implement a way to override
- Exclude checks
TODO found Open
// TODO: another option, replace current resource
- Exclude checks
Avoid excessively long variable names like $actionDefaultResource. Keep variable name length under 20. Open
$actionDefaultResource = Ajde_Resource_Local::lazyCreate($resourceType, $template->getBase(),
- 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
The property $_meta is not named in camelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The class Ajde_Document_Format_Html is not named in CamelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The property $_contentType is not named in camelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_maxAge is not named in camelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_cacheControl is not named in camelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_compressors is not named in camelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The property $_resources is not named in camelCase. Open
class Ajde_Document_Format_Html extends Ajde_Document
{
const RESOURCE_POSITION_TOP = 0;
const RESOURCE_POSITION_FIRST = 1;
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The method _getTemplateActionDefault is not named in camelCase. Open
private function _getTemplateActionDefault(Ajde_Template $template)
{
$actionArray = explode('/', $template->getAction());
end($actionArray);
$actionArray[key($actionArray)] = 'default';
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}