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

UseBlockParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 10
ccs 9
cts 9
cp 1
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getUseStatement() 0 15 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