BaseEloquentRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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