Skip to content

Commit e4c8c0e

Browse files
franmomuphansys
authored andcommitted
Specify array configuration in extensions
1 parent 0c41b00 commit e4c8c0e

File tree

11 files changed

+140
-32
lines changed

11 files changed

+140
-32
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -630,31 +630,6 @@ parameters:
630630
count: 4
631631
path: src/Translatable/TranslatableListener.php
632632

633-
-
634-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:insertTranslationRecord\\(\\)\\.$#"
635-
count: 1
636-
path: src/Translatable/TranslatableListener.php
637-
638-
-
639-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:loadTranslations\\(\\)\\.$#"
640-
count: 1
641-
path: src/Translatable/TranslatableListener.php
642-
643-
-
644-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:removeAssociatedTranslations\\(\\)\\.$#"
645-
count: 1
646-
path: src/Translatable/TranslatableListener.php
647-
648-
-
649-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:setTranslationValue\\(\\)\\.$#"
650-
count: 1
651-
path: src/Translatable/TranslatableListener.php
652-
653-
-
654-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:usesPersonalTranslation\\(\\)\\.$#"
655-
count: 2
656-
path: src/Translatable/TranslatableListener.php
657-
658633
-
659634
message: "#^Negated boolean expression is always false\\.$#"
660635
count: 1

