diff options
author | Umherirrender <umherirrender_de.wp@web.de> | 2022-06-17 23:38:00 +0200 |
---|---|---|
committer | Umherirrender <umherirrender_de.wp@web.de> | 2022-06-18 09:34:36 +0200 |
commit | 69b6c4983d06442446be851234b35f708d9bac07 (patch) | |
tree | 1abaffe910164b832e6241a0a00408731f66a7d6 | |
parent | 05a3dd8bfe976b9bac4dd292561f66ef28748838 (diff) | |
download | mediawikicore-69b6c4983d06442446be851234b35f708d9bac07.tar.gz mediawikicore-69b6c4983d06442446be851234b35f708d9bac07.zip |
Pass array to Assert::parameterType when asserting multiple types
Change-Id: I6db78db18b2d8982ce5158f44c03bfdb8d48f97c
-rw-r--r-- | includes/Revision/RevisionSlots.php | 2 | ||||
-rw-r--r-- | includes/Revision/SlotRecord.php | 2 | ||||
-rw-r--r-- | includes/diff/SlotDiffRenderer.php | 9 | ||||
-rw-r--r-- | includes/json/JsonCodec.php | 2 | ||||
-rw-r--r-- | includes/libs/ParamValidator/ParamValidator.php | 4 | ||||
-rw-r--r-- | includes/page/PageSelectQueryBuilder.php | 4 | ||||
-rw-r--r-- | includes/user/UserSelectQueryBuilder.php | 4 |
7 files changed, 14 insertions, 13 deletions
diff --git a/includes/Revision/RevisionSlots.php b/includes/Revision/RevisionSlots.php index f739cc291e33..f3b1a3af97e3 100644 --- a/includes/Revision/RevisionSlots.php +++ b/includes/Revision/RevisionSlots.php @@ -51,7 +51,7 @@ class RevisionSlots { * or a callback that returns such a structure. */ public function __construct( $slots ) { - Assert::parameterType( 'array|callable', $slots, '$slots' ); + Assert::parameterType( [ 'array', 'callable' ], $slots, '$slots' ); if ( is_callable( $slots ) ) { $this->slots = $slots; diff --git a/includes/Revision/SlotRecord.php b/includes/Revision/SlotRecord.php index d49ee1d25b10..2059dd3dcd1b 100644 --- a/includes/Revision/SlotRecord.php +++ b/includes/Revision/SlotRecord.php @@ -256,7 +256,7 @@ class SlotRecord { * in revision history. */ public function __construct( \stdClass $row, $content, bool $derived = false ) { - Assert::parameterType( 'Content|callable', $content, '$content' ); + Assert::parameterType( [ 'Content', 'callable' ], $content, '$content' ); Assert::parameter( property_exists( $row, 'slot_revision_id' ), diff --git a/includes/diff/SlotDiffRenderer.php b/includes/diff/SlotDiffRenderer.php index f7a422adc150..3592d5475239 100644 --- a/includes/diff/SlotDiffRenderer.php +++ b/includes/diff/SlotDiffRenderer.php @@ -83,11 +83,12 @@ abstract class SlotDiffRenderer { } if ( $allowedClasses ) { - if ( is_array( $allowedClasses ) ) { - $allowedClasses = implode( '|', $allowedClasses ); + if ( !is_array( $allowedClasses ) ) { + $allowedClasses = explode( '|', $allowedClasses ); } - Assert::parameterType( $allowedClasses . '|null', $oldContent, '$oldContent' ); - Assert::parameterType( $allowedClasses . '|null', $newContent, '$newContent' ); + $allowedClasses[] = 'null'; + Assert::parameterType( $allowedClasses, $oldContent, '$oldContent' ); + Assert::parameterType( $allowedClasses, $newContent, '$newContent' ); } if ( !$oldContent ) { diff --git a/includes/json/JsonCodec.php b/includes/json/JsonCodec.php index 617fe63b2f85..13fc7734d54b 100644 --- a/includes/json/JsonCodec.php +++ b/includes/json/JsonCodec.php @@ -36,7 +36,7 @@ use Wikimedia\Assert\Assert; class JsonCodec implements JsonUnserializer, JsonSerializer { public function unserialize( $json, string $expectedClass = null ) { - Assert::parameterType( 'object|array|string', $json, '$json' ); + Assert::parameterType( [ 'object', 'array', 'string' ], $json, '$json' ); Assert::precondition( !$expectedClass || is_subclass_of( $expectedClass, JsonUnserializable::class ), '$expectedClass parameter must be subclass of JsonUnserializable, got ' . $expectedClass diff --git a/includes/libs/ParamValidator/ParamValidator.php b/includes/libs/ParamValidator/ParamValidator.php index f5f8ef2fe929..ec5ece8119a9 100644 --- a/includes/libs/ParamValidator/ParamValidator.php +++ b/includes/libs/ParamValidator/ParamValidator.php @@ -267,7 +267,7 @@ class ParamValidator { */ public function addTypeDef( $name, $typeDef ) { Assert::parameterType( - implode( '|', [ TypeDef::class, 'array' ] ), + [ TypeDef::class, 'array' ], $typeDef, '$typeDef' ); @@ -286,7 +286,7 @@ class ParamValidator { */ public function overrideTypeDef( $name, $typeDef ) { Assert::parameterType( - implode( '|', [ TypeDef::class, 'array', 'null' ] ), + [ TypeDef::class, 'array', 'null' ], $typeDef, '$typeDef' ); diff --git a/includes/page/PageSelectQueryBuilder.php b/includes/page/PageSelectQueryBuilder.php index 1319db16d305..f32ad847b5ea 100644 --- a/includes/page/PageSelectQueryBuilder.php +++ b/includes/page/PageSelectQueryBuilder.php @@ -41,7 +41,7 @@ class PageSelectQueryBuilder extends SelectQueryBuilder { * @return PageSelectQueryBuilder */ public function wherePageIds( $pageIds ): self { - Assert::parameterType( 'integer|array', $pageIds, '$pageIds' ); + Assert::parameterType( [ 'integer', 'array' ], $pageIds, '$pageIds' ); if ( $pageIds ) { $this->conds( [ 'page_id' => $pageIds ] ); @@ -87,7 +87,7 @@ class PageSelectQueryBuilder extends SelectQueryBuilder { * @return PageSelectQueryBuilder */ public function whereTitles( int $namespace, $pageTitles ): self { - Assert::parameterType( 'string|array', $pageTitles, '$pageTitles' ); + Assert::parameterType( [ 'string', 'array' ], $pageTitles, '$pageTitles' ); $this->conds( [ 'page_namespace' => $namespace ] ); $this->conds( [ 'page_title' => $pageTitles ] ); return $this; diff --git a/includes/user/UserSelectQueryBuilder.php b/includes/user/UserSelectQueryBuilder.php index 120c91632461..3d54273ad604 100644 --- a/includes/user/UserSelectQueryBuilder.php +++ b/includes/user/UserSelectQueryBuilder.php @@ -49,7 +49,7 @@ class UserSelectQueryBuilder extends SelectQueryBuilder { * @return UserSelectQueryBuilder */ public function whereUserIds( $userIds ): self { - Assert::parameterType( 'integer|array', $userIds, '$userIds' ); + Assert::parameterType( [ 'integer', 'array' ], $userIds, '$userIds' ); $this->conds( [ 'actor_user' => $userIds ] ); return $this; } @@ -71,7 +71,7 @@ class UserSelectQueryBuilder extends SelectQueryBuilder { * @return UserSelectQueryBuilder */ public function whereUserNames( $userNames ): self { - Assert::parameterType( 'string|array', $userNames, '$userIds' ); + Assert::parameterType( [ 'string', 'array' ], $userNames, '$userIds' ); $userNames = array_map( function ( $name ) { return $this->actorStore->normalizeUserName( (string)$name ); }, (array)$userNames ); |