sonata-project / sonata-doctrine-extensions

Compare 2967d6e ... +244 ... 37da047


@@ -13,8 +13,11 @@
Loading
13 13
14 14
namespace Sonata\Doctrine\Entity;
15 15
16 +
use Doctrine\DBAL\Connection;
16 17
use Doctrine\ORM\EntityManagerInterface;
17 18
use Doctrine\ORM\EntityRepository;
19 +
use Doctrine\Persistence\ObjectManager;
20 +
use Doctrine\Persistence\ObjectRepository;
18 21
use Sonata\Doctrine\Model\BaseManager;
19 22
20 23
/**
@@ -55,7 +58,7 @@
Loading
55 58
     *
56 59
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.15
57 60
     */
58 -
    public function getConnection()
61 +
    public function getConnection(): Connection
59 62
    {
60 63
        @trigger_error(sprintf(
61 64
            'The "%s()" method is deprecated since sonata-project/sonata-doctrine-extensions 1.15'
@@ -70,7 +73,7 @@
Loading
70 73
    /**
71 74
     * @return EntityManagerInterface
72 75
     */
73 -
    public function getEntityManager()
76 +
    public function getEntityManager(): ObjectManager
74 77
    {
75 78
        $objectManager = $this->getObjectManager();
76 79
        \assert($objectManager instanceof EntityManagerInterface);
@@ -81,7 +84,7 @@
Loading
81 84
    /**
82 85
     * @phpstan-return EntityRepository<T>
83 86
     */
84 -
    protected function getRepository(): EntityRepository
87 +
    protected function getRepository(): ObjectRepository
85 88
    {
86 89
        return $this->getEntityManager()->getRepository($this->class);
87 90
    }

@@ -39,22 +39,18 @@
Loading
39 39
    protected $class;
40 40
41 41
    /**
42 -
     * @param string $class
43 -
     *
44 42
     * @phpstan-param class-string<T> $class
45 43
     */
46 -
    public function __construct($class, ManagerRegistry $registry)
44 +
    public function __construct(string $class, ManagerRegistry $registry)
47 45
    {
48 46
        $this->registry = $registry;
49 47
        $this->class = $class;
50 48
    }
51 49
52 50
    /**
53 51
     * @throws \RuntimeException
54 -
     *
55 -
     * @return ObjectManager
56 52
     */
57 -
    public function getObjectManager()
53 +
    public function getObjectManager(): ObjectManager
58 54
    {
59 55
        $manager = $this->registry->getManagerForClass($this->class);
60 56
@@ -71,22 +67,22 @@
Loading
71 67
        return $manager;
72 68
    }
73 69
74 -
    public function getClass()
70 +
    public function getClass(): string
75 71
    {
76 72
        return $this->class;
77 73
    }
78 74
79 -
    public function findAll()
75 +
    public function findAll(): array
80 76
    {
81 77
        return $this->getRepository()->findAll();
82 78
    }
83 79
84 -
    public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null)
80 +
    public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
85 81
    {
86 82
        return $this->getRepository()->findBy($criteria, $orderBy, $limit, $offset);
87 83
    }
88 84
89 -
    public function findOneBy(array $criteria, ?array $orderBy = null)
85 +
    public function findOneBy(array $criteria, ?array $orderBy = null): ?object
90 86
    {
91 87
        if (null !== $orderBy) {
92 88
            @trigger_error(
@@ -98,17 +94,17 @@
Loading
98 94
        return $this->getRepository()->findOneBy($criteria);
99 95
    }
100 96
101 -
    public function find($id)
97 +
    public function find($id): ?object
102 98
    {
103 99
        return $this->getRepository()->find($id);
104 100
    }
105 101
106 -
    public function create()
102 +
    public function create(): object
107 103
    {
108 104
        return new $this->class();
109 105
    }
110 106
111 -
    public function save($entity, $andFlush = true)
107 +
    public function save(object $entity, bool $andFlush = true): void
112 108
    {
113 109
        $this->checkObject($entity);
114 110
@@ -119,7 +115,7 @@
Loading
119 115
        }
120 116
    }
121 117
122 -
    public function delete($entity, $andFlush = true)
118 +
    public function delete(object $entity, bool $andFlush = true): void
123 119
    {
124 120
        $this->checkObject($entity);
125 121
@@ -135,7 +131,7 @@
Loading
135 131
     *
136 132
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.15
137 133
     */
138 -
    public function getTableName()
134 +
    public function getTableName(): string
139 135
    {
140 136
        @trigger_error(sprintf(
141 137
            'The "%s()" method is deprecated since sonata-project/sonata-doctrine-extensions 1.15'
@@ -161,7 +157,7 @@
Loading
161 157
     *
162 158
     * @phpstan-return ObjectRepository<T>
163 159
     */
164 -
    protected function getRepository()
160 +
    protected function getRepository(): ObjectRepository
165 161
    {
166 162
        return $this->getObjectManager()->getRepository($this->class);
167 163
    }
@@ -171,11 +167,9 @@
Loading
171 167
     *
172 168
     * @throws \InvalidArgumentException
173 169
     *
174 -
     * @return void
175 -
     *
176 170
     * @phpstan-param T $object
177 171
     */
178 -
    protected function checkObject($object)
172 +
    protected function checkObject($object): void
179 173
    {
180 174
        if (!$object instanceof $this->class) {
181 175
            throw new \InvalidArgumentException(sprintf(

@@ -20,10 +20,7 @@
Loading
20 20
     */
21 21
    protected $adapters = [];
22 22
23 -
    /**
24 -
     * @return void
25 -
     */
26 -
    public function addAdapter(AdapterInterface $adapter)
23 +
    public function addAdapter(AdapterInterface $adapter): void
27 24
    {
28 25
        $this->adapters[] = $adapter;
29 26
    }

@@ -13,7 +13,9 @@
Loading
13 13
14 14
namespace Sonata\Doctrine\Document;
15 15
16 +
use Doctrine\DBAL\Connection;
16 17
use Doctrine\ODM\MongoDB\DocumentManager;
18 +
use Doctrine\Persistence\ObjectManager;
17 19
use Sonata\Doctrine\Model\BaseManager;
18 20
19 21
/**
@@ -54,15 +56,15 @@
Loading
54 56
     *
55 57
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.15
56 58
     */
57 -
    public function getConnection()
59 +
    public function getConnection(): Connection
58 60
    {
59 61
        throw new \LogicException('MongoDB does not use a database connection.');
60 62
    }
61 63
62 64
    /**
63 65
     * @return DocumentManager
64 66
     */
65 -
    public function getDocumentManager()
67 +
    public function getDocumentManager(): ObjectManager
66 68
    {
67 69
        $dm = $this->getObjectManager();
68 70

@@ -25,11 +25,9 @@
Loading
25 25
    /**
26 26
     * Return the Entity class name.
27 27
     *
28 -
     * @return string
29 -
     *
30 28
     * @phpstan-return class-string<T>
31 29
     */
32 -
    public function getClass();
30 +
    public function getClass(): string;
33 31
34 32
    /**
35 33
     * Find all entities in the repository.
@@ -38,95 +36,79 @@
Loading
38 36
     *
39 37
     * @phpstan-return T[]
40 38
     */
41 -
    public function findAll();
39 +
    public function findAll(): array;
42 40
43 41
    /**
44 42
     * Find entities by a set of criteria.
45 43
     *
46 44
     * @param array<string, mixed>                          $criteria
47 45
     * @param array<string, 'asc'|'ASC'|'desc'|'DESC'>|null $orderBy
48 -
     * @param int|null                                      $limit
49 -
     * @param int|null                                      $offset
50 46
     *
51 47
     * @return object[]
52 48
     *
53 49
     * @phpstan-return T[]
54 50
     */
55 -
    public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null);
51 +
    public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;
56 52
57 53
    /**
58 54
     * Find a single entity by a set of criteria.
59 55
     *
60 56
     * @param array<string, mixed>       $criteria
61 57
     * @param array<string, string>|null $orderBy
62 58
     *
63 -
     * @return object|null
64 -
     *
65 59
     * @phpstan-return T|null
66 60
     */
67 -
    public function findOneBy(array $criteria, ?array $orderBy = null);
61 +
    public function findOneBy(array $criteria, ?array $orderBy = null): ?object;
68 62
69 63
    /**
70 64
     * Finds an entity by its primary key / identifier.
71 65
     *
72 66
     * @param mixed $id The identifier
73 67
     *
74 -
     * @return object|null
75 -
     *
76 68
     * @phpstan-return T|null
77 69
     */
78 -
    public function find($id);
70 +
    public function find($id): ?object;
79 71
80 72
    /**
81 73
     * Create an empty Entity instance.
82 74
     *
83 -
     * @return object
84 -
     *
85 75
     * @phpstan-return T
86 76
     */
87 -
    public function create();
77 +
    public function create(): object;
88 78
89 79
    /**
90 80
     * Save an Entity.
91 81
     *
92 82
     * @param object $entity   The Entity to save
93 83
     * @param bool   $andFlush Flush the EntityManager after saving the object?
94 84
     *
95 -
     * @return void
96 -
     *
97 85
     * @phpstan-param T $entity
98 86
     */
99 -
    public function save($entity, $andFlush = true);
87 +
    public function save(object $entity, bool $andFlush = true): void;
100 88
101 89
    /**
102 90
     * Delete an Entity.
103 91
     *
104 92
     * @param object $entity   The Entity to delete
105 93
     * @param bool   $andFlush Flush the EntityManager after deleting the object?
106 94
     *
107 -
     * @return void
108 -
     *
109 95
     * @phpstan-param T $entity
110 96
     */
111 -
    public function delete($entity, $andFlush = true);
97 +
    public function delete(object $entity, bool $andFlush = true): void;
112 98
113 99
    /**
114 100
     * Get the related table name.
115 101
     *
116 102
     * NEXT_MAJOR: Remove this ORM-related method from the interface.
117 -
     *
118 -
     * @return string
119 103
     */
120 -
    public function getTableName();
104 +
    public function getTableName(): string;
121 105
122 106
    /**
123 107
     * Get the DB driver connection.
124 108
     *
125 109
     * NEXT_MAJOR: Remove this ORM-related method from the interface.
126 -
     *
127 -
     * @return Connection
128 110
     */
129 -
    public function getConnection();
111 +
    public function getConnection(): Connection;
130 112
}
131 113
132 114
interface_exists(\Sonata\CoreBundle\Model\ManagerInterface::class);

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.

246 Commits

+31
+16
+15
+40
+32
+8
+16
+16
+2
+2
+3
+3
-13
-13
+4
+4
+4 Files
+20
+20
Hiding 144 contexual commits
-4 Files
-103
-77
-26
Files Complexity Coverage
src ø 63.48%
Project Totals (27 files) 211 63.48%
Loading