Term   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 58
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A txVocabulary() 0 5 1
A termsByMany() 0 5 1
A scopeByVocabulary() 0 3 1
A vocabulariesByMany() 0 5 1
1
<?php
2
3
namespace Fomvasss\Taxonomy\Models;
4
5
use Fomvasss\Taxonomy\Models\Traits\HasTaxonomies;
6
use Fomvasss\Taxonomy\Models\Traits\HasTaxonomyablesToMany;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\SoftDeletes;
9
use Kalnoy\Nestedset\NodeTrait;
10
11
class Term extends Model
12
{
13
    use HasTaxonomies,
0 ignored issues
show
Bug introduced by
The trait Kalnoy\Nestedset\NodeTrait requires the property $forceDeleting which is not provided by Fomvasss\Taxonomy\Models\Term.
Loading history...
14
        HasTaxonomyablesToMany,
15
        NodeTrait;
16
17
    protected $guarded = ['id'];
18
19
    /**
20
     * Связь:
21
     * Терм пренадлежит (относится к) одному словарю
22
     *
23
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
24
     */
25
    public function txVocabulary()
26
    {
27
        $related = config('taxonomy.models.vocabulary', Vocabulary::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

27
        $related = /** @scrutinizer ignore-call */ config('taxonomy.models.vocabulary', Vocabulary::class);
Loading history...
28
29
        return $this->belongsTo($related, 'vocabulary', 'system_name');
30
    }
31
32
    /**
33
     * Связь:
34
     * Сущность текущей модели терм "держит" много термов
35
     *
36
     * @return $this
37
     */
38
    public function termsByMany()
39
    {
40
        $related = config('taxonomy.models.term', static::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

40
        $related = /** @scrutinizer ignore-call */ config('taxonomy.models.term', static::class);
Loading history...
41
        
42
        return $this->morphedByMany($related, 'termable');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->morphedByMany($related, 'termable') returns the type Illuminate\Database\Eloquent\Relations\MorphToMany which is incompatible with the documented return type Fomvasss\Taxonomy\Models\Term.
Loading history...
43
    }
44
45
    /**
46
     * Связь:
47
     * Сущность текущей модели "держит" много словарей
48
     *
49
     * @return $this
50
     */
51
    public function vocabulariesByMany()
52
    {
53
        $related = config('taxonomy.models.vocabulary', Vocabulary::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

53
        $related = /** @scrutinizer ignore-call */ config('taxonomy.models.vocabulary', Vocabulary::class);
Loading history...
54
        
55
        return $this->morphedByMany($related, 'termable');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->morphedByMany($related, 'termable') returns the type Illuminate\Database\Eloquent\Relations\MorphToMany which is incompatible with the documented return type Fomvasss\Taxonomy\Models\Term.
Loading history...
56
    }
57
58
    /**
59
     * Все термы по указанным словарям
60
     *
61
     * @param $query
62
     * @param $vocabulary
63
     * @param string|null $vocabularyKey
64
     * @return mixed
65
     */
66
    public function scopeByVocabulary($query, $vocabulary)
67
    {
68
        return $query->where('vocabulary', $vocabulary);
69
    }
70
}
71