Completed
Pull Request — master (#22)
by Sergey
17:35 queued 02:34
created

ElasticsearchModel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A di() 0 4 1
A getRelationshipKey() 0 4 1
A setRelationshipKey() 0 4 1
A belongsTo() 0 4 1
A hasMany() 0 4 1
1
<?php
2
3
namespace Isswp101\Persimmon\Model;
4
5
use Isswp101\Persimmon\Collection\IElasticsearchCollection;
6
use Isswp101\Persimmon\DI\Container;
7
use Isswp101\Persimmon\DI\DI;
8
use Isswp101\Persimmon\QueryBuilder\IQueryBuilder;
9
use Isswp101\Persimmon\Relationship\BelongsToRelationship;
10
use Isswp101\Persimmon\Relationship\HasManyRelationship;
11
use Isswp101\Persimmon\Relationship\RelationshipKey;
12
13
/**
14
 * @method static static find($id, array $columns = [])
15
 * @method static IElasticsearchCollection all(IQueryBuilder $query, callable $callback = null)
16
 */
17
class ElasticsearchModel extends Eloquent implements IElasticsearchModel
18
{
19
    protected $relationshipKey;
20
21
    protected static function di(): Container
22
    {
23
        return DI::make(DI::ELASTICSEARCH);
24
    }
25
26
    public function getRelationshipKey(): RelationshipKey
27
    {
28
        return $this->relationshipKey;
29
    }
30
31
    public function setRelationshipKey(RelationshipKey $relationshipKey)
32
    {
33
        $this->relationshipKey = $relationshipKey;
34
    }
35
36
    protected function belongsTo(string $class)
37
    {
38
        return new BelongsToRelationship($this, $class);
39
    }
40
41
    protected function hasMany(string $class)
42
    {
43
        return new HasManyRelationship($this, $class);
44
    }
45
}