The method getDataCrm has a boolean flag argument $onEdit, which is a certain sign of a Single Responsibility Principle violation. Open
public function getDataCrm(bool $onEdit = false): array
- 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
Avoid assigning values to variables in if clauses and the like (line '44', column '14'). Open
public function getDataCrm(bool $onEdit = false): array
{
$parsedData = parent::getDataCrm($onEdit);
if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
$parsedData = \array_replace_recursive($parsedData, $shippingAddress);
- 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 '47', column '14'). Open
public function getDataCrm(bool $onEdit = false): array
{
$parsedData = parent::getDataCrm($onEdit);
if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
$parsedData = \array_replace_recursive($parsedData, $shippingAddress);
- 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
Define a constant instead of duplicating this literal "gender" 3 times. Open
'salutationtype' => 'gender',
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($billingAddress = $this->getAddressDataCrm('billing'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getDataCrm(bool $onEdit = false): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parsedData = $this->parsePhone('mobile', $parsedData);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->dataCrm = $parsedData;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $moduleName = 'Accounts';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $mappedFields = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parsedData = parent::getDataCrm($onEdit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static $additionalFieldsCrm = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parsedData = \array_replace_recursive($parsedData, $billingAddress);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'salutationtype' => 'gender',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'lastname' => 'lastname',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'birthday' => 'dob',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'email' => 'email',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($shippingAddress = $this->getAddressDataCrm('shipping'))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'firstname' => 'firstname',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'gender' => 'gender',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($parsedData['mobile'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 182 characters Open
* The file is part of the paid functionality. Using the file is allowed only after purchasing a subscription. File modification allowed only with the consent of the system producer.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($parsedData['phone'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parsedData = $this->parsePhone('phone', $parsedData);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'leadsource' => 'Magento',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parsedData = \array_replace_recursive($parsedData, $shippingAddress);
- Exclude checks