Completed
Branch master (fe6485)
by Nil
02:01
created

BaseEloquentRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 4 1
A guard() 0 4 1
1
<?php
2
3
namespace NilPortugues\Foundation\Infrastructure\Model\Repository\EloquentMongoDB;
4
5
use Jenssegers\Mongodb\Eloquent\Model;
6
use NilPortugues\Assert\Assert;
7
8
abstract class BaseEloquentRepository
9
{
10
    /** @var Model */
11
    protected static $instance;
12
13
    /**
14
     * BaseEloquentRepository constructor.
15
     *
16
     * @param Model $instance
17
     */
18
    protected function __construct(Model $instance)
19
    {
20
        self::$instance = $instance;
21
    }
22
23
    /**
24
     * @param Model $instance
25
     *
26
     * @return static
27
     */
28
    public static function create(Model $instance)
29
    {
30
        return new static($instance);
31
    }
32
33
    /**
34
     * @param $value
35
     *
36
     * @throws \Exception
37
     */
38
    protected function guard($value)
39
    {
40
        Assert::isInstanceOf($value, self::$instance);
41
    }
42
}
43