sonata-project / sonata-doctrine-extensions
Showing 18 of 36 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,11 @@
Loading
25 25
 */
26 26
class SonataDoctrineExtension extends Extension
27 27
{
28 +
    /**
29 +
     * @param mixed[] $configs
30 +
     *
31 +
     * @return void
32 +
     */
28 33
    public function load(array $configs, ContainerBuilder $container)
29 34
    {
30 35
        $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
@@ -36,6 +41,8 @@
Loading
36 41
        }
37 42
38 43
        $bundles = $container->getParameter('kernel.bundles');
44 +
        \assert(\is_array($bundles));
45 +
39 46
        if (class_exists(DocumentManager::class) && isset($bundles['DoctrinePHPCRBundle'])) {
40 47
            $loader->load('doctrine_phpcr.php');
41 48
        }

@@ -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));

@@ -20,6 +20,9 @@
Loading
20 20
     */
21 21
    protected $adapters = [];
22 22
23 +
    /**
24 +
     * @return void
25 +
     */
23 26
    public function addAdapter(AdapterInterface $adapter)
24 27
    {
25 28
        $this->adapters[] = $adapter;
@@ -30,7 +33,7 @@
Loading
30 33
        foreach ($this->adapters as $adapter) {
31 34
            $identifier = $adapter->getNormalizedIdentifier($model);
32 35
33 -
            if ($identifier) {
36 +
            if (null !== $identifier) {
34 37
                return $identifier;
35 38
            }
36 39
        }
@@ -43,7 +46,7 @@
Loading
43 46
        foreach ($this->adapters as $adapter) {
44 47
            $safeIdentifier = $adapter->getUrlSafeIdentifier($model);
45 48
46 -
            if ($safeIdentifier) {
49 +
            if (null !== $safeIdentifier) {
47 50
                return $safeIdentifier;
48 51
            }
49 52
        }

@@ -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) {

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

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

@@ -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;
@@ -57,7 +58,7 @@
Loading
57 58
    {
58 59
        $manager = $this->registry->getManagerForClass($this->class);
59 60
60 -
        if (!$manager) {
61 +
        if (null === $manager) {
61 62
            throw new \RuntimeException(sprintf(
62 63
                'Unable to find the mapping information for the class %s.'
63 64
                .' Please check the `auto_mapping` option'
@@ -129,9 +130,23 @@
Loading
129 130
        }
130 131
    }
131 132
133 +
    /**
134 +
     * NEXT_MAJOR: Remove this method.
135 +
     *
136 +
     * @deprecated since sonata-project/sonata-doctrine-extensions 1.x
137 +
     */
132 138
    public function getTableName()
133 139
    {
134 -
        return $this->getObjectManager()->getClassMetadata($this->class)->table['name'];
140 +
        @trigger_error(sprintf(
141 +
            'The "%s()" method is deprecated since sonata-project/sonata-doctrine-extensions 1.x'
142 +
            .' and will be removed in version 2.0.',
143 +
            __METHOD__
144 +
        ), \E_USER_DEPRECATED);
145 +
146 +
        $metadata = $this->getObjectManager()->getClassMetadata($this->class);
147 +
        \assert($metadata instanceof ClassMetadataInfo);
148 +
149 +
        return $metadata->table['name'];
135 150
    }
136 151
137 152
    public function clear(?string $objectName = null): void
@@ -142,7 +157,9 @@
Loading
142 157
    /**
143 158
     * Returns the related Object Repository.
144 159
     *
145 -
     * @return ObjectRepository
160 +
     * @return ObjectRepository<object>
161 +
     *
162 +
     * @phpstan-return ObjectRepository<T>
146 163
     */
147 164
    protected function getRepository()
148 165
    {
@@ -150,9 +167,13 @@
Loading
150 167
    }
151 168
152 169
    /**
170 +
     * @param object $object
171 +
     *
153 172
     * @throws \InvalidArgumentException
154 173
     *
155 174
     * @return void
175 +
     *
176 +
     * @phpstan-param T $object
156 177
     */
157 178
    protected function checkObject($object)
158 179
    {

@@ -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)

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

@@ -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));

@@ -92,6 +92,8 @@
Loading
92 92
     * @param object $entity   The Entity to save
93 93
     * @param bool   $andFlush Flush the EntityManager after saving the object?
94 94
     *
95 +
     * @return void
96 +
     *
95 97
     * @phpstan-param T $entity
96 98
     */
97 99
    public function save($entity, $andFlush = true);
@@ -102,6 +104,8 @@
Loading
102 104
     * @param object $entity   The Entity to delete
103 105
     * @param bool   $andFlush Flush the EntityManager after deleting the object?
104 106
     *
107 +
     * @return void
108 +
     *
105 109
     * @phpstan-param T $entity
106 110
     */
107 111
    public function delete($entity, $andFlush = true);
@@ -109,6 +113,8 @@
Loading
109 113
    /**
110 114
     * Get the related table name.
111 115
     *
116 +
     * NEXT_MAJOR: Remove this ORM-related method from the interface.
117 +
     *
112 118
     * @return string
113 119
     */
114 120
    public function getTableName();
@@ -116,6 +122,8 @@
Loading
116 122
    /**
117 123
     * Get the DB driver connection.
118 124
     *
125 +
     * NEXT_MAJOR: Remove this ORM-related method from the interface.
126 +
     *
119 127
     * @return Connection
120 128
     */
121 129
    public function getConnection();
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