Completed
Push — extensions-support ( 3bbfd2...ec18bd )
by Guido
12:26
created

Entity   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 4
dl 0
loc 64
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setRepositoryClass() 0 6 1
A readOnly() 0 6 1
A cacheable() 0 7 2
A __call() 0 8 2
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Builders;
4
5
use Doctrine\ORM\Mapping\ClassMetadataInfo;
6
use LaravelDoctrine\Fluent\Builders\Traits\Macroable;
7
8
class Entity extends AbstractBuilder
9
{
10
    use Macroable;
11
12
    /**
13
     * @param string $class
14
     *
15
     * @return Entity
16
     */
17 1
    public function setRepositoryClass($class)
18
    {
19 1
        $this->builder->setCustomRepositoryClass($class);
20
21 1
        return $this;
22
    }
23
24
    /**
25
     * @return Entity
26
     */
27 1
    public function readOnly()
28
    {
29 1
        $this->builder->setReadOnly();
30
31 1
        return $this;
32
    }
33
34
    /**
35
     * Enables second-level cache on this entity.
36
     * If you want to enable second-level cache,
37
     * you must enable it on the EntityManager configuration.
38
     * Depending on the cache mode selected, you may also need to configure
39
     * lock modes.
40
     *
41
     * @param int         $usage  Cache mode. use ClassMetadataInfo::CACHE_USAGE_* constants.
42
     *                            Defaults to READ_ONLY mode.
43
     * @param string|null $region The cache region to be used. Doctrine will use a default region
44
     *                            for each entity, if none is provided.
45
     *
46
     * @return Entity
47
     * @see http://doctrine-orm.readthedocs.org/en/latest/reference/second-level-cache.html
48
     */
49 1
    public function cacheable($usage = ClassMetadataInfo::CACHE_USAGE_READ_ONLY, $region = null)
50
    {
51 1
        $meta = $this->builder->getClassMetadata();
52 1
        $meta->enableCache(compact('usage', $region === null ?: 'region'));
53
54 1
        return $this;
55
    }
56
57
    /**
58
     * @param string $method
59
     * @param array  $params
60
     *
61
     * @return mixed
62
     */
63 4
    public function __call($method, $params)
64
    {
65 4
        if ($this->hasMacro($method)) {
66 3
            return $this->callMacro($method, $params);
67
        }
68
69 1
        throw new \InvalidArgumentException('Fluent builder method [' . $method . '] does not exist');
70
    }   
71
}
72