Passed
Push — master ( e1c5c8...a48a63 )
by Guillermo A.
08:16
created

ReadOnlyRepositoryTrait::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Guillermoandrae\Repositories;
4
5
use BadMethodCallException;
6
use Guillermoandrae\Models\ModelInterface;
7
8
trait ReadOnlyRepositoryTrait
9
{
10
    final public function create(array $options): ModelInterface
11
    {
12
        unset($options);
13
        return $this->callUnsupportedMethod('create');
14
    }
15
16
    final public function update($id, array $options): ModelInterface
17
    {
18
        unset($id, $options);
19
        return $this->callUnsupportedMethod('update');
20
    }
21
22
    final public function delete($id): bool
23
    {
24
        unset($id);
25
        return $this->callUnsupportedMethod('delete');
26
    }
27
28
    /**
29
     * Throws an exception and uses the method name to generate the message.
30
     *
31
     * @param string $method The name of the unsupported method.
32
     */
33
    protected function callUnsupportedMethod(string $method)
34
    {
35
        throw new BadMethodCallException(
36
            sprintf('The %s method of this read-only repository is not supported.', $method)
37
        );
38
    }
39
}
40