Skip to content

Commit fc1ce26

Browse files
Do not use empty()
1 parent 3dd2c7a commit fc1ce26

File tree

9 files changed

+16
-16
lines changed

9 files changed

+16
-16
lines changed

src/CodeCoverage.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $a
252252
$size,
253253
);
254254

255-
if (empty($rawData->lineCoverage())) {
255+
if ($rawData->lineCoverage() === []) {
256256
return;
257257
}
258258

@@ -395,7 +395,7 @@ private function applyCoversAndUsesFilter(RawCodeCoverageData $rawData, array|fa
395395
return;
396396
}
397397

398-
if (empty($linesToBeCovered)) {
398+
if ($linesToBeCovered === []) {
399399
return;
400400
}
401401

@@ -513,7 +513,7 @@ private function performUnintentionallyCoveredCodeCheck(RawCodeCoverageData $dat
513513

514514
$unintentionallyCoveredUnits = $this->processUnintentionallyCoveredUnits($unintentionallyCoveredUnits);
515515

516-
if (!empty($unintentionallyCoveredUnits)) {
516+
if ($unintentionallyCoveredUnits === []) {
517517
throw new UnintentionallyCoveredCodeException(
518518
$unintentionallyCoveredUnits,
519519
);

src/Data/RawCodeCoverageData.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function keepFunctionCoverageDataOnlyForLines(string $filename, array $li
214214
*/
215215
public function removeCoverageDataForLines(string $filename, array $lines): void
216216
{
217-
if (empty($lines)) {
217+
if ($lines === []) {
218218
return;
219219
}
220220

src/Filter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ public function files(): array
8888

8989
public function isEmpty(): bool
9090
{
91-
return empty($this->files);
91+
return $this->files === [];
9292
}
9393
}

src/Node/Builder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private function buildDirectoryStructure(ProcessedCodeCoverageData $data): array
201201
*/
202202
private function reducePaths(ProcessedCodeCoverageData $coverage): string
203203
{
204-
if (empty($coverage->coveredFiles())) {
204+
if ($coverage->coveredFiles() === []) {
205205
return '.';
206206
}
207207

@@ -226,7 +226,7 @@ private function reducePaths(ProcessedCodeCoverageData $coverage): string
226226

227227
$paths[$i] = explode(DIRECTORY_SEPARATOR, $paths[$i]);
228228

229-
if (empty($paths[$i][0])) {
229+
if ($paths[$i][0] === '') {
230230
$paths[$i][0] = DIRECTORY_SEPARATOR;
231231
}
232232
}

src/Report/Crap4j.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string
8383

8484
$methodNode = $document->createElement('method');
8585

86-
if (!empty($class['namespace'])) {
86+
if ($class['namespace'] !== '') {
8787
$namespace = $class['namespace'];
8888
}
8989

src/Report/Html/Renderer/File.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private function renderTraitOrClassItems(array $items, Template $template, Templ
332332
{
333333
$buffer = '';
334334

335-
if (empty($items)) {
335+
if ($items === []) {
336336
return $buffer;
337337
}
338338

@@ -437,7 +437,7 @@ private function renderTraitOrClassItems(array $items, Template $template, Templ
437437
*/
438438
private function renderFunctionItems(array $functions, Template $template): string
439439
{
440-
if (empty($functions)) {
440+
if ($functions === []) {
441441
return '';
442442
}
443443

@@ -570,7 +570,7 @@ private function renderSourceWithLineCoverage(FileNode $node): string
570570

571571
$popover = '';
572572

573-
if (!empty($popoverTitle)) {
573+
if ($popoverTitle !== '') {
574574
$popover = sprintf(
575575
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
576576
$popoverTitle,
@@ -848,7 +848,7 @@ private function renderBranchLines(array $branch, array $codeLines, array $testD
848848

849849
$popover = '';
850850

851-
if (!empty($popoverTitle)) {
851+
if ($popoverTitle !== '') {
852852
$popover = sprintf(
853853
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
854854
$popoverTitle,
@@ -966,7 +966,7 @@ private function renderPathLines(array $path, array $branches, array $codeLines,
966966

967967
$popover = '';
968968

969-
if (!empty($popoverTitle)) {
969+
if ($popoverTitle !== '') {
970970
$popover = sprintf(
971971
' data-bs-title="%s" data-bs-content="%s" data-bs-placement="top" data-bs-html="true"',
972972
$popoverTitle,

src/Report/Text.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(Thresholds $thresholds, bool $showUncoveredFiles = f
6060

6161
public function process(CodeCoverage $coverage, bool $showColors = false): string
6262
{
63-
$hasBranchCoverage = !empty($coverage->getData(true)->functionCoverage());
63+
$hasBranchCoverage = $coverage->getData(true)->functionCoverage() !== [];
6464

6565
$output = PHP_EOL . PHP_EOL;
6666
$report = $coverage->getReport();

src/StaticAnalysis/CodeUnitFindingVisitor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function leaveNode(Node $node): null
117117
}
118118
}
119119

120-
if (empty($traits)) {
120+
if ($traits === []) {
121121
return null;
122122
}
123123

src/StaticAnalysis/ParsingFileAnalyser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function analyse(string $filename): void
160160
$source = file_get_contents($filename);
161161
$linesOfCode = max(substr_count($source, "\n") + 1, substr_count($source, "\r") + 1);
162162

163-
if ($linesOfCode === 0 && !empty($source)) {
163+
if ($linesOfCode === 0 && $source !== false && $source !== '') {
164164
$linesOfCode = 1;
165165
}
166166

0 commit comments

Comments
 (0)