The method save has a boolean flag argument $commit, which is a certain sign of a Single Responsibility Principle violation. Open
function save($commit = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '22', column '37'). Open
$this->fields['file'] = new Pluf_Form_Field_File(array(
- Read upRead up
- 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 'Pluf' in method 'initFields'. Open
'max_size' => Pluf::f('upload_max_size', 2097152),
- 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
Add curly braces around the nested statement(s). Open
if (empty($name))
- Read upRead up
- Exclude checks
While not technically incorrect, the omission of curly braces can be misleading, and may lead to the introduction of errors during maintenance.
Noncompliant Code Example
if (condition) // Noncompliant executeSomething();
Compliant Solution
if (condition) { executeSomething(); }
See
- MISRA C:2004, 14.8 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
- MISRA C:2004, 14.9 - An if (expression) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
- MISRA C++:2008, 6-3-1 - The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement
- MISRA C++:2008, 6-4-1 - An if (condition) construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement, or another if statement
- MISRA C:2012, 15.6 - The body of an iteration-statement or a selection-statement shall be a compound-statement
- CERT, EXP19-C. - Use braces for the body of an if, for, or while statement
- CERT, EXP52-J. - Use braces for the body of an if, for, or while statement
Reference to undeclared class \Pluf_Form_Model
Open
$model = parent::save(false);
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->model
Open
$this->model->_a['cols']['lesson']['blank'] = true;
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Form_Field_File
Open
$this->fields['file'] = new Pluf_Form_Field_File(array(
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->model
Open
'file_name' => $this->model->id,
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->cleaned_data
Open
if (array_key_exists('file', $this->cleaned_data)) {
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->fields
Open
$this->fields['file'] = new Pluf_Form_Field_File(array(
- Exclude checks
Reference to undeclared class \Pluf_Form_Model
Open
parent::initFields($extra);
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->model
Open
'upload_path' => $this->model->file_path,
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->data
Open
$myFile = $this->data['file'];
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->cleaned_data
Open
$name = $this->cleaned_data['name'];
- Exclude checks
Class extends undeclared class \Pluf_Form_Model
Open
class ELearn_Form_PartUpdate extends Pluf_Form_Model
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->model
Open
$this->model = $extra['model'];
- Exclude checks
Call to method f
from undeclared class \Pluf
Open
'max_size' => Pluf::f('upload_max_size', 2097152),
- Exclude checks
Reference to undeclared property \ELearn_Form_PartUpdate->model
Open
if (strcmp($name, $this->model->name) === 0) {
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class ELearn_Form_PartUpdate extends Pluf_Form_Model
- Exclude checks
The class ELearn_Form_PartUpdate is not named in CamelCase. Open
class ELearn_Form_PartUpdate extends Pluf_Form_Model
{
public function initFields($extra = array())
{
- 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
Visibility must be declared on method "save" Open
function save($commit = true)
- Exclude checks
Method name "ELearn_Form_PartUpdate::clean_name" is not in camel caps format Open
public function clean_name()
- Exclude checks
Inline control structures are not allowed Open
if (empty($name))
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
* با استفاده از این فرم میتوان اطلاعات یک محتوا را به روزرسانی کرد.
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Class name "ELearn_Form_PartUpdate" is not in camel caps format Open
class ELearn_Form_PartUpdate extends Pluf_Form_Model
- Exclude checks
The method clean_name is not named in camelCase. Open
public function clean_name()
{
$name = $this->cleaned_data['name'];
if (empty($name))
return null;
- 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() {
}
}