Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#382)
by Cristian
03:31
created

SluggableScopeHelpers   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeWhereSlug() 0 4 1
A findBySlug() 0 4 1
A findBySlugOrFail() 0 4 1
1
<?php
2
3
namespace Backpack\CRUD\ModelTraits\SpatieTranslatable;
4
5
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Backpack\CRUD\ModelTrait...e\SluggableScopeHelpers.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
trait SluggableScopeHelpers
8
{
9
    use SluggableScopeHelpers;
10
11
    /**
12
     * Query scope for finding a model by its primary slug.
13
     *
14
     * @param \Illuminate\Database\Eloquent\Builder $scope
15
     * @param string $slug
16
     * @return \Illuminate\Database\Eloquent\Builder
17
     */
18
    public function scopeWhereSlug($scope, $slug)
19
    {
20
        return $scope->where($this->getSlugKeyName().'->'.$this->getLocale(), $slug);
21
    }
22
23
    /**
24
     * Find a model by its primary slug.
25
     *
26
     * @param string $slug
27
     * @param array $columns
28
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|null
29
     */
30
    public static function findBySlug($slug, array $columns = ['*'])
31
    {
32
        return static::whereSlug($slug)->first($columns);
33
    }
34
35
    /**
36
     * Find a model by its primary slug or throw an exception.
37
     *
38
     * @param string $slug
39
     * @param array $columns
40
     * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection
41
     *
42
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
43
     */
44
    public static function findBySlugOrFail($slug, array $columns = ['*'])
45
    {
46
        return static::whereSlug($slug)->firstOrFail($columns);
47
    }
48
}
49