Skip to content

Commit fa96ab1

Browse files
committed
MQE-610: [PHPMD] Reduce Cyclomatic Complexity in Problem Methods
Refactored to keep Cyclomatic complexity <= 10. Added comments to functions that are not refactored for readability
1 parent 15668f2 commit fa96ab1

File tree

6 files changed

+43
-26
lines changed

6 files changed

+43
-26
lines changed

src/Magento/FunctionalTestingFramework/Config/Converter/Dom/Flat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected function getNodeAttributes(\DOMNode $node)
7070
* @return string|array
7171
* @throws \UnexpectedValueException
7272
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
73+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
7374
*/
7475
public function convert(\DOMNode $source, $basePath = '')
7576
{

src/Magento/FunctionalTestingFramework/ObjectManager/Config/Config.php

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function getPreference($type)
152152
*
153153
* @param string $type
154154
* @return array
155-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
155+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
156156
*/
157157
protected function collectConfiguration($type)
158158
{
@@ -194,7 +194,6 @@ protected function collectConfiguration($type)
194194
*
195195
* @param array $configuration
196196
* @return void
197-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
198197
*/
199198
protected function mergeConfiguration(array $configuration)
200199
{
@@ -207,32 +206,44 @@ protected function mergeConfiguration(array $configuration)
207206
break;
208207

209208
default:
210-
$key = ltrim($key, '\\');
211-
if (isset($curConfig['type'])) {
212-
$this->virtualTypes[$key] = ltrim($curConfig['type'], '\\');
213-
}
214-
if (isset($curConfig['arguments'])) {
215-
if (!empty($this->mergedArguments)) {
216-
$this->mergedArguments = [];
217-
}
218-
if (isset($this->arguments[$key])) {
219-
$this->arguments[$key] = array_replace($this->arguments[$key], $curConfig['arguments']);
220-
} else {
221-
$this->arguments[$key] = $curConfig['arguments'];
222-
}
223-
}
224-
if (isset($curConfig['shared'])) {
225-
if (!$curConfig['shared']) {
226-
$this->nonShared[$key] = 1;
227-
} else {
228-
unset($this->nonShared[$key]);
229-
}
230-
}
209+
$this->setArguments($key, $curConfig);
231210
break;
232211
}
233212
}
234213
}
235214

215+
/**
216+
* Set arguments
217+
*
218+
* @param string $key
219+
* @param array $config
220+
* @return void
221+
*/
222+
private function setArguments($key, $config)
223+
{
224+
$key = ltrim($key, '\\');
225+
if (isset($config['type'])) {
226+
$this->virtualTypes[$key] = ltrim($config['type'], '\\');
227+
}
228+
if (isset($config['arguments'])) {
229+
if (!empty($this->mergedArguments)) {
230+
$this->mergedArguments = [];
231+
}
232+
if (isset($this->arguments[$key])) {
233+
$this->arguments[$key] = array_replace($this->arguments[$key], $config['arguments']);
234+
} else {
235+
$this->arguments[$key] = $config['arguments'];
236+
}
237+
}
238+
if (isset($config['shared'])) {
239+
if (!$config['shared']) {
240+
$this->nonShared[$key] = 1;
241+
} else {
242+
unset($this->nonShared[$key]);
243+
}
244+
}
245+
}
246+
236247
/**
237248
* Extend configuration
238249
*

src/Magento/FunctionalTestingFramework/ObjectManager/Factory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public function prepareArguments($object, $method, array $arguments = [])
103103
*
104104
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
105105
* @SuppressWarnings(PHPMD.NPathComplexity)
106+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
106107
*/
107108
protected function resolveArguments($requestedType, array $parameters, array $arguments = [])
108109
{
@@ -179,8 +180,10 @@ protected function resolveArguments($requestedType, array $parameters, array $ar
179180
*
180181
* @param array $array
181182
* @return void
183+
*
182184
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
183185
* @SuppressWarnings(PHPMD.NPathComplexity)
186+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
184187
*/
185188
protected function parseArray(&$array)
186189
{
@@ -219,8 +222,6 @@ protected function parseArray(&$array)
219222
* @param array $arguments
220223
* @return object
221224
* @throws \Exception
222-
*
223-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
224225
*/
225226
public function create($requestedType, array $arguments = [])
226227
{

src/Magento/FunctionalTestingFramework/ObjectManager/Factory/Dynamic/Developer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function setObjectManager(\Magento\FunctionalTestingFramework\ObjectManag
8787
*
8888
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8989
* @SuppressWarnings(PHPMD.NPathComplexity)
90+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
9091
*/
9192
protected function resolveArguments($requestedType, array $parameters, array $arguments = [])
9293
{

src/Magento/FunctionalTestingFramework/Suite/Util/SuiteObjectExtractor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ public function __construct()
4040
* @param array $parsedSuiteData
4141
* @return array
4242
* @throws XmlException
43+
* @throws \Exception
44+
*
4345
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
4446
* @SuppressWarnings(PHPMD.NPathComplexity)
45-
* @throws \Exception
47+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
4648
*/
4749
public function parseSuiteDataIntoObjects($parsedSuiteData)
4850
{

src/Magento/FunctionalTestingFramework/Test/Config/Converter/Dom/Flat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function convert($source)
7070
* @return string|array
7171
* @throws \UnexpectedValueException
7272
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
73+
* Revisited to reduce cyclomatic complexity, left unrefactored for readability
7374
*/
7475
public function convertXml(\DOMNode $source, $basePath = '')
7576
{

0 commit comments

Comments
 (0)