Skip to content

Commit 5ac9cbc

Browse files
committed
refactor: extract method
NPath complexity was 216.
1 parent d1623b7 commit 5ac9cbc

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/TestDouble.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,7 @@ public function getDouble(
5353
$mockBuilder->setConstructorArgs($constructorParams);
5454
}
5555

56-
$methods = [];
57-
$onConsecutiveCalls = [];
58-
$otherCalls = [];
59-
60-
foreach ($params as $key => $val) {
61-
if (is_int($key)) {
62-
$onConsecutiveCalls = array_merge($onConsecutiveCalls, $val);
63-
$methods[] = array_keys($val)[0];
64-
} else {
65-
$otherCalls[$key] = $val;
66-
$methods[] = $key;
67-
}
68-
}
56+
[$onConsecutiveCalls, $otherCalls, $methods] = $this->processParams($params);
6957

7058
if ($methods === []) {
7159
$mock = $mockBuilder->getMock();
@@ -103,6 +91,30 @@ public function getDouble(
10391
return $mock;
10492
}
10593

94+
/**
95+
* @param array<string, mixed>|array<array> $params [method_name => return_value]
96+
*
97+
* @return array{0: array<string, array<string>>, 1: array<string, mixed>, 2: string[]}
98+
*/
99+
private function processParams(array $params): array
100+
{
101+
$onConsecutiveCalls = [];
102+
$otherCalls = [];
103+
$methods = [];
104+
105+
foreach ($params as $key => $val) {
106+
if (is_int($key)) {
107+
$onConsecutiveCalls = array_merge($onConsecutiveCalls, $val);
108+
$methods[] = array_keys($val)[0];
109+
} else {
110+
$otherCalls[$key] = $val;
111+
$methods[] = $key;
112+
}
113+
}
114+
115+
return [$onConsecutiveCalls, $otherCalls, $methods];
116+
}
117+
106118
/**
107119
* @param array<mixed>|null $params
108120
* @param mixed $expects

0 commit comments

Comments
 (0)