NestedRelation   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveNestedRelation() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zing\QueryBuilder\Concerns;
6
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\Str;
9
10
trait NestedRelation
11
{
12
    /**
13
     * @return array{string, string}
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{string, string} at position 2 could not be parsed: Expected ':' at position 2, but found 'string'.
Loading history...
14
     */
15 5
    protected function resolveNestedRelation(string $property): array
16
    {
17 5
        return collect(explode('.', $property))
18 5
            ->pipe(
19 5
                function (Collection $parts): array {
20
                    return [
21 5
                        $parts->except([\count($parts) - 1])
22 5
                            ->map(function (string $value): string {
23 5
                                return Str::camel($value);
24 5
                            })->implode('.'),
25 5
                        $parts->last(),
26
                    ];
27
                }
28
            );
29
    }
30
}
31