Completed
Push — master ( 1f358d...28dfad )
by
03:02
created

AbstractProvider::flush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DoS\ResourceBundle\Provider;
4
5
use Doctrine\ODM\MongoDB\DocumentManager;
6
use Doctrine\ORM\EntityManager;
7
use DoS\ResourceBundle\Doctrine\RepositoryInterface;
8
use DoS\ResourceBundle\Factory\FactoryInterface;
9
use Sylius\Component\Resource\Model\ResourceInterface;
10
11
/**
12
 * @author liverbool <[email protected]>
13
 */
14
abstract class AbstractProvider
15
{
16
    /**
17
     * @var EntityManager|DocumentManager
18
     */
19
    protected $manager;
20
21
    /**
22
     * @var string
23
     */
24
    protected $dataClass;
25
26
    /**
27
     * @var RepositoryInterface
28
     */
29
    protected $repository;
30
31
    /**
32
     * @var FactoryInterface
33
     */
34
    protected $factory;
35
36
    public function __construct(RepositoryInterface $repository, FactoryInterface $factory)
37
    {
38
        $this->repository = $repository;
39
        $this->factory = $factory;
40
        $this->manager = $repository->getManager();
0 ignored issues
show
Documentation Bug introduced by
It seems like $repository->getManager() of type object<Doctrine\Common\Persistence\ObjectManager> is incompatible with the declared type object<Doctrine\ORM\Enti...ongoDB\DocumentManager> of property $manager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
        $this->dataClass = $repository->getEntityName();
42
    }
43
44
    /**
45
     * @return ResourceInterface
46
     */
47
    public function createNew()
48
    {
49
        return $this->factory->createNew();
50
    }
51
52
    /**
53
     * @param ResourceInterface $resource
54
     */
55
    public function persist(ResourceInterface $resource)
56
    {
57
        $this->manager->persist($resource);
58
    }
59
60
    /**
61
     * @param ResourceInterface|null $resource
62
     */
63
    public function flush(ResourceInterface $resource = null)
64
    {
65
        $this->manager->flush($resource);
66
    }
67
68
    /**
69
     * @param ResourceInterface $resource
70
     * @param bool $single
71
     */
72
    public function save(ResourceInterface $resource, $single = false)
73
    {
74
        $this->manager->persist($resource);
75
        $this->manager->flush($single ? $resource : null);
76
    }
77
78
    /**
79
     * @param $id
80
     *
81
     * @return ResourceInterface
82
     */
83
    public function find($id)
84
    {
85
        return $this->repository->find($id);
86
    }
87
88
    /**
89
     * @return ResourceInterface[]
90
     */
91
    public function findAll()
92
    {
93
        return $this->repository->findAll();
94
    }
95
96
    /**
97
     * @param array $criteria
98
     * @param array|null $orderBy
99
     * @param null $limit
100
     * @param null $offset
101
     *
102
     * @return ResourceInterface[]
103
     */
104
    public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
105
    {
106
        return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
107
    }
108
109
    /**
110
     * @param array $criteria
111
     *
112
     * @return ResourceInterface[]
113
     */
114
    public function findOneBy(array $criteria)
115
    {
116
        return $this->repository->findOneBy($criteria);
117
    }
118
}
119