src/Loggable/LoggableListener.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Doctrine\Common\EventArgs;
1313
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
14+
use Doctrine\Persistence\ObjectManager;
1415
use Gedmo\Loggable\Mapping\Event\LoggableAdapter;
1516
use Gedmo\Mapping\MappedEventSubscriber;
1617
use Gedmo\Tool\Wrapper\AbstractWrapper;
@@ -20,6 +21,17 @@
2021
*
2122
* @author Boussekeyt Jules <[email protected]>
2223
* @author Gediminas Morkevicius <[email protected]>
24+
*
25+
* @phpstan-type LoggableConfiguration = array{
26+
* loggable?: bool,
27+
* logEntryClass?: class-string,
28+
* useObjectClass?: class-string,
29+
* versioned?: string[],
30+
* }
31+
*
32+
* @phpstan-method LoggableConfiguration getConfiguration(ObjectManager $objectManager, $class)
33+
*
34+
* @method LoggableAdapter getEventAdapter(EventArgs $args)
2335
*/
2436
class LoggableListener extends MappedEventSubscriber
2537
{

src/References/ReferencesListener.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@
2121
* @author Gediminas Morkevicius <[email protected]>
2222
* @author Bulat Shakirzyanov <[email protected]>
2323
* @author Jonathan H. Wage <[email protected]>
24+
*
25+
* @phpstan-type ReferenceConfiguration = array{
26+
* field?: string,
27+
* type?: string,
28+
* class?: class-string,
29+
* identifier?: string,
30+
* mappedBy?: string,
31+
* inversedBy?: string,
32+
* }
33+
*
34+
* @phpstan-type ReferencesConfiguration = array{
35+
* referenceMany?: array<string, ReferenceConfiguration>,
36+
* referenceManyEmbed?: array<string, ReferenceConfiguration>,
37+
* referenceOne?: array<string, ReferenceConfiguration>,
38+
* useObjectClass?: class-string,
39+
* }
40+
*
41+
* @phpstan-method ReferencesConfiguration getConfiguration(ObjectManager $objectManager, $class)
2442
*/
2543
class ReferencesListener extends MappedEventSubscriber
2644
{

src/Sluggable/Mapping/Event/SluggableAdapter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
use Doctrine\Persistence\Mapping\ClassMetadata;
1313
use Gedmo\Mapping\Event\AdapterInterface;
14+
use Gedmo\Sluggable\SluggableListener;
1415

1516
/**
1617
* Doctrine event adapter for the Sluggable extension.
1718
*
1819
* @author Gediminas Morkevicius <[email protected]>
20+
*
21+
* @phpstan-import-type SluggableConfiguration from SluggableListener
1922
*/
2023
interface SluggableAdapter extends AdapterInterface
2124
{
@@ -25,6 +28,7 @@ interface SluggableAdapter extends AdapterInterface
2528
* @param object $object
2629
* @param ClassMetadata $meta
2730
* @param string $slug
31+
* @phpstan-param SluggableConfiguration $config
2832
*
2933
* @return array
3034
*/
@@ -36,6 +40,7 @@ public function getSimilarSlugs($object, $meta, array $config, $slug);
3640
* @param object $object
3741
* @param string $target
3842
* @param string $replacement
43+
* @phpstan-param SluggableConfiguration $config
3944
*
4045
* @return int the number of updated records
4146
*/
@@ -48,6 +53,7 @@ public function replaceRelative($object, array $config, $target, $replacement);
4853
* @param object $object
4954
* @param string $target
5055
* @param string $replacement
56+
* @phpstan-param SluggableConfiguration $config
5157
*
5258
* @return int the number of updated records
5359
*/

src/Sluggable/SluggableListener.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,39 @@
2727
*
2828
* @author Gediminas Morkevicius <[email protected]>
2929
* @author Klein Florian <[email protected]>
30+
*
31+
* @phpstan-type SluggableConfiguration = array{
32+
* mappedBy?: string,
33+
* pathSeparator?: string,
34+
* slug?: string,
35+
* slugs?: array<string, array{
36+
* fields?: string[],
37+
* slug?: string,
38+
* style?: string,
39+
* dateFormat?: string,
40+
* updatable?: bool,
41+
* unique?: bool,
42+
* unique_base?: string,
43+
* separator?: string,
44+
* prefix?: string,
45+
* suffix?: string,
46+
* handlers?: array<class-string, array{
47+
* mappedBy?: string,
48+
* inverseSlugField?: string,
49+
* parentRelationField?: string,
50+
* relationClass?: class-string,
51+
* relationField?: string,
52+
* relationSlugField?: string,
53+
* separator?: string,
54+
* }>,
55+
* }>,
56+
* unique?: bool,
57+
* useObjectClass?: class-string,
58+
* }
59+
*
60+
* @phpstan-method SluggableConfiguration getConfiguration(ObjectManager $objectManager, $class)
61+
*
62+
* @method SluggableAdapter getEventAdapter(EventArgs $args)
3063
*/
3164
class SluggableListener extends MappedEventSubscriber
3265
{

src/Sortable/Mapping/Event/Adapter/ORM.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
use Doctrine\Persistence\Mapping\ClassMetadata;
1414
use Gedmo\Mapping\Event\Adapter\ORM as BaseAdapterORM;
1515
use Gedmo\Sortable\Mapping\Event\SortableAdapter;
16+
use Gedmo\Sortable\SortableListener;
1617

1718
/**
1819
* Doctrine event adapter for ORM adapted
1920
* for sortable behavior
2021
*
2122
* @author Lukas Botsch <[email protected]>
23+
*
24+
* @phpstan-import-type SortableRelocation from SortableListener
2225
*/
2326
final class ORM extends BaseAdapterORM implements SortableAdapter
2427
{
@@ -48,6 +51,7 @@ public function getMaxPosition(array $config, $meta, $groups)
4851
* @param array $relocation
4952
* @param array $delta
5053
* @param array $config
54+
* @phpstan-param SortableRelocation $relocation
5155
*
5256
* @return void
5357
*/

src/Sortable/SortableListener.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\Common\Util\ClassUtils;
1515
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
1616
use Doctrine\Persistence\Mapping\ClassMetadata;
17+
use Doctrine\Persistence\ObjectManager;
1718
use Gedmo\Mapping\MappedEventSubscriber;
1819
use Gedmo\Sortable\Mapping\Event\SortableAdapter;
1920
use ProxyManager\Proxy\GhostObjectInterface;
@@ -26,11 +27,33 @@
2627
* since it does some additional calculations on persisted objects.
2728
*
2829
* @author Lukas Botsch <[email protected]>
30+
*
31+
* @phpstan-type SortableConfiguration = array{
32+
* groups?: string[],
33+
* position?: string,
34+
* useObjectClass?: class-string,
35+
* }
36+
*
37+
* @phpstan-type SortableRelocation = array{
38+
* name?: class-string,
39+
* groups?: mixed[],
40+
* deltas?: array<array{
41+
* delta: int,
42+
* exclude: int[],
43+
* start: int,
44+
* stop: int,
45+
* }>,
46+
* }
47+
*
48+
* @phpstan-method SortableConfiguration getConfiguration(ObjectManager $objectManager, $class)
49+
*
50+
* @method SortableAdapter getEventAdapter(EventArgs $args)
2951
*/
3052
class SortableListener extends MappedEventSubscriber
3153
{
3254
/**
3355
* @var array<string, array<string, mixed>>
56+
* @phpstan-var array<string, SortableRelocation>
3457
*/
3558
private $relocations = [];
3659

src/Translatable/Entity/Repository/TranslationRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public function findTranslations($entity)
164164
* @param string $field
165165
* @param string $value
166166
* @param string $class
167+
* @phpstan-param class-string $class
167168
*
168169
* @return object instance of $class or null if not found
169170
*/

src/Translatable/TranslatableListener.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\ORM\ORMInvalidArgumentException;
1515
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
1616
use Doctrine\Persistence\Mapping\ClassMetadata;
17+
use Doctrine\Persistence\ObjectManager;
1718
use Gedmo\Mapping\MappedEventSubscriber;
1819
use Gedmo\Tool\Wrapper\AbstractWrapper;
1920
use Gedmo\Translatable\Mapping\Event\TranslatableAdapter;
@@ -31,6 +32,18 @@
3132
* the caching is activated for metadata
3233
*
3334
* @author Gediminas Morkevicius <[email protected]>
35+
*
36+
* @phpstan-type TranslatableConfiguration = array{
37+
* fields?: string[],
38+
* fallback?: array<string, bool>,
39+
* locale?: string,
40+
* translationClass?: class-string,
41+
* useObjectClass?: class-string,
42+
* }
43+
*
44+
* @phpstan-method TranslatableConfiguration getConfiguration(ObjectManager $objectManager, $class)
45+
*
46+
* @method TranslatableAdapter getEventAdapter(EventArgs $args)
3447
*/
3548
class TranslatableListener extends MappedEventSubscriber
3649
{

src/Tree/Entity/Repository/NestedTreeRepository.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -921,13 +921,9 @@ private function verifyTree(array &$errors, ?object $root = null): void
921921

922922
$identifier = $meta->getSingleIdentifierFieldName();
923923
if (isset($config['root'])) {
924-
if (isset($config['root'])) {
925-
$rootId = $meta->getReflectionProperty($config['root'])->getValue($root);
926-
if (is_object($rootId)) {
927-
$rootId = $meta->getReflectionProperty($identifier)->getValue($rootId);
928-
}
929-
} else {
930-
$rootId = null;
924+
$rootId = $meta->getReflectionProperty($config['root'])->getValue($root);
925+
if (is_object($rootId)) {
926+
$rootId = $meta->getReflectionProperty($identifier)->getValue($rootId);
931927
}
932928
} else {
933929
$rootId = null;

0 commit comments

Comments
 (0)