Skip to content

Commit d5b2c35

Browse files
committed
minor #54447 Remove unnecessary empty usages (ostrolucky)
This PR was merged into the 7.1 branch. Discussion ---------- Remove unnecessary empty usages | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? |no | Deprecations? | no | Issues | | License | MIT I've written a rector for this rectorphp/rector-src#5783 and decided to apply it on Symfony src here. As for motivation for removing empty where possible, in my and several other prominent devs opinions, using `empty()` is a bad practice for several reasons: - it's misleading. It doesn't work with collection or stringable objects. Its meaning is more like `isset($foo) && (bool) $foo` rather than `count($foo) === 0` or `strlen($foo) === 0`, contrary to name of this function. - it decreases safety of the code, because it's doing implicit `isset` call, so once you remove variable assignment, `empty()` call that references it continues silently working - it increases complexity because of having to negate the call in most cases (there is no `nonempty()` function) - it's unnecessary in most cases and hence adds extra opcodes and increases length of code for no good reason There were also several articles written on this topic, I know about these 2: - https://www.contextualcode.com/Blog/php-micro-optimization.-variable-boolean-cast-vs-!empty - https://www.beberlei.de/2021/02/19/when_to_use_empty_in_php_i_say_never.html (this one is from `@beberlei`) However, personally I'm not in a super strict camp. I like that I don't have to explicitly specify `[] === $foo` or `'' === $foo` or `null === $foo` (and so on and on) and I think Symfony shares the similar opinion. Commits ------- ccc813c65f Remove unnecessary empty usages
2 parents 6cd02e6 + 9280ea4 commit d5b2c35

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

DataCollector/HttpClientDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private function getCurlCommand(array $trace): ?string
213213
}
214214
}
215215

216-
$dataArg = empty($dataArg) ? null : implode(' ', $dataArg);
216+
$dataArg = $dataArg ? implode(' ', $dataArg) : null;
217217

218218
foreach (explode("\n", $trace['info']['debug']) as $line) {
219219
$line = substr($line, 0, -1);

0 commit comments

Comments
 (0)