Showing 35 of 43 total issues
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($this->isAssociative()){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
} catch (ValidationException $e){
- Exclude checks
Expected 1 newline at end of file; 0 found Open
*/
- Exclude checks
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks
Whitespace found at end of line Open
* Array of attributes that must be observed for changes. These
- Exclude checks
Remove the unused function parameter "$schema". Open
public static function createDTO($schema, array $args = []): object
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Remove this commented out code. Open
// use PhpSchema\Models\SchemaModel;
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Move arguments "$street_2" after arguments without default value Open
public function __construct(string $street_1, string $street_2 = null, string $city, string $state, string $zipcode)
- Read upRead up
- Exclude checks
The ability to define default values for method arguments can make a method easier to use. Default argument values allow callers to specify as many or as few arguments as they want while getting the same functionality and minimizing boilerplate, wrapper code.
But all method arguments with default values should be declared after the method arguments without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values in order to "get to" the non-default arguments.
Noncompliant Code Example
function makeyogurt($type = "acidophilus", $flavor){...} // Noncompliant makeyogurt("raspberry")}} // Runtime error: Missing argument 2 in call to makeyogurt()
Compliant Solution
function makeyogurt($flavor, $type = "acidophilus", ){...} makeyogurt("raspberry")}} // Works as expected
Remove the unused function parameter "$args". Open
public static function createDTO($schema, array $args = []): object
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Remove the unused function parameter "$method". Open
protected function isGetterMethod(string $method): bool
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Add curly braces around the nested statement(s). Open
if (array() === $this->container) return false;
- 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
Remove the unused function parameter "$method". Open
protected function isSetterMethod(string $method): bool
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Move arguments "$input" after arguments without default value Open
public function __construct($input = [], Observable $subscriber)
- Read upRead up
- Exclude checks
The ability to define default values for method arguments can make a method easier to use. Default argument values allow callers to specify as many or as few arguments as they want while getting the same functionality and minimizing boilerplate, wrapper code.
But all method arguments with default values should be declared after the method arguments without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values in order to "get to" the non-default arguments.
Noncompliant Code Example
function makeyogurt($type = "acidophilus", $flavor){...} // Noncompliant makeyogurt("raspberry")}} // Runtime error: Missing argument 2 in call to makeyogurt()
Compliant Solution
function makeyogurt($flavor, $type = "acidophilus", ){...} makeyogurt("raspberry")}} // Works as expected