Skip to content

Commit

Permalink
Merge "repo: Replace call_user_func with dynamic function call"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Feb 4, 2025
2 parents eec2d98 + a753e10 commit f3f3536
Show file tree
Hide file tree
Showing 22 changed files with 25 additions and 32 deletions.
2 changes: 1 addition & 1 deletion repo/WikibaseRepo.ServiceWiring.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
$baseDeserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services );
$deserializers = [];
foreach ( $deserializerFactoryCallbacks as $callback ) {
$deserializers[] = call_user_func( $callback, $baseDeserializerFactory );
$deserializers[] = $callback( $baseDeserializerFactory );
}
return new DispatchingDeserializer( $deserializers );
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ private function getHttpResponseForThrowingUseCase( array $routeHandler, Throwab
}

private function newHandlerWithValidRequest( array $routeData, array $validRequest ): Handler {
$routeHandler = call_user_func( $routeData['factory'] );
$routeHandler = $routeData['factory']();
$this->initHandler(
$routeHandler,
new RequestData( [
Expand Down
4 changes: 1 addition & 3 deletions repo/includes/BuilderBasedDataTypeValidatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public function getValidators( $dataTypeId ) {
throw new OutOfBoundsException( 'No validators known for data type ' . $dataTypeId );
}

$validators = call_user_func(
$this->validatorBuilders[ $dataTypeId ]
);
$validators = $this->validatorBuilders[ $dataTypeId ]();

Assert::postcondition(
is_array( $validators ),
Expand Down
2 changes: 1 addition & 1 deletion repo/includes/ChangeOp/EntityChangeOpProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function newDeserializerForEntityType( $type ) {
);
}

$deserializer = call_user_func( $this->changeOpDeserializerInstantiators[$type] );
$deserializer = $this->changeOpDeserializerInstantiators[$type]();
Assert::postcondition(
$deserializer instanceof ChangeOpDeserializer,
'changeop-deserializer-callback defined for entity type: ' . $type . ' does not instantiate ChangeOpDeserializer'
Expand Down
2 changes: 1 addition & 1 deletion repo/includes/Content/EntityContentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getContentHandlerForType( string $entityType ): EntityHandler {
}

if ( !isset( $this->entityHandlers[$entityType] ) ) {
$entityHandler = call_user_func( $this->entityHandlerFactoryCallbacks[$entityType] );
$entityHandler = $this->entityHandlerFactoryCallbacks[$entityType]();

Assert::postcondition(
$entityHandler instanceof EntityHandler,
Expand Down
2 changes: 1 addition & 1 deletion repo/includes/Content/EntityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function exportTransform( $blob, $format = null ) {
return $blob;
}

$needsTransform = call_user_func( $this->legacyExportFormatDetector, $blob, $format );
$needsTransform = ( $this->legacyExportFormatDetector )( $blob, $format );

if ( $needsTransform ) {
$format = ( $format === null ) ? $this->getDefaultFormat() : $format;
Expand Down
3 changes: 1 addition & 2 deletions repo/includes/Diff/EntityDiffVisualizerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public function newEntityDiffVisualizer( ?string $type = null, ?IContextSource $
);
}

$visualizer = call_user_func(
$this->entityDiffVisualizerInstantiators[$type],
$visualizer = $this->entityDiffVisualizerInstantiators[$type](
$context,
$this->claimDiffer,
$claimDiffView,
Expand Down
2 changes: 1 addition & 1 deletion repo/includes/EntityIdHtmlLinkFormatterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private function buildFormatters( Language $language ) {
$formatters = [];

foreach ( $this->formatterCallbacks as $type => $func ) {
$formatters[ $type ] = call_user_func( $func, $language );
$formatters[ $type ] = $func( $language );
}

return $formatters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function newEntityMetaTags(
return new DefaultMetaTagsCreator();
}

$entityMetaTags = call_user_func( $this->entityMetaTagsFactoryCallbacks[$entityType], $userLanguage );
$entityMetaTags = $this->entityMetaTagsFactoryCallbacks[$entityType]( $userLanguage );

Assert::postcondition(
$entityMetaTags instanceof EntityMetaTagsCreator,
Expand Down
3 changes: 1 addition & 2 deletions repo/includes/ParserOutput/DispatchingEntityViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function newEntityView(
throw new OutOfBoundsException( "No EntityDocumentView is registered for entity type '$entityType'" );
}

$entityView = call_user_func(
$this->entityViewFactoryCallbacks[$entityType],
$entityView = $this->entityViewFactoryCallbacks[$entityType](
$language,
$termFallbackChain,
$entity
Expand Down
3 changes: 1 addition & 2 deletions repo/includes/Rdf/EntityRdfBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ private function createEntityRdfBuilders(
$builders = [];

foreach ( $this->factoryCallbacks as $key => $callback ) {
$builders[$key] = call_user_func(
$callback,
$builders[$key] = $callback(
$flavorFlags,
$vocabulary,
$writer,
Expand Down
3 changes: 1 addition & 2 deletions repo/includes/Rdf/EntityStubRdfBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ private function createEntityRdfBuilders(
$builders = [];

foreach ( $this->factoryCallbacks as $key => $callback ) {
$builders[ $key ] = call_user_func(
$callback,
$builders[ $key ] = $callback(
$vocabulary,
$writer
);
Expand Down
3 changes: 1 addition & 2 deletions repo/includes/Rdf/ValueSnakRdfBuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ private function createValueSnakRdfBuilders(
$builders = [];

foreach ( $this->factoryCallbacks as $key => $callback ) {
$builder = call_user_func(
$callback,
$builder = $callback(
$flavorFlags,
$vocabulary,
$writer,
Expand Down
2 changes: 1 addition & 1 deletion repo/includes/Validators/MembershipValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct( array $allowed, $errorCode = 'not-allowed', $normal
*/
public function validate( $value ) {
if ( $this->normalizer !== null ) {
$value = call_user_func( $this->normalizer, $value );
$value = ( $this->normalizer )( $value );
}

if ( !in_array( $value, $this->allowed, true ) ) {
Expand Down
4 changes: 2 additions & 2 deletions repo/includes/Validators/StringLengthValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function validate( $value ) {
// wikibase-validator-description-too-short, wikibase-validator-description-too-long,
// wikibase-validator-alias-too-short, wikibase-validator-alias-too-long

$length = call_user_func( $this->measure, $value );
$length = ( $this->measure )( $value );

if ( $length < $this->minLength ) {
// XXX: having to provide an array is quite inconvenient
Expand Down Expand Up @@ -121,7 +121,7 @@ public function setOptions( array $options ) {
* @return string
*/
private function truncateValue( $value, $truncateAt = 32 ) {
$length = call_user_func( $this->measure, $value );
$length = ( $this->measure )( $value );

if ( $length > $truncateAt ) {
$value = substr( $value, 0, max( 1, $truncateAt - 3 ) ) . '...';
Expand Down
2 changes: 1 addition & 1 deletion repo/includes/ValueParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function newParser( $parserId, ParserOptions $parserOptions ) {
* @return ValueParser
*/
private function instantiateParser( $builder, ParserOptions $options ) {
$parser = call_user_func( $builder, $options );
$parser = $builder( $options );

if ( !( $parser instanceof ValueParser ) ) {
throw new LogicException( "Invalid parser builder, did not create an instance of ValueParser." );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ protected function tryUndoAction(
if ( $expectedProps ) {
foreach ( $expectedProps as $p => $pattern ) {
$func = 'get' . ucfirst( $p );
$act = call_user_func( [ $out, $func ] );
$act = $out->$func();

if ( $pattern === true ) {
$this->assertNotSame( '', $act, $p );
Expand Down
2 changes: 1 addition & 1 deletion repo/tests/phpunit/includes/Api/ApiModuleTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function newApiModule( $instantiator, $name, array $params, User $user )
if ( is_string( $instantiator ) && class_exists( $instantiator ) ) {
$module = new $instantiator( $main, $name );
} else {
$module = call_user_func( $instantiator, $main, $name );
$module = $instantiator( $main, $name );
}

return $module;
Expand Down
3 changes: 2 additions & 1 deletion repo/tests/phpunit/includes/Api/ApiUserBlockedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ public function testBlock() {
if ( !is_array( $value ) ) {
continue;
}
$value = call_user_func( ...$value );
$callable = array_shift( $value );
$value = $callable( ...$value );
}
unset( $value );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ChangeOpDeserializationAssert {
*/
public static function assertThrowsChangeOpDeserializationException( callable $callback, $errorCode ) {
try {
call_user_func( $callback );
$callback();
} catch ( ChangeOpDeserializationException $ex ) {
Assert::assertSame( $errorCode, $ex->getErrorCode() );
return;
Expand Down
5 changes: 2 additions & 3 deletions repo/tests/phpunit/includes/EntityTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function testViewFactoryCallback( $entityType ) {

$this->assertIsCallable( $callback );

$entityView = call_user_func(
$callback,
$entityView = $callback(
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
new TermLanguageFallbackChain( [], $this->createStub( ContentLanguages::class ) ),
new Item( new ItemId( 'Q123' ) )
Expand Down Expand Up @@ -88,7 +87,7 @@ public function testContentHandlerFactoryCallback( $entityType ) {
$this->assertIsCallable( $callback );

/** @var EntityHandler $entityHandler */
$entityHandler = call_user_func( $callback );
$entityHandler = $callback();

$this->assertInstanceOf( EntityHandler::class, $entityHandler );
$this->assertSame( $entityType, $entityHandler->getEntityType() );
Expand Down
2 changes: 1 addition & 1 deletion repo/tests/phpunit/includes/ValidatorBuildersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public function testDataTypeValidation( string $typeId, $value, bool $expected )
'wikibase-property' => [ $builders, 'buildPropertyValidators' ],
];

$validators = call_user_func( $validatorMap[$typeId] );
$validators = $validatorMap[$typeId]();

$this->assertValidation( $expected, $validators, $value );
}
Expand Down

0 comments on commit f3f3536

Please sign in to comment.