Skip to content

Commit 0e3a644

Browse files
authored
[3.x] refactor: Use first-class callables for internal callbacks (#1780)
We still had a few uses of array callables within our internal code, which I found when starting to look at adding parameter types to internal methods. Rector has a rule to fix these as part of the PHP 8.1 set that we are running, but it had skipped over them because they were not public methods, even though they are defined and used in their own scope. I think this may actually be a Rector bug - see rectorphp/rector-src#7760 for the patch which I have temporarily used locally to convert these. Refactoring them to first-class callables will help Rector (and possibly phpstan) to make better decisions about parameter & return types in future.
1 parent ee6edc2 commit 0e3a644

7 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/Behat/Behat/HelperContainer/Argument/ServicesResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
*/
3838
public function resolveArguments(ReflectionClass $classReflection, array $arguments)
3939
{
40-
return array_map([$this, 'resolveArgument'], $arguments);
40+
return array_map($this->resolveArgument(...), $arguments);
4141
}
4242

4343
/**

src/Behat/Behat/Output/Node/Printer/Pretty/PrettyExampleRowPrinter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private function printStepException(OutputPrinter $printer, AfterTested $event):
134134
}
135135

136136
$text = $this->exceptionPresenter->presentException($result->getException());
137-
$indentedText = implode("\n", array_map([$this, 'subIndent'], explode("\n", $text)));
137+
$indentedText = implode("\n", array_map($this->subIndent(...), explode("\n", $text)));
138138
$printer->writeln(sprintf('{+%s}%s{-%s}', $style, $indentedText, $style));
139139
}
140140

src/Behat/Behat/Output/Node/Printer/Pretty/PrettyFeaturePrinter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function printTags(OutputPrinter $printer, array $tags): void
6767
return;
6868
}
6969

70-
$tags = array_map([$this, 'prependTagWithTagSign'], $tags);
70+
$tags = array_map($this->prependTagWithTagSign(...), $tags);
7171
$printer->writeln(sprintf('%s{+tag}%s{-tag}', $this->indentText, implode(' ', $tags)));
7272
}
7373

src/Behat/Behat/Output/Node/Printer/Pretty/PrettyScenarioPrinter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function printTags(OutputPrinter $printer, array $tags): void
7777
return;
7878
}
7979

80-
$tags = array_map([$this, 'prependTagWithTagSign'], $tags);
80+
$tags = array_map($this->prependTagWithTagSign(...), $tags);
8181
$printer->writeln(sprintf('%s{+tag}%s{-tag}', $this->indentText, implode(' ', $tags)));
8282
}
8383

src/Behat/Behat/Output/Node/Printer/Pretty/PrettySkippedStepPrinter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private function printArguments(Formatter $formatter, array $arguments): void
9999
foreach ($arguments as $argument) {
100100
$text = $this->getArgumentString($argument, !$formatter->getParameter('multiline'));
101101

102-
$indentedText = implode("\n", array_map([$this, 'subIndent'], explode("\n", $text)));
102+
$indentedText = implode("\n", array_map($this->subIndent(...), explode("\n", $text)));
103103
$formatter->getOutputPrinter()->writeln(sprintf('{+%s}%s{-%s}', $style, $indentedText, $style));
104104
}
105105
}

src/Behat/Behat/Output/Node/Printer/Pretty/PrettyStepPrinter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function printArguments(Formatter $formatter, array $arguments, StepResu
113113
foreach ($arguments as $argument) {
114114
$text = $this->getArgumentString($argument, !$formatter->getParameter('multiline'));
115115

116-
$indentedText = implode("\n", array_map([$this, 'subIndent'], explode("\n", $text)));
116+
$indentedText = implode("\n", array_map($this->subIndent(...), explode("\n", $text)));
117117
$formatter->getOutputPrinter()->writeln(sprintf('{+%s}%s{-%s}', $style, $indentedText, $style));
118118
}
119119
}
@@ -151,7 +151,7 @@ private function printException(OutputPrinter $printer, StepResult $result): voi
151151
}
152152

153153
$text = $this->exceptionPresenter->presentException($result->getException());
154-
$indentedText = implode("\n", array_map([$this, 'subIndent'], explode("\n", $text)));
154+
$indentedText = implode("\n", array_map($this->subIndent(...), explode("\n", $text)));
155155
$printer->writeln(sprintf('{+%s}%s{-%s}', $style, $indentedText, $style));
156156
}
157157

src/Behat/Testwork/Argument/MixedArgumentOrganiser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ private function prepareTypehintedArguments(array $parameters, array $typehinted
223223
$parameters,
224224
$candidates,
225225
$arguments,
226-
[$this, 'classMatchingPredicateForTypehintedArguments']
226+
$this->classMatchingPredicateForTypehintedArguments(...)
227227
);
228228

229229
// This iteration maps up everything else, providing the argument is an instanceof the parameter.
230230
$this->applyPredicateToTypehintedArguments(
231231
$parameters,
232232
$candidates,
233233
$arguments,
234-
[$this, 'isInstancePredicateForTypehintedArguments']
234+
$this->isInstancePredicateForTypehintedArguments(...)
235235
);
236236

237237
return $arguments;

0 commit comments

Comments
 (0)