Failed Conditions
Push — 186-self-joins-fail-in-relatio... ( ba3e0e...5bcaaa )
by Bas
08:01 queued 40s
created

GeneratesTableAlias::generateTableAlias()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 11
rs 10
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent\Query\Concerns;
4
5
use Illuminate\Database\Query\Expression;
6
use Illuminate\Support\Str;
7
8
trait GeneratesTableAlias
9
{
10
    public function generateTableAlias(string|Expression $table, string $postfix = 'Doc'): string
11
    {
12
        if (Str::startsWith($table, 'laravel_')) {
0 ignored issues
show
Bug introduced by
It seems like $table can also be of type Illuminate\Database\Query\Expression; however, parameter $haystack of Illuminate\Support\Str::startsWith() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

12
        if (Str::startsWith(/** @scrutinizer ignore-type */ $table, 'laravel_')) {
Loading history...
13
            return $table;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $table could return the type Illuminate\Database\Query\Expression which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
14
        }
15
16
        if ($table instanceof Expression) {
17
            return 'laravel_expression_' . spl_object_id($table);
18
        }
19
20
        return Str::camel(Str::singular($table)) . $postfix;
21
    }
22
}