sonata-project / sonata-doctrine-extensions
Showing 18 of 35 files from the diff.

@@ -21,37 +21,37 @@
Loading
21 21
final class DoctrineORMMapper implements EventSubscriber
22 22
{
23 23
    /**
24 -
     * @var array
24 +
     * @var array<class-string, array<string, array<array<string, mixed>>>>
25 25
     */
26 26
    private $associations = [];
27 27
28 28
    /**
29 -
     * @var array
29 +
     * @var array<class-string, array<string, class-string>>
30 30
     */
31 31
    private $discriminators = [];
32 32
33 33
    /**
34 -
     * @var array
34 +
     * @var array<class-string, array<string, mixed>>
35 35
     */
36 36
    private $discriminatorColumns = [];
37 37
38 38
    /**
39 -
     * @var array
39 +
     * @var array<class-string, int>
40 40
     */
41 41
    private $inheritanceTypes = [];
42 42
43 43
    /**
44 -
     * @var array
44 +
     * @var array<class-string, array<string, array<string>>>
45 45
     */
46 46
    private $indexes = [];
47 47
48 48
    /**
49 -
     * @var array
49 +
     * @var array<class-string, array<string, array<string>>>
50 50
     */
51 51
    private $uniques = [];
52 52
53 53
    /**
54 -
     * @var array
54 +
     * @var array<class-string, array<string, array<array<string, mixed>>>>
55 55
     */
56 56
    private $overrides = [];
57 57
@@ -63,7 +63,9 @@
Loading
63 63
    }
64 64
65 65
    /**
66 -
     * @param array $options
66 +
     * @param array<array<string, mixed>> $options
67 +
     *
68 +
     * @phpstan-param class-string $class
67 69
     */
68 70
    public function addAssociation(string $class, string $type, $options): void
69 71
    {
@@ -85,8 +87,10 @@
Loading
85 87
    /**
86 88
     * Add a discriminator to a class.
87 89
     *
88 -
     * @param string $key                Key is the database value and values are the classes
89 -
     * @param string $discriminatorClass The mapped class
90 +
     * @param string $key Key is the database value and values are the classes
91 +
     *
92 +
     * @phpstan-param class-string $class
93 +
     * @phpstan-param class-string $discriminatorClass
90 94
     */
91 95
    public function addDiscriminator(string $class, string $key, string $discriminatorClass): void
92 96
    {
@@ -100,7 +104,9 @@
Loading
100 104
    }
101 105
102 106
    /**
103 -
     * @param array $columnDef
107 +
     * @param array<string, mixed> $columnDef
108 +
     *
109 +
     * @phpstan-param class-string $class
104 110
     */
105 111
    public function addDiscriminatorColumn(string $class, $columnDef): void
106 112
    {
@@ -118,6 +124,8 @@
Loading
118 124
    }
119 125
120 126
    /**
127 +
     * @phpstan-param class-string $class
128 +
     *
121 129
     * @see ClassMetadata for supported types
122 130
     */
123 131
    public function addInheritanceType(string $class, int $type): void
@@ -128,7 +136,9 @@
Loading
128 136
    }
129 137
130 138
    /**
131 -
     * @param array<string> $columns
139 +
     * @param string[] $columns
140 +
     *
141 +
     * @phpstan-param class-string $class
132 142
     */
133 143
    public function addIndex(string $class, string $name, array $columns): void
134 144
    {
@@ -146,7 +156,9 @@
Loading
146 156
    }
147 157
148 158
    /**
149 -
     * @param array<string> $columns
159 +
     * @param string[] $columns
160 +
     *
161 +
     * @phpstan-param class-string $class
150 162
     */
151 163
    public function addUnique(string $class, string $name, array $columns): void
152 164
    {
@@ -164,7 +176,9 @@
Loading
164 176
    }
165 177
166 178
    /**
167 -
     * @param array $options
179 +
     * @param array<array<string, mixed>> $options
180 +
     *
181 +
     * @phpstan-param class-string $class
168 182
     */
