Completed
Push — master ( 408932...ce7eb5 )
by Dawid
06:58
created

Repository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 53
ccs 25
cts 30
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 8 1
A get() 0 17 2
A create() 0 15 2
A update() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Driver\MongoDB;
4
5
use Igni\Storage\Driver\GenericRepository;
6
use Igni\Storage\Exception\RepositoryException;
7
use Igni\Storage\Storable;
8
9
abstract class Repository extends GenericRepository
10
{
11 2
    public function get($id): Storable
12
    {
13 2
        $cursor = $this->connection->find(
0 ignored issues
show
Bug introduced by
The method find() does not exist on Igni\Storage\Driver\Connection. It seems like you code against a sub-type of Igni\Storage\Driver\Connection such as Igni\Storage\Driver\MongoDB\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

13
        /** @scrutinizer ignore-call */ 
14
        $cursor = $this->connection->find(
Loading history...
14 2
            $this->metaData->getSource(),
15 2
            ['_id' => $id],
16 2
            ['limit' => 1]
17
        );
18 2
        $cursor->hydrateWith($this->hydrator);
19
20 2
        $entity = $cursor->current();
21 2
        $cursor->close();
22
23 2
        if (!$entity instanceof Storable) {
24
            throw RepositoryException::forNotFound($id);
25
        }
26
27 2
        return $entity;
28
    }
29
30 1
    public function create(Storable $entity): Storable
31
    {
32
        // Support id auto-generation.
33 1
        $entity->getId();
34 1
        $data = $this->hydrator->extract($entity);
35 1
        if (isset($data['id'])) {
36 1
            $data['_id'] = $data['id'];
37 1
            unset($data['id']);
38
        }
39 1
        $this->connection->insert(
0 ignored issues
show
Bug introduced by
The method insert() does not exist on Igni\Storage\Driver\Connection. It seems like you code against a sub-type of Igni\Storage\Driver\Connection such as Igni\Storage\Driver\MongoDB\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $this->connection->/** @scrutinizer ignore-call */ 
40
                           insert(
Loading history...
40 1
            $this->metaData->getSource(),
41 1
            $data
42
        );
43
44 1
        return $entity;
45
    }
46
47 1
    public function remove(Storable $entity): Storable
48
    {
49 1
        $this->connection->remove(
0 ignored issues
show
Bug introduced by
The method remove() does not exist on Igni\Storage\Driver\Connection. It seems like you code against a sub-type of Igni\Storage\Driver\Connection such as Igni\Storage\Driver\MongoDB\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        $this->connection->/** @scrutinizer ignore-call */ 
50
                           remove(
Loading history...
50 1
            $this->metaData->getSource(),
51 1
            $entity->getId()->getValue()
52
        );
53
54 1
        return $entity;
55
    }
56
57
    public function update(Storable $entity): Storable
58
    {
59
        $this->connection->update(
0 ignored issues
show
Bug introduced by
The method update() does not exist on Igni\Storage\Driver\Connection. It seems like you code against a sub-type of Igni\Storage\Driver\Connection such as Igni\Storage\Driver\MongoDB\Connection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        $this->connection->/** @scrutinizer ignore-call */ 
60
                           update(
Loading history...
60
            $this->metaData->getSource(),
61
            $this->hydrator->extract($entity)
62
        );
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Igni\Storage\Storable. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
63
    }
64
}
65