Showing 93 of 93 total issues
Avoid unused parameters such as '$value'. Open
public function setName($type, $value)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid unused parameters such as '$data'. Open
protected function fetchSpouses(PersonaInterface $persona, \ArrayAccess $data, $options)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Avoid assigning values to variables in if clauses and the like (line '319', column '13'). Open
protected function fetchParents(PersonaInterface $persona, \ArrayAccess $data, $options)
{
if ($fatherId = $data['father_id']) {
$father = $this->getPersonaById($fatherId, $options);
$persona->setFather($father);
- 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 '323', column '13'). Open
protected function fetchParents(PersonaInterface $persona, \ArrayAccess $data, $options)
{
if ($fatherId = $data['father_id']) {
$father = $this->getPersonaById($fatherId, $options);
$persona->setFather($father);
- 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 save uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$row = $this->getRowGatewayInstance();
$row->populate($rowData, true);
$row->save();
$rowData = $row->toArray();
- 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
The method isValidSpouse() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function isValidSpouse(PersonaInterface $persona, PersonaInterface $spouse)
{
$errors = [];
if ($persona === $spouse) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method getPersonaById() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function getPersonaById($id, $fetchWithOptions = self::WITHOUT_KINSHIP)
{
$options = $fetchWithOptions;
if ($this->identityMap->has($id)) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method save() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function save(PersonaInterface $persona)
{
/*
* TODO extract to method?
* save parents before
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Line exceeds 120 characters; contains 230 characters Open
public function createPersona($gender = self::GENDER_UNDEFINED, array $names = [], PersonaInterface $father = null, PersonaInterface $mother = null, DateTimeInterface $dateOfBirth = null, DateTimeInterface $dateOfDeath = null)
- Exclude checks
End of line character is invalid; expected "\n" but found "\r\n" Open
<?php
- Exclude checks
Line exceeds 120 characters; contains 206 characters Open
public function createPersona($gender, array $names = [], PersonaInterface $father = null, PersonaInterface $mother = null, DateTimeInterface $dateOfBirth = null, DateTimeInterface $dateOfDeath = null);
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
if (($mother->hasDateOfBirth() && $persona->hasDateOfBirth()) && (int) $mother->getDateOfBirth('Y') >= (int) $persona->getDateOfBirth('Y')) {
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
} elseif ($gender !== self::GENDER_MALE && $gender !== self::GENDER_FEMALE && $gender !== self::GENDER_UNDEFINED) {
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
public function __construct($gender = self::GENDER_UNDEFINED, array $names = [], Persona $father = null, Persona $mother = null)
- Exclude checks
Line exceeds 120 characters; contains 154 characters Open
throw new InvalidArgumentException("Invalid gender value: {$gender}, possible values: ".self::MALE.', '.self::FEMALE.' or NULL if undefined');
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
if ($father->hasDateOfBirth() && $persona->hasDateOfBirth() && $father->getDateOfBirth('Y') >= $persona->getDateOfBirth('Y')) {
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks