Collector::collections()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Vetor\Laravel\Collect\Collector\Models\Traits;
4
5
use Vetor\Contracts\Collect\Collection\Models\Collection as CollectionContract;
6
use Vetor\Contracts\Collect\Collectable\Models\Collectable as CollectableContract;
7
use Vetor\Contracts\Collect\Collectable\Services\CollectableService as CollectableServiceContract;
8
9
trait Collector
10
{
11
    /**
12
     * @return mixed
13
     */
14 1
    public function collections()
15
    {
16 1
        return $this->hasMany(app(CollectionContract::class), 'user_id', $this->getKeyName());
0 ignored issues
show
Bug introduced by
It seems like getKeyName() 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

16
        return $this->hasMany(app(CollectionContract::class), 'user_id', $this->/** @scrutinizer ignore-call */ getKeyName());
Loading history...
Bug introduced by
It seems like hasMany() 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

16
        return $this->/** @scrutinizer ignore-call */ hasMany(app(CollectionContract::class), 'user_id', $this->getKeyName());
Loading history...
17
    }
18
19
    /**
20
     * @param \Vetor\Contracts\Collect\Collectable\Models\Collectable $collectable
21
     */
22 4
    public function collect(CollectableContract $collectable)
23
    {
24 4
        return app(CollectableServiceContract::class)->addCollectionTo($collectable, $this);
25
    }
26
27
    /**
28
     * @param \Vetor\Contracts\Collect\Collectable\Models\Collectable $collectable
29
     */
30
    public function isCollectThis(CollectableContract $collectable)
31
    {
32
        return app(CollectableServiceContract::class)->isCollection($collectable, $this);
0 ignored issues
show
Bug introduced by
The method isCollection() does not exist on Vetor\Contracts\Collect\...ices\CollectableService. Since it exists in all sub-types, consider adding an abstract or default implementation to Vetor\Contracts\Collect\...ices\CollectableService. ( Ignorable by Annotation )

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

32
        return app(CollectableServiceContract::class)->/** @scrutinizer ignore-call */ isCollection($collectable, $this);
Loading history...
33
    }
34
35
    /**
36
     * @param \Vetor\Contracts\Collect\Collectable\Models\Collectable $collectable
37
     */
38 1
    public function cancelCollect(CollectableContract $collectable)
39
    {
40 1
        return app(CollectableServiceContract::class)->removeCollectionFrom($collectable, $this);
41
    }
42
43
    /**
44
     * @param $collectableClass
45
     * @return mixed
46
     */
47 1
    public function collectionsWhereCollectable($collectableClass)
48
    {
49 1
        return $this->collections()->where('collectable_type', (new $collectableClass)->getMorphClass())->get();
50
    }
51
}
52