sonata-project / sonata-doctrine-extensions

Compare c4169aa ... +27 ... 5b4742b

Showing 18 of 49 files from the diff.

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

@@ -16,12 +16,7 @@
Loading
16 16
use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle as ForwardCompatibleSonataDoctrineBundle;
17 17
use Symfony\Component\HttpKernel\Bundle\Bundle;
18 18
19 -
@trigger_error(sprintf(
20 -
    'The %s\SonataDoctrineBundle class is deprecated since sonata-project/doctrine-extensions 1.9, to be removed in version 2.0. Use %s instead.',
21 -
    __NAMESPACE__,
22 -
    ForwardCompatibleSonataDoctrineBundle::class
23 -
), \E_USER_DEPRECATED);
24 -
19 +
// @phpstan-ignore-next-line
25 20
if (false) {
26 21
    /**
27 22
     * NEXT_MAJOR: remove this class.

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 16 files with coverage changes found.

Changes in src/Document/BasePHPCRManager.php
New
Loading file...
Changes in src/Bridge/Symfony/DependencyInjection/SonataDoctrineExtension.php
+1
Loading file...
Changes in src/Adapter/AdapterChain.php
+1
Loading file...
Changes in src/Bridge/Symfony/DependencyInjection/Compiler/AdapterCompilerPass.php
+1
Loading file...
Changes in src/Document/BaseDocumentManager.php
+2
Loading file...
Changes in src/Mapper/Builder/ColumnDefinitionBuilder.php
+1
Loading file...
Changes in src/Bridge/Symfony/SonataDoctrineBundle.php
+1
Loading file...
Changes in src/Model/ManagerInterface.php
+1
Loading file...
Changes in src/Adapter/PHPCR/DoctrinePHPCRAdapter.php
+1
Loading file...
Changes in src/Mapper/Builder/OptionsBuilder.php
+1
Loading file...
Changes in src/Mapper/ORM/DoctrineORMMapper.php
+2
+1
Loading file...
Changes in src/Mapper/DoctrineCollector.php
+3
Loading file...
Changes in src/Bridge/Symfony/DependencyInjection/Compiler/MapperCompilerPass.php
+1
Loading file...
Changes in src/Adapter/ORM/DoctrineORMAdapter.php
+1
Loading file...
Changes in src/Entity/BaseEntityManager.php
+1
Loading file...
Changes in src/Model/BaseManager.php
+8
Loading file...

29 Commits

Hiding 1 contexual commits Hiding 1 contexual commits
-6
-3
-3
+31
+16
+15
Hiding 3 contexual commits
+40
+32
+8
Files Complexity Coverage
src ø 0.66% 63.61%
Project Totals (27 files) 211 63.61%
Loading