169 183
    public function addOverride(string $class, string $type, $options): void
170 184
    {
@@ -198,6 +212,8 @@
Loading
198 212
    }
199 213
200 214
    /**
215 +
     * @param ClassMetadata<object> $metadata
216 +
     *
201 217
     * @throws \RuntimeException
202 218
     */
203 219
    private function loadAssociations(ClassMetadata $metadata): void
@@ -214,6 +230,7 @@
Loading
214 230
                        continue;
215 231
                    }
216 232
233 +
                    // @phpstan-ignore-next-line https://github.com/phpstan/phpstan/issues/1105
217 234
                    \call_user_func([$metadata, $type], $mapping);
218 235
                }
219 236
            }
@@ -223,6 +240,8 @@
Loading
223 240
    }
224 241
225 242
    /**
243 +
     * @param ClassMetadata<object> $metadata
244 +
     *
226 245
     * @throws \RuntimeException
227 246
     */
228 247
    private function loadDiscriminatorColumns(ClassMetadata $metadata): void
@@ -247,6 +266,8 @@
Loading
247 266
    }
248 267
249 268
    /**
269 +
     * @param ClassMetadata<object> $metadata
270 +
     *
250 271
     * @throws \RuntimeException
251 272
     */
252 273
    private function loadInheritanceTypes(ClassMetadata $metadata): void
@@ -267,6 +288,8 @@
Loading
267 288
    }
268 289
269 290
    /**
291 +
     * @param ClassMetadata<object> $metadata
292 +
     *
270 293
     * @throws \RuntimeException
271 294
     */
272 295
    private function loadDiscriminators(ClassMetadata $metadata): void
@@ -289,6 +312,9 @@
Loading
289 312
        }
290 313
    }
291 314
315 +
    /**
316 +
     * @param ClassMetadata<object> $metadata
317 +
     */
292 318
    private function loadIndexes(ClassMetadata $metadata): void
293 319
    {
294 320
        if (!\array_key_exists($metadata->getName(), $this->indexes)) {
@@ -302,6 +328,9 @@
Loading
302 328
        }
303 329
    }
304 330
331 +
    /**
332 +
     * @param ClassMetadata<object> $metadata
333 +
     */
305 334
    private function loadUniques(ClassMetadata $metadata): void
306 335
    {
307 336
        if (!\array_key_exists($metadata->getName(), $this->uniques)) {
@@ -315,6 +344,9 @@
Loading
315 344
        }
316 345
    }
317 346
347 +
    /**
348 +
     * @param ClassMetadata<object> $metadata
349 +
     */
318 350
    private function loadOverrides(ClassMetadata $metadata): void
