Passed
Push — master ( ede65d...64a7f1 )
by Vasyl
02:06
created

UrlAliasable::scopeByLocales()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: fomvasss
5
 * Date: 21.08.18
6
 * Time: 11:34
7
 */
8
9
namespace Fomvasss\UrlAliases\Traits;
10
11
trait UrlAliasable
12
{
13
    /**
14
     * @return mixed
15
     */
16
    public function urlAlias()
17
    {
18
        $model = config('url-aliases.model', \Fomvasss\UrlAliases\Models\UrlAlias::class);
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

18
        $model = /** @scrutinizer ignore-call */ config('url-aliases.model', \Fomvasss\UrlAliases\Models\UrlAlias::class);
Loading history...
19
20
        return $this->morphOne($model, 'model');
0 ignored issues
show
Bug introduced by
It seems like morphOne() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

20
        return $this->/** @scrutinizer ignore-call */ morphOne($model, 'model');
Loading history...
21
    }
22
23
    /**
24
     * @return mixed
25
     */
26
    public function urlAliases()
27
    {
28
        $model = config('url-aliases.model', \Fomvasss\UrlAliases\Models\UrlAlias::class);
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

28
        $model = /** @scrutinizer ignore-call */ config('url-aliases.model', \Fomvasss\UrlAliases\Models\UrlAlias::class);
Loading history...
29
30
        return $this->morphMany($model, 'model');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

30
        return $this->/** @scrutinizer ignore-call */ morphMany($model, 'model');
Loading history...
31
    }
32
33
    /**
34
     * @return |null
0 ignored issues
show
Documentation Bug introduced by
The doc comment |null at position 0 could not be parsed: Unknown type name '|' at position 0 in |null.
Loading history...
35
     */
36
    public function getLocaleboundStr()
37
    {
38
        if ($this->urlAlias) {
39
            return $this->urlAlias->locale_bound;
40
        } 
41
        
42
        return null;
43
    }
44
45
46
    /**
47
     * @param $query
48
     * @param null $locale
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $locale is correct as it would always require null to be passed?
Loading history...
49
     * @return mixed
50
     */
51
    public function scopeByLocale($query, $locale = null)
52
    {
53
        $locale = $locale ?: \UrlAliasLocalization::getCurrentLocale();
0 ignored issues
show
introduced by
$locale is of type null, thus it always evaluated to false.
Loading history...
Bug introduced by
The type UrlAliasLocalization was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
55
        return $query->whereLocale($locale);
56
    }
57
    
58
59
    /**
60
     * @param $query
61
     * @param null $locales
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $locales is correct as it would always require null to be passed?
Loading history...
62
     * @return mixed
63
     */
64
    public function scopeByLocales($query, $locales = null)
65
    {
66
        $locales = $locales ?: session('app_locales');
0 ignored issues
show
Bug introduced by
The function session was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

66
        $locales = $locales ?: /** @scrutinizer ignore-call */ session('app_locales');
Loading history...
introduced by
$locales is of type null, thus it always evaluated to false.
Loading history...
67
68
        if ($locales) {
69
            return $query->whereIn('locale', is_array($locales) ? $locales : [$locales]);
70
        }
71
    }
72
73
}