NestedRelation::resolveNestedRelation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 1
rs 9.9666
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