Skip to content

Commit c8e48d8

Browse files
committed
MQE-590: Fix PHP Mess Detector Errors
- First batch, mostly @SupressWarnings due to PHPMD hating singletons, and classes that we already have stories for refactoring. - TestGenerator was edited somewhat to actually fix the issues, no huge refactoring though.
1 parent 9123be8 commit c8e48d8

File tree

18 files changed

+61
-41
lines changed

18 files changed

+61
-41
lines changed

dev/tests/static/Magento/CodeMessDetector/ruleset.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
</rule>
2727

2828
<!-- Unused code rules -->
29-
<rule ref="rulesets/unusedcode.xml" />
29+
<rule ref="rulesets/unusedcode.xml" >
30+
<properties>
31+
<property name="allow-unused-foreach-variables" value="true"/>
32+
</properties>
33+
</rule>
3034

3135
<!-- Code design rules -->
3236
<rule ref="rulesets/design.xml/ExitExpression" />

src/Magento/FunctionalTestingFramework/Config/Converter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function convert($source)
8282
*
8383
* @param \DOMNodeList|array $elements
8484
* @return array
85+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8586
*/
8687
protected function convertXml($elements)
8788
{

src/Magento/FunctionalTestingFramework/Config/Dom.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function merge($xml)
114114
* @param string $parentPath path to parent node
115115
* @return void
116116
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
117+
* @SuppressWarnings(PHPMD.NPathComplexity)
117118
*/
118119
protected function mergeNode(\DOMElement $node, $parentPath)
119120
{

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/DataObjectHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function getAllObjects()
109109
* Method to initialize parsing of data.xml and read into objects.
110110
*
111111
* @return void
112+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
112113
*/
113114
private function initDataObjects()
114115
{

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ public function getOperationDefinition($operation, $dataType)
122122
/**
123123
* This method reads all dataDefinitions from metadata xml into memory.
124124
* @return void
125+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
126+
* @SuppressWarnings(PHPMD.NPathComplexity)
127+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
125128
*/
126129
private function initDataDefinitions()
127130
{
131+
//TODO: Reduce CyclomaticComplexity/NPathComplexity of method, remove warning suppression.
128132
$objectManager = ObjectManagerFactory::getObjectManager();
129133
$metadataParser = $objectManager->create(OperationDefinitionParser::class);
130134
foreach ($metadataParser->readOperationMetadata()

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getType()
107107
*
108108
* @return bool
109109
*/
110-
public function getRequired()
110+
public function isRequired()
111111
{
112112
return $this->required;
113113
}

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/OperationDataArrayResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
7373
foreach ($operationMetadata as $operationElement) {
7474
if ($operationElement->getType() == OperationElementExtractor::OPERATION_OBJECT_OBJ_NAME) {
7575
$entityObj = $this->resolveOperationObjectAndEntityData($entityObject, $operationElement->getValue());
76-
if (null === $entityObj && $operationElement->getRequired()) {
76+
if (null === $entityObj && $operationElement->isRequired()) {
7777
throw new \Exception(sprintf(
7878
self::EXCEPTION_REQUIRED_DATA,
7979
$operationElement->getType(),
@@ -123,7 +123,7 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
123123
$elementData
124124
);
125125

126-
} elseif ($operationElement->getRequired()) {
126+
} elseif ($operationElement->isRequired()) {
127127
throw new \Exception(sprintf(
128128
self::EXCEPTION_REQUIRED_DATA,
129129
$operationElement->getType(),
@@ -135,7 +135,7 @@ public function resolveOperationDataArray($entityObject, $operationMetadata, $op
135135
$entityNamesOfType = $entityObject->getLinkedEntitiesOfType($operationElementType);
136136

137137
// If an element is required by metadata, but was not provided in the entity, throw an exception
138-
if ($operationElement->getRequired() && $entityNamesOfType == null) {
138+
if ($operationElement->isRequired() && $entityNamesOfType == null) {
139139
throw new \Exception(sprintf(
140140
self::EXCEPTION_REQUIRED_DATA,
141141
$operationElement->getType(),

src/Magento/FunctionalTestingFramework/Helper/AdminUrlList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/**
1010
* Class AdminUrlList
11+
* @SuppressWarnings(PHPMD)
1112
*/
1213
// @codingStandardsIgnoreFile
1314
class AdminUrlList

src/Magento/FunctionalTestingFramework/Helper/EntityRESTApiHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EntityRESTApiHelper
3939
public function __construct($host, $port)
4040
{
4141
$this->guzzle_client = new Client([
42-
'base_uri' => "http://${host}:${port}",
42+
'base_uri' => "http://{$host}:{$port}",
4343
'timeout' => 5.0,
4444
]);
4545
}

src/Magento/FunctionalTestingFramework/Helper/MagentoFakerData.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getCustomerData(array $additional = [])
2727
'lastname' => $faker->lastName,
2828
'suffix' => \Faker\Provider\en_US\Person::suffix(),
2929
'email' => $faker->email,
30-
'dateOfBirth' => $faker->date($format = 'm/d/Y', $max = 'now'),
30+
'dateOfBirth' => $faker->date('m/d/Y', 'now'),
3131
'gender' => rand(0, 1),
3232
'group_id' => 1,
3333
'store_id' => 1,
@@ -61,38 +61,36 @@ public function getCategoryData()
6161
'includeInMenu' => $faker->boolean(),
6262
'categoryName' => $faker->md5,
6363
'categoryImage' => '',
64-
'description' => $faker->sentence($nbWords = 10, $variableNbWords = true),
64+
'description' => $faker->sentence(10, true),
6565
'addCMSBlock' => '',
6666

6767
'urlKey' => $faker->uuid,
6868
'metaTitle' => $faker->word,
69-
'metaKeywords' => $faker->sentence($nbWords = 5, $variableNbWords = true),
70-
'metaDescription' => $faker->sentence($nbWords = 10, $variableNbWords = true),
69+
'metaKeywords' => $faker->sentence(5, true),
70+
'metaDescription' => $faker->sentence(10, true),
7171
];
7272
}
7373

7474
/**
7575
* Get simple product data.
7676
*
77-
* @param integer $categoryId
78-
* @param array $productData
7977
* @return array
8078
*/
81-
public function getProductData($categoryId = 0, $productData = [])
79+
public function getProductData()
8280
{
8381
$faker = \Faker\Factory::create();
8482
return [
8583
'enableProduct' => $faker->boolean(),
8684
'attributeSet' => '',
87-
'productName' => $faker->text($maxNbChars = 20),
88-
'sku' => \Faker\Provider\DateTime::unixTime($max = 'now'),
89-
'price' => $faker->randomFloat($nbMaxDecimals = 2, $min = 0, $max = 999),
90-
'quantity' => $faker->numberBetween($min = 1, $max = 999),
85+
'productName' => $faker->text(20),
86+
'sku' => \Faker\Provider\DateTime::unixTime('now'),
87+
'price' => $faker->randomFloat(2, 0, 999),
88+
'quantity' => $faker->numberBetween(1, 999),
9189

9290
'urlKey' => $faker->uuid,
9391
'metaTitle' => $faker->word,
94-
'metaKeywords' => $faker->sentence($nbWords = 5, $variableNbWords = true),
95-
'metaDescription' => $faker->sentence($nbWords = 10, $variableNbWords = true)
92+
'metaKeywords' => $faker->sentence(5, true),
93+
'metaDescription' => $faker->sentence(10, true)
9694
];
9795
}
9896

@@ -106,14 +104,14 @@ public function getContentPage()
106104
$faker = \Faker\Factory::create();
107105

108106
$pageContent = [
109-
'pageTitle' => $faker->sentence($nbWords = 3, $variableNbWords = true),
110-
'contentHeading' => $faker->sentence($nbWords = 3, $variableNbWords = true),
111-
'contentBody' => $faker->sentence($nbWords = 10, $variableNbWords = true),
107+
'pageTitle' => $faker->sentence(3, true),
108+
'contentHeading' => $faker->sentence(3, true),
109+
'contentBody' => $faker->sentence(10, true),
112110
'urlKey' => $faker->uuid,
113111
'metaTitle' => $faker->word,
114-
'metaKeywords' => $faker->sentence($nbWords = 5, $variableNbWords = true),
115-
'metaDescription' => $faker->sentence($nbWords = 10, $variableNbWords = true),
116-
'from' => $faker->date($format = 'm/d/Y', $max = 'now'),
112+
'metaKeywords' => $faker->sentence(5, true),
113+
'metaDescription' => $faker->sentence(10, true),
114+
'from' => $faker->date($format = 'm/d/Y', 'now'),
117115
'to' => $faker->date($format = 'm/d/Y')
118116
];
119117
$pageContent['layoutUpdateXml'] = "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading>";

0 commit comments

Comments
 (0)