319 351
    {
320 352
        if (!\array_key_exists($metadata->getName(), $this->overrides)) {
@@ -324,6 +356,7 @@
Loading
324 356
        try {
325 357
            foreach ($this->overrides[$metadata->getName()] as $type => $overrides) {
326 358
                foreach ($overrides as $override) {
359 +
                    // @phpstan-ignore-next-line https://github.com/phpstan/phpstan/issues/1105
327 360
                    \call_user_func([$metadata, $type], $override['fieldName'], $override);
328 361
                }
329 362
            }
@@ -336,6 +369,9 @@
Loading
336 369
        }
337 370
    }
338 371
372 +
    /**
373 +
     * @param string[] $columns
374 +
     */
339 375
    private function verifyColumnNames(array $columns): void
340 376
    {
341 377
        foreach ($columns as $column) {

@@ -25,6 +25,9 @@
Loading
25 25
 */
26 26
class SonataDoctrineExtension extends Extension
27 27
{
28 +
    /**
29 +
     * @param mixed[] $configs
30 +
     */
28 31
    public function load(array $configs, ContainerBuilder $container): void
29 32
    {
30 33
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
@@ -36,6 +39,8 @@
Loading
36 39
        }
37 40
38 41
        $bundles = $container->getParameter('kernel.bundles');
42 +
        \assert(\is_array($bundles));
43 +
39 44
        if (class_exists(DocumentManager::class) && isset($bundles['DoctrinePHPCRBundle'])) {
40 45
            $loader->load('doctrine_phpcr.php');
41 46
        }

@@ -35,12 +35,23 @@
Loading
35 35
36 36
    public function getNormalizedIdentifier($model)
37 37
    {
38 -
        if (null === $model) {
39 -
            return null;
40 -
        }
41 -
38 +
        // NEXT_MAJOR: Remove this check and add type hint instead.
42 39
        if (!\is_object($model)) {
43 -
            throw new \RuntimeException('Invalid argument, object or null required');
40 +
            if (null === $model) {
41 +
                @trigger_error(sprintf(
42 +
                    'Passing other type than object as argument 1 for method %s() is deprecated since'
43 +
                    .' sonata-project/doctrine-extensions 1.x. It will accept only object in version 2.0.',
44 +
                    __METHOD__
45 +
                ), \E_USER_DEPRECATED);
46 +
47 +
                return null;
48 +
            }
49 +
50 +
            throw new \RuntimeException(sprintf(
51 +
                'Argument 1 passed to "%s()" must be an object, %s given.',
52 +
                __METHOD__,
53 +
                \gettype($model)
54 +
            ));
44 55
        }
45 56
46 57
        $manager = $this->registry->getManagerForClass(\get_class($model));

@@ -30,7 +30,7 @@
Loading
30 30
        foreach ($this->adapters as $adapter) {
31 31
            $identifier = $adapter->getNormalizedIdentifier($model);
32 32
33 -
            if ($identifier) {
33 +
            if (null !== $identifier) {
34 34
                return $identifier;
35 35
            }
36 36
        }
@@ -43,7 +43,7 @@
Loading
43 43
        foreach ($this->adapters as $adapter) {
44 44
            $safeIdentifier = $adapter->getUrlSafeIdentifier($model);
45 45
46 -
            if ($safeIdentifier) {
46 +
            if (null !== $safeIdentifier) {
47 47
                return $safeIdentifier;
48 48
            }
49 49
        }

@@ -22,6 +22,7 @@
Loading
22 22
    ForwardCompatibleSonataDoctrineBundle::class
23 23
), \E_USER_DEPRECATED);
24 24
25 +
// @phpstan-ignore-next-line
25 26
if (false) {
26 27
    /**
27 28
     * NEXT_MAJOR: remove this class.

@@ -23,6 +23,8 @@
Loading
23 23
);
24 24
25 25
/**
26 +
 * NEXT_MAJOR: Remove this class.
27 +
 *
26 28
 * Convert a value into a json string to be stored into the persistency layer.
27 29
 */
28 30
class JsonType extends Type

@@ -19,37 +19,37 @@
Loading
19 19
final class DoctrineCollector
20 20
{
21 21
    /**
22 -
     * @var array
22 +
     * @var array<class-string, array<string, array<array<string, mixed>>>>
23 23
     */
24 24
    private $associations = [];
25 25
26 26
    /**
27 -
     * @var array
27 +
     * @var array<class-string, array<string, array<string>>>
28 28
     */
29 29
    private $indexes = [];
30 30
31 31
    /**
32 -
     * @var array
32 +
     * @var array<class-string, array<string, array<string>>>
33 33
     */
34 34
    private $uniques = [];
35 35
36 36
    /**
37 -
     * @var array
37 +
     * @var array<class-string, array<string, class-string>>
38 38
     */
39 39
    private $discriminators = [];
40 40
41 41
    /**
42 -
     * @var array
42 +
     * @var array<class-string, array<string, mixed>>
43 43
     */
44 44
    private $discriminatorColumns = [];
45 45
46 46
    /**
47 -
     * @var array
47 +
     * @var array<class-string, int>
48 48
     */
49 49
    private $inheritanceTypes = [];
50 50
51 51
    /**
52 -
     * @var array
52 +
     * @var array<class-string, array<string, array<array<string, mixed>>>>
53 53
     */
54 54
    private $overrides = [];
55 55
@@ -77,8 +77,10 @@
Loading
77 77
    /**
78 78
     * Add a discriminator to a class.
79 79
     *
80 -
     * @param string $key                Key is the database value and values are the classes
81 -
     * @param string $discriminatorClass The mapped class
80 +
     * @param string $key Key is the database value and values are the classes
81 +
     *
82 +
     * @phpstan-param class-string $class
83 +
     * @phpstan-param class-string $discriminatorClass
82 84
     */
83 85
    public function addDiscriminator(string $class, string $key, string $discriminatorClass): void
84 86
    {
@@ -91,6 +93,9 @@
Loading
91 93
        }
92 94
    }
93 95
96 +
    /**
97 +
     * @phpstan-param class-string $class
98 +
     */
94 99
    public function addDiscriminatorColumn(string $class, ColumnDefinitionBuilder $columnDef): void
95 100
    {
96 101
        if (!isset($this->discriminatorColumns[$class])) {
@@ -100,6 +105,8 @@
Loading
100 105
101 106
    /**
102 107
     * @param int $type
108 +
     *
109 +
     * @phpstan-param class-string $class
103 110
     */
104 111
    public function addInheritanceType(string $class, $type): void
105 112
    {
@@ -116,6 +123,9 @@
Loading
116 123
        }
117 124
    }
118 125
126 +
    /**
127 +
     * @phpstan-param class-string $class
128 +
     */
119 129
    public function addAssociation(string $class, string $type, OptionsBuilder $options): void
120 130
    {
121 131
        if (!isset($this->associations[$class])) {
@@ -130,7 +140,9 @@
Loading
130 140
    }
131 141
132 142
    /**
133 -
     * @param array<string> $columns
143 +
     * @param string[] $columns
144 +
     *
145 +
     * @phpstan-param class-string $class
134 146
     */
135 147
    public function addIndex(string $class, string $name, array $columns): void
136 148
    {
@@ -148,7 +160,9 @@
Loading
148 160
    }
149 161
150 162
    /**
151 -
     * @param array<string> $columns
163 +
     * @param string[] $columns
164 +
     *
165 +
     * @phpstan-param class-string $class
152 166
     */
153 167
    public function addUnique(string $class, string $name, array $columns): void
154 168
    {
@@ -165,6 +179,9 @@
Loading
165 179
        $this->uniques[$class][$name] = $columns;
166 180
    }
167 181
182 +
    /**
183 +
     * @phpstan-param class-string $class
184 +
     */
168 185
    public function addOverride(string $class, string $type, OptionsBuilder $options): void
169 186
    {
170 187
        if (!isset($this->overrides[$class])) {
@@ -178,36 +195,57 @@
Loading
178 195
        $this->overrides[$class][$type][] = $options->getOptions();
179 196
    }
180 197
198 +
    /**
199 +
     * @return array<class-string, array<string, array<array<string, mixed>>>>
200 +
     */
181 201
    public function getAssociations(): array
182 202
    {
183 203
        return $this->associations;
184 204
    }
185 205
206 +
    /**
207 +
     * @return array<class-string, array<string, class-string>>
208 +
     */
186 209
    public function getDiscriminators(): array
187 210
    {
188 211
        return $this->discriminators;
189 212
    }
190 213
214 +
    /**
215 +
     * @return array<class-string, array<string, mixed>>
216 +
     */
191 217
    public function getDiscriminatorColumns(): array
192 218
    {
193 219
        return $this->discriminatorColumns;
194 220
    }
195 221
222 +
    /**
223 +
     * @return array<class-string, int>
224 +
     */
196 225
    public function getInheritanceTypes(): array
197 226
    {
198 227
        return $this->inheritanceTypes;
199 228
    }
200 229
230 +
    /**
231 +
     * @return array<class-string, array<string, array<string>>>
232 +
     */
201 233
    public function getIndexes(): array
202 234
    {
203 235
        return $this->indexes;
204 236
    }
205 237
238 +
    /**
239 +
     * @return array<class-string, array<string, array<string>>>
240 +
     */
206 241
    public function getUniques(): array
207 242
    {
208 243
        return $this->uniques;
209 244
    }
210 245
246 +
    /**
247 +
     * @return array<class-string, array<string, array<array<string, mixed>>>>
248 +
     */
211 249
    public function getOverrides(): array
212 250
    {
213 251
        return $this->overrides;
@@ -224,6 +262,9 @@
Loading
224 262
        $this->overrides = [];
225 263
    }
226 264
265 +
    /**
266 +
     * @param string[] $columns
267 +
     */
227 268
    private function verifyColumnNames(array $columns): void
228 269
    {
229 270
        foreach ($columns as $column) {

@@ -29,20 +29,36 @@
Loading
29 29
    /**
30 30
     * Make sure the code is compatible with legacy code.
31 31
     *
32 +
     * NEXT_MAJOR: Remove the magic getter.
33 +
     *
34 +
     * @param string $name
35 +
     *
32 36
     * @return mixed
33 37
     */
34 38
    public function __get($name)
35 39
    {
36 40
        if ('dm' === $name) {
41 +
            @trigger_error(
42 +
                'Accessing to the document manager through the magic getter is deprecated since'
43 +
                .' sonata-project/sonata-doctrine-extensions 1.x and will throw an exception in 2.0.'
44 +
                .' Use the "getObjectManager()" method instead.',
45 +
                \E_USER_DEPRECATED
46 +
            );
47 +
37 48
            return $this->getObjectManager();
38 49
        }
39 50
40 51
        throw new \RuntimeException(sprintf('The property %s does not exists', $name));
41 52
    }
42 53
54 +
    /**
55 +
     * NEXT_MAJOR: Remove this method.
56 +
     *
57 +
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.x
58 +
     */
43 59
    public function getConnection(): Connection
44 60
    {
45 -
        return $this->getObjectManager()->getConnection();
61 +
        throw new \LogicException('MongoDB does not use a database connection.');
46 62
    }
47 63
48 64
    /**

@@ -26,11 +26,22 @@
Loading
26 26
    /**
27 27
     * Make sure the code is compatible with legacy code.
28 28
     *
29 +
     * NEXT_MAJOR: Remove the magic getter.
30 +
     *
31 +
     * @param string $name
32 +
     *
29 33
     * @return mixed
30 34
     */
31 35
    public function __get($name)
32 36
    {
33 37
        if ('dm' === $name) {
38 +
            @trigger_error(
39 +
                'Accessing to the document manager through the magic getter is deprecated since'
40 +
                .' sonata-project/sonata-doctrine-extensions 1.x and will throw an exception in 2.0.'
41 +
                .' Use the "getObjectManager()" method instead.',
42 +
                \E_USER_DEPRECATED
43 +
            );
44 +
34 45
            return $this->getObjectManager();
35 46
        }
36 47
@@ -38,9 +49,9 @@
Loading
38 49
    }
39 50
40 51
    /**
41 -
     * {@inheritdoc}
52 +
     * NEXT_MAJOR: Remove this method.
42 53
     *
43 -
     * @throws \LogicException Each call
54 +
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.x
44 55
     */
45 56
    public function getConnection(): Connection
46 57
    {
@@ -48,9 +59,9 @@
Loading
48 59
    }
49 60
50 61
    /**
51 -
     * {@inheritdoc}
62 +
     * NEXT_MAJOR: Remove this method.
52 63
     *
53 -
     * @throws \LogicException Each call
64 +
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.x
54 65
     */
55 66
    public function getTableName(): string
56 67
    {

@@ -13,6 +13,7 @@
Loading
13 13
14 14
namespace Sonata\Doctrine\Model;
15 15
16 +
use Doctrine\ORM\Mapping\ClassMetadataInfo;
16 17
use Doctrine\Persistence\ManagerRegistry;
17 18
use Doctrine\Persistence\ObjectManager;
18 19
use Doctrine\Persistence\ObjectRepository;
@@ -53,7 +54,7 @@
Loading
53 54
    {
54 55
        $manager = $this->registry->getManagerForClass($this->class);
55 56
56 -
        if (!$manager) {
57 +
        if (null === $manager) {
57 58
            throw new \RuntimeException(sprintf(
58 59
                'Unable to find the mapping information for the class %s.'
59 60
                .' Please check the `auto_mapping` option'
@@ -125,9 +126,23 @@
Loading
125 126
        }
126 127
    }
127 128
129 +
    /**
130 +
     * NEXT_MAJOR: Remove this method.
131 +
     *
132 +
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.x
133 +
     */
128 134
    public function getTableName(): string
129 135
    {
130 -
        return $this->getObjectManager()->getClassMetadata($this->class)->table['name'];
136 +
        @trigger_error(sprintf(
137 +
            'The "%s()" method is deprecated since sonata-project/sonata-doctrine-extensions 1.x'
138 +
            .' and will be removed in version 2.0.',
139 +
            __METHOD__
140 +
        ), \E_USER_DEPRECATED);
141 +
142 +
        $metadata = $this->getObjectManager()->getClassMetadata($this->class);
143 +
        \assert($metadata instanceof ClassMetadataInfo);
144 +
145 +
        return $metadata->table['name'];
131 146
    }
132 147
133 148
    public function clear(?string $objectName = null): void
@@ -137,6 +152,10 @@
Loading
137 152
138 153
    /**
139 154
     * Returns the related Object Repository.
155 +
     *
156 +
     * @return ObjectRepository<object>
157 +
     *
158 +
     * @phpstan-return ObjectRepository<T>
140 159
     */
141 160
    protected function getRepository(): ObjectRepository
142 161
    {
@@ -144,7 +163,11 @@
Loading
144 163
    }
145 164
146 165
    /**
166 +
     * @param object $object
167 +
     *
147 168
     * @throws \InvalidArgumentException
169 +
     *
170 +
     * @phpstan-param T $object
148 171
     */
149 172
    protected function checkObject($object): void
150 173
    {

@@ -56,6 +56,11 @@
Loading
56 56
        return new self();
57 57
    }
58 58
59 +
    /**
60 +
     * @param mixed $value
61 +
     *
62 +
     * @return $this
63 +
     */
59 64
    public function add(string $key, $value): self
60 65
    {
61 66
        $this->options[$key] = $value;
@@ -83,6 +88,9 @@
Loading
83 88
        return new self(self::MANY_TO_MANY, $fieldName, $targetEntity);
84 89
    }
85 90
91 +
    /**
92 +
     * @return $this
93 +
     */
86 94
    public function mappedBy(string $mappedBy): self
87 95
    {
88 96
        if (!\in_array($this->type, [self::ONE_TO_MANY, self::ONE_TO_ONE, self::MANY_TO_MANY], true)) {
@@ -96,6 +104,9 @@
Loading
96 104
        return $this;
97 105
    }
98 106
107 +
    /**
108 +
     * @return $this
109 +
     */
99 110
    public function inversedBy(string $inversedBy): self
100 111
    {
101 112
        if (!\in_array($this->type, [self::ONE_TO_ONE, self::MANY_TO_ONE, self::MANY_TO_MANY], true)) {
@@ -144,6 +155,8 @@
Loading
144 155
145 156
    /**
146 157
     * @param 'ASC'|'DESC' $orientation
158 +
     *
159 +
     * @return $this
147 160
     */
148 161
    public function addOrder(string $field, string $orientation): self
149 162
    {
@@ -171,6 +184,8 @@
Loading
171 184
     *     onDelete?: string,
172 185
     *     columnDefinition?: string
173 186
     * } $joinColumn
187 +
     *
188 +
     * @return $this
174 189
     */
175 190
    public function addJoin(array $joinColumn): self
176 191
    {
@@ -190,6 +205,8 @@
Loading
190 205
    }
191 206
192 207
    /**
208 +
     * @return $this
209 +
     *
193 210
     * @psalm-param list<'persist'|'remove'|'merge'|'detach'|'refresh'|'all'> $value
194 211
     */
195 212
    public function cascade(array $value): self
@@ -199,6 +216,9 @@
Loading
199 216
        return $this;
200 217
    }
201 218
219 +
    /**
220 +
     * @return $this
221 +
     */
202 222
    public function orphanRemoval(): self
203 223
    {
204 224
        if (!\in_array($this->type, [self::ONE_TO_ONE, self::ONE_TO_MANY], true)) {
@@ -212,6 +232,9 @@
Loading
212 232
        return $this;
213 233
    }
214 234
235 +
    /**
236 +
     * @return array<string, mixed>
237 +
     */
215 238
    public function getOptions(): array
216 239
    {
217 240
        return $this->options;

@@ -24,6 +24,8 @@
Loading
24 24
/**
25 25
 * @author Raphaël Benitte <benitteraphael@gmail.com>
26 26
 *
27 +
 * NEXT_MAJOR: Remove this interface.
28 +
 *
27 29
 * @deprecated since 1.3, to be removed in 2.0. Use Sonata\DatagridBundle\Pager\PageableInterface instead.
28 30
 */
29 31
interface PageableManagerInterface

@@ -29,6 +29,11 @@
Loading
29 29
        return new self();
30 30
    }
31 31
32 +
    /**
33 +
     * @param mixed $value
34 +
     *
35 +
     * @return $this
36 +
     */
32 37
    public function add(string $key, $value): self
33 38
    {
34 39
        $this->options[$key] = $value;
@@ -36,6 +41,9 @@
Loading
36 41
        return $this;
37 42
    }
38 43
44 +
    /**
45 +
     * @return array<string, mixed>
46 +
     */
39 47
    public function getOptions(): array
40 48
    {
41 49
        return $this->options;

@@ -20,6 +20,9 @@
Loading
20 20
21 21
final class SonataDoctrineBundle extends Bundle
22 22
{
23 +
    /**
24 +
     * @return void
25 +
     */
23 26
    public function build(ContainerBuilder $container)
24 27
    {
25 28
        $container->addCompilerPass(new AdapterCompilerPass());

@@ -29,11 +29,15 @@
Loading
29 29
);
30 30
31 31
/**
32 +
 * NEXT_MAJOR: Remove this class.
33 +
 *
32 34
 * @deprecated since sonata-project/doctrine-extensions 1.5, to be removed in 2.0.
33 35
 */
34 36
class EntityManagerMockFactory
35 37
{
36 38
    /**
39 +
     * @param string[] $fields
40 +
     *
37 41
     * @return EntityManagerInterface
38 42
     */
39 43
    public static function create(TestCase $test, \Closure $qbCallback, $fields)

@@ -14,7 +14,7 @@
Loading
14 14
namespace Sonata\Doctrine\Entity;
15 15
16 16
use Doctrine\DBAL\Connection;
17 -
use Doctrine\ORM\EntityManager;
17 +
use Doctrine\ORM\EntityManagerInterface;
18 18
use Doctrine\ORM\EntityRepository;
19 19
use Doctrine\Persistence\ObjectManager;
20 20
use Doctrine\Persistence\ObjectRepository;
@@ -31,41 +31,62 @@
Loading
31 31
    /**
32 32
     * Make sure the code is compatible with legacy code.
33 33
     *
34 +
     * NEXT_MAJOR: Remove the magic getter.
35 +
     *
36 +
     * @param string $name
37 +
     *
34 38
     * @return mixed
35 39
     */
36 40
    public function __get($name)
37 41
    {
38 42
        if ('em' === $name) {
43 +
            @trigger_error(
44 +
                'Accessing to the entity manager through the magic getter is deprecated since'
45 +
                .' sonata-project/sonata-doctrine-extensions 1.x and will throw an exception in 2.0.'
46 +
                .' Use the "getObjectManager()" method instead.',
47 +
                \E_USER_DEPRECATED
48 +
            );
49 +
39 50
            return $this->getObjectManager();
40 51
        }
41 52
42 53
        throw new \RuntimeException(sprintf('The property %s does not exists', $name));
43 54
    }
44 55
56 +
    /**
57 +
     * NEXT_MAJOR: Remove this method.
58 +
     *
59 +
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.x
60 +
     */
45 61
    public function getConnection(): Connection
46 62
    {
63 +
        @trigger_error(sprintf(
64 +
            'The "%s()" method is deprecated since sonata-project/sonata-doctrine-extensions 1.x'
65 +
            .' and will be removed in version 2.0. Use "%s" instead.',
66 +
            __METHOD__,
67 +
            'getEntityManager()->getConnection()'
68 +
        ), \E_USER_DEPRECATED);
69 +
47 70
        return $this->getEntityManager()->getConnection();
48 71
    }
49 72
50 73
    /**
51 -
     * @return EntityManager
74 +
     * @return EntityManagerInterface
52 75
     */
53 76
    public function getEntityManager(): ObjectManager
54 77
    {
55 78
        $objectManager = $this->getObjectManager();
56 -
57 -
        \assert($objectManager instanceof EntityManager);
79 +
        \assert($objectManager instanceof EntityManagerInterface);
58 80
59 81
        return $objectManager;
60 82
    }
61 83
84 +
    /**
85 +
     * @phpstan-return EntityRepository<T>
86 +
     */
62 87
    protected function getRepository(): ObjectRepository
63 88
    {
64 -
        $repository = $this->getEntityManager()->getRepository($this->class);
65 -
66 -
        \assert($repository instanceof EntityRepository);
67 -
68 -
        return $repository;
89 +
        return $this->getEntityManager()->getRepository($this->class);
69 90
    }
70 91
}
71 92

@@ -34,12 +34,23 @@
Loading
34 34
35 35
    public function getNormalizedIdentifier($model)
36 36
    {
37 -
        if (null === $model) {
38 -
            return null;
39 -
        }
40 -
37 +
        // NEXT_MAJOR: Remove this check and add type hint instead.
41 38
        if (!\is_object($model)) {
42 -
            throw new \RuntimeException('Invalid argument, object or null required');
39 +
            if (null === $model) {
40 +
                @trigger_error(sprintf(
41 +
                    'Passing other type than object as argument 1 for method %s() is deprecated since'
42 +
                    .' sonata-project/doctrine-extensions 1.x. It will accept only object in version 2.0.',
43 +
                    __METHOD__
44 +
                ), \E_USER_DEPRECATED);
45 +
46 +
                return null;
47 +
            }
48 +
49 +
            throw new \RuntimeException(sprintf(
50 +
                'Argument 1 passed to "%s()" must be an object, %s given.',
51 +
                __METHOD__,
52 +
                \gettype($model)
53 +
            ));
43 54
        }
44 55
45 56
        $manager = $this->registry->getManagerForClass(\get_class($model));

@@ -98,11 +98,15 @@
Loading
98 98
99 99
    /**
100 100
     * Get the related table name.
101 +
     *
102 +
     * NEXT_MAJOR: Remove this ORM-related method from the interface.
101 103
     */
102 104
    public function getTableName(): string;
103 105
104 106
    /**
105 107
     * Get the DB driver connection.
108 +
     *
109 +
     * NEXT_MAJOR: Remove this ORM-related method from the interface.
106 110
     */
107 111
    public function getConnection(): Connection;
108 112
}
Files Complexity Coverage
src 211 63.48%
Project Totals (27 files) 211 63.48%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading