addAction accesses the super-global variable $_POST. Open
public function addAction()
{
$this->requireAdminPrivileges();
$this->disableLayout();
$this->disableView();
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
addAction accesses the super-global variable $_POST. Open
public function addAction()
{
$this->requireAdminPrivileges();
$this->disableLayout();
$this->disableView();
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Method addAction
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addAction()
{
$this->requireAdminPrivileges();
$this->disableLayout();
$this->disableView();
- Create a ticketCreate a ticket
Method editAction
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function editAction()
{
$this->requireAdminPrivileges();
$this->disableLayout();
$this->disableView();
- Create a ticketCreate a ticket
Function editAction
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function editAction()
{
$this->requireAdminPrivileges();
$this->disableLayout();
$this->disableView();
- Read upRead up
- Create a ticketCreate a ticket
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 addAction
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function addAction()
{
$this->requireAdminPrivileges();
$this->disableLayout();
$this->disableView();
- Read upRead up
- Create a ticketCreate a ticket
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 too many return
statements within this method. Open
return false;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return true;
- Create a ticketCreate a ticket
Missing class import via use statement (line '226', column '23'). Open
throw new Zend_Exception('Must provide srcAssetstoreId and dstAssetstoreId parameters');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '137', column '34'). Open
$assetstoreDao = new AssetstoreDao();
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '235', column '23'). Open
throw new Zend_Exception('Invalid srcAssetstoreId or dstAssetstoreId');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '198', column '23'). Open
throw new Zend_Exception('Must provide srcAssetstoreId parameter');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '204', column '23'). Open
throw new Zend_Exception('Invalid srcAssetstoreId');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class 'JsonComponent' in method 'editAction'. Open
echo JsonComponent::encode(array(false, $ze->getMessage()));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'defaultassetstoreAction'. Open
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'addAction'. Open
echo JsonComponent::encode(array('error' => $ze->getMessage()));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'addAction'. Open
echo JsonComponent::encode(array('error' => 'The path provided is not a valid directory'));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'deleteAction'. Open
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'deleteAction'. Open
echo JsonComponent::encode(array(false, $this->t('Error')));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'editAction'. Open
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'defaultassetstoreAction'. Open
echo JsonComponent::encode(array(false, $this->t('Error')));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'UtilityComponent' in method 'addAction'. Open
$totalSpace = UtilityComponent::diskTotalSpace($assetstoreDao->getPath());
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'editAction'. Open
echo JsonComponent::encode(array(false, 'The path provided is not a valid directory'));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'addAction'. Open
echo JsonComponent::encode(
array(
'msg' => 'The assetstore has been added.',
'assetstore_id' => $assetstoreDao->getAssetstoreId(),
'assetstore_name' => $assetstoreDao->getName(),
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'editAction'. Open
echo JsonComponent::encode(array(false, 'The specified directory is not writable'));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'editAction'. Open
echo JsonComponent::encode(array(false, $this->t('Error')));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'addAction'. Open
echo JsonComponent::encode(array('error' => 'The specified directory is not writable'));
- Read upRead up
- Create a ticketCreate a ticket
- 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 'UtilityComponent' in method 'addAction'. Open
$freeSpace = UtilityComponent::diskFreeSpace($assetstoreDao->getPath());
- Read upRead up
- Create a ticketCreate a ticket
- 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 'JsonComponent' in method 'movecontentsAction'. Open
echo JsonComponent::encode(array('status' => 'ok', 'message' => 'Bitstreams moved'));
- Read upRead up
- Create a ticketCreate a ticket
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class AssetstoreController extends AppController
- Create a ticketCreate a ticket
- Exclude checks
The property $_components is not named in camelCase. Open
class AssetstoreController extends AppController
{
public $_models = array('Assetstore', 'Bitstream', 'Progress', 'Setting');
public $_daos = array('Assetstore');
public $_components = array('Utility');
- Read upRead up
- Create a ticketCreate a ticket
- 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 $_daos is not named in camelCase. Open
class AssetstoreController extends AppController
{
public $_models = array('Assetstore', 'Bitstream', 'Progress', 'Setting');
public $_daos = array('Assetstore');
public $_components = array('Utility');
- Read upRead up
- Create a ticketCreate a ticket
- 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 $_models is not named in camelCase. Open
class AssetstoreController extends AppController
{
public $_models = array('Assetstore', 'Bitstream', 'Progress', 'Setting');
public $_daos = array('Assetstore');
public $_components = array('Utility');
- Read upRead up
- Create a ticketCreate a ticket
- 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 $_forms is not named in camelCase. Open
class AssetstoreController extends AppController
{
public $_models = array('Assetstore', 'Bitstream', 'Progress', 'Setting');
public $_daos = array('Assetstore');
public $_components = array('Utility');
- Read upRead up
- Create a ticketCreate a ticket
- 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
Property name "$_forms" should not be prefixed with an underscore to indicate visibility Open
public $_forms = array('Assetstore');
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_components" should not be prefixed with an underscore to indicate visibility Open
public $_components = array('Utility');
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_models" should not be prefixed with an underscore to indicate visibility Open
public $_models = array('Assetstore', 'Bitstream', 'Progress', 'Setting');
- Create a ticketCreate a ticket
- Exclude checks
Property name "$_daos" should not be prefixed with an underscore to indicate visibility Open
public $_daos = array('Assetstore');
- Create a ticketCreate a ticket
- Exclude checks