Passed
Push — master ( 36b5c4...8bb9fe )
by bader
02:50
created

HasManyCached::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 4
1
<?php
2
3
namespace Awssat\Kabsa\Relationships;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
8
9
class HasManyCached extends HasOneOrMany
10
{
11
    protected $foreignKey;
12
    protected $ownerKey;
13
    protected $related;
14
15
    public function __construct($related, Model $parent, $foreignKey = null, $ownerKey = null)
16
    {
17
        $this->foreignKey = $foreignKey;
18
        $this->ownerKey = $ownerKey;
19
        $this->related = $related;
20
21
        parent::__construct((new $related)->newQuery(), $parent, $foreignKey, $ownerKey);
22
    }
23
24
    public function getResults()
25
    {
26
        return $this->related::where($this->foreignKey,
27
            $this->parent->{$this->ownerKey});
28
    }
29
30
    public function initRelation(array $models, $relation)
31
    {
32
    }
33
34
    public function match(array $models, Collection $results, $relation)
35
    {
36
    }
37
}
38