Passed
Push — master ( 583647...efdb33 )
by Dawid
02:55
created

Repository::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
    public function get($id): Storable
12
    {
13
        $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
            $this->metaData->getSource(),
15
            ['_id' => $id],
16
            ['limit' => 1]
17
        );
18
        $cursor->hydrateWith($this->hydrator);
19
20
        $entity = $cursor->current();
21
        $cursor->close();
22
23
        if (!$entity instanceof Storable) {
24
            throw RepositoryException::forNotFound($id);
25
        }
26
27
        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
    public function remove(Storable $entity): Storable
48
    {
49
        $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
            $this->metaData->getSource(),
51
            $entity->getId()->getValue()
52
        );
53
54
        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