Passed
Push — feature/custom-services-v2 ( 14ad97...35de26 )
by Chema
03:35
created

UseBlockParser::getUseStatement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 15
rs 10
ccs 9
cts 9
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\DocBlockService;
6
7
final class UseBlockParser
8
{
9 5
    public function getUseStatement(string $className, string $phpCode): string
10
    {
11 5
        if ($phpCode === '') {
12 1
            return '';
13
        }
14
15 4
        $needle = "{$className};";
16 4
        $lines = array_filter(
17 4
            explode(PHP_EOL, $phpCode),
18 4
            static fn (string $l) => str_contains($l, $needle)
19
        );
20
        /** @psalm-suppress RedundantCast */
21 4
        $lineSplit = (array)explode(' ', (string)reset($lines));
22
23 4
        return rtrim($lineSplit[1] ?? '', ';');
24
    }
25
}
26