Conditions | 3 |
Paths | 1 |
Total Lines | 220 |
Code Lines | 105 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
249 | private function registerCallbackHandlersByConstructedInstance( $containerBuilder ) { |
||
250 | |||
251 | /** |
||
252 | * @var BlobStore |
||
253 | */ |
||
254 | $containerBuilder->registerCallback( 'BlobStore', function( $containerBuilder, $namespace, $cacheType = null, $ttl = 0 ) { |
||
255 | $containerBuilder->registerExpectedReturnType( 'BlobStore', '\Onoi\BlobStore\BlobStore' ); |
||
256 | |||
257 | $cacheFactory = $containerBuilder->create( 'CacheFactory' ); |
||
258 | |||
259 | $blobStore = new BlobStore( |
||
260 | $namespace, |
||
261 | $cacheFactory->newMediaWikiCompositeCache( $cacheType ) |
||
262 | ); |
||
263 | |||
264 | $blobStore->setNamespacePrefix( |
||
265 | $cacheFactory->getCachePrefix() |
||
266 | ); |
||
267 | |||
268 | $blobStore->setExpiryInSeconds( |
||
269 | $ttl |
||
270 | ); |
||
271 | |||
272 | $blobStore->setUsageState( |
||
273 | $cacheType !== CACHE_NONE && $cacheType !== false |
||
274 | ); |
||
275 | |||
276 | return $blobStore; |
||
277 | } ); |
||
278 | |||
279 | /** |
||
280 | * @var CachedQueryResultPrefetcher |
||
281 | */ |
||
282 | $containerBuilder->registerCallback( 'CachedQueryResultPrefetcher', function( $containerBuilder, $cacheType = null ) { |
||
283 | $containerBuilder->registerExpectedReturnType( 'CachedQueryResultPrefetcher', '\SMW\Query\Result\CachedQueryResultPrefetcher' ); |
||
284 | |||
285 | $settings = $containerBuilder->singleton( 'Settings' ); |
||
286 | $cacheType = $cacheType === null ? $settings->get( 'smwgQueryResultCacheType' ) : $cacheType; |
||
287 | |||
288 | $cachedQueryResultPrefetcher = new CachedQueryResultPrefetcher( |
||
289 | $containerBuilder->create( 'Store' ), |
||
290 | $containerBuilder->singleton( 'QueryFactory' ), |
||
291 | $containerBuilder->create( |
||
292 | 'BlobStore', |
||
293 | CachedQueryResultPrefetcher::CACHE_NAMESPACE, |
||
294 | $cacheType, |
||
295 | $settings->get( 'smwgQueryResultCacheLifetime' ) |
||
296 | ), |
||
297 | $containerBuilder->singleton( |
||
298 | 'BufferedStatsdCollector', |
||
299 | CachedQueryResultPrefetcher::STATSD_ID |
||
300 | ) |
||
301 | ); |
||
302 | |||
303 | $cachedQueryResultPrefetcher->setHashModifier( |
||
304 | $settings->get( 'smwgFulltextSearchIndexableDataTypes' ) |
||
305 | ); |
||
306 | |||
307 | $cachedQueryResultPrefetcher->setLogger( |
||
308 | $containerBuilder->singleton( 'MediaWikiLogger' ) |
||
309 | ); |
||
310 | |||
311 | $cachedQueryResultPrefetcher->setNonEmbeddedCacheLifetime( |
||
312 | $settings->get( 'smwgQueryResultNonEmbeddedCacheLifetime' ) |
||
313 | ); |
||
314 | |||
315 | return $cachedQueryResultPrefetcher; |
||
316 | } ); |
||
317 | |||
318 | /** |
||
319 | * @var CachedPropertyValuesPrefetcher |
||
320 | */ |
||
321 | $containerBuilder->registerCallback( 'CachedPropertyValuesPrefetcher', function( $containerBuilder, $cacheType = null, $ttl = 604800 ) { |
||
322 | $containerBuilder->registerExpectedReturnType( 'CachedPropertyValuesPrefetcher', CachedPropertyValuesPrefetcher::class ); |
||
323 | |||
324 | $cachedPropertyValuesPrefetcher = new CachedPropertyValuesPrefetcher( |
||
325 | $containerBuilder->create( 'Store' ), |
||
326 | $containerBuilder->create( 'BlobStore', CachedPropertyValuesPrefetcher::CACHE_NAMESPACE, $cacheType, $ttl ) |
||
327 | ); |
||
328 | |||
329 | return $cachedPropertyValuesPrefetcher; |
||
330 | } ); |
||
331 | |||
332 | /** |
||
333 | * @var BufferedStatsdCollector |
||
334 | */ |
||
335 | $containerBuilder->registerCallback( 'BufferedStatsdCollector', function( $containerBuilder, $id ) { |
||
336 | $containerBuilder->registerExpectedReturnType( 'BufferedStatsdCollector', '\SMW\Utils\BufferedStatsdCollector' ); |
||
337 | |||
338 | // Explicitly use the DB to access a SqlBagOstuff instance |
||
339 | $cacheType = CACHE_DB; |
||
340 | $ttl = 0; |
||
341 | |||
342 | $bufferedStatsdCollector = new BufferedStatsdCollector( |
||
343 | $containerBuilder->create( 'BlobStore', BufferedStatsdCollector::CACHE_NAMESPACE, $cacheType, $ttl ), |
||
344 | $id |
||
345 | ); |
||
346 | |||
347 | return $bufferedStatsdCollector; |
||
348 | } ); |
||
349 | |||
350 | /** |
||
351 | * @var PropertySpecificationLookup |
||
352 | */ |
||
353 | $containerBuilder->registerCallback( 'PropertySpecificationLookup', function( $containerBuilder ) { |
||
354 | $containerBuilder->registerExpectedReturnType( 'PropertySpecificationLookup', '\SMW\PropertySpecificationLookup' ); |
||
355 | |||
356 | $propertySpecificationLookup = new PropertySpecificationLookup( |
||
357 | $containerBuilder->singleton( 'CachedPropertyValuesPrefetcher' ), |
||
358 | $containerBuilder->singleton( 'InMemoryPoolCache' )->getPoolCacheById( PropertySpecificationLookup::POOLCACHE_ID ) |
||
359 | ); |
||
360 | |||
361 | return $propertySpecificationLookup; |
||
362 | } ); |
||
363 | |||
364 | /** |
||
365 | * @var EditProtectionValidator |
||
366 | */ |
||
367 | $containerBuilder->registerCallback( 'EditProtectionValidator', function( $containerBuilder ) { |
||
368 | $containerBuilder->registerExpectedReturnType( 'EditProtectionValidator', '\SMW\Protection\EditProtectionValidator' ); |
||
369 | |||
370 | $editProtectionValidator = new EditProtectionValidator( |
||
371 | $containerBuilder->singleton( 'CachedPropertyValuesPrefetcher' ), |
||
372 | $containerBuilder->singleton( 'InMemoryPoolCache' )->getPoolCacheById( EditProtectionValidator::POOLCACHE_ID ) |
||
373 | ); |
||
374 | |||
375 | $editProtectionValidator->setEditProtectionRight( |
||
376 | $containerBuilder->singleton( 'Settings' )->get( 'smwgEditProtectionRight' ) |
||
377 | ); |
||
378 | |||
379 | return $editProtectionValidator; |
||
380 | } ); |
||
381 | |||
382 | /** |
||
383 | * @var EditProtectionUpdater |
||
384 | */ |
||
385 | $containerBuilder->registerCallback( 'EditProtectionUpdater', function( $containerBuilder, \WikiPage $wikiPage, \User $user = null ) { |
||
386 | $containerBuilder->registerExpectedReturnType( 'EditProtectionUpdater', '\SMW\Protection\EditProtectionUpdater' ); |
||
387 | |||
388 | $editProtectionUpdater = new EditProtectionUpdater( |
||
389 | $wikiPage, |
||
390 | $user |
||
391 | ); |
||
392 | |||
393 | $editProtectionUpdater->setEditProtectionRight( |
||
394 | $containerBuilder->singleton( 'Settings' )->get( 'smwgEditProtectionRight' ) |
||
395 | ); |
||
396 | |||
397 | $editProtectionUpdater->setLogger( |
||
398 | $containerBuilder->singleton( 'MediaWikiLogger' ) |
||
399 | ); |
||
400 | |||
401 | return $editProtectionUpdater; |
||
402 | } ); |
||
403 | |||
404 | /** |
||
405 | * @var PropertyHierarchyLookup |
||
406 | */ |
||
407 | $containerBuilder->registerCallback( 'PropertyHierarchyLookup', function( $containerBuilder ) { |
||
408 | $containerBuilder->registerExpectedReturnType( 'PropertyHierarchyLookup', '\SMW\PropertyHierarchyLookup' ); |
||
409 | |||
410 | $propertyHierarchyLookup = new PropertyHierarchyLookup( |
||
411 | $containerBuilder->create( 'Store' ), |
||
412 | $containerBuilder->singleton( 'InMemoryPoolCache' )->getPoolCacheById( PropertyHierarchyLookup::POOLCACHE_ID ) |
||
413 | ); |
||
414 | |||
415 | $propertyHierarchyLookup->setLogger( |
||
416 | $containerBuilder->singleton( 'MediaWikiLogger' ) |
||
417 | ); |
||
418 | |||
419 | $propertyHierarchyLookup->setSubcategoryDepth( |
||
420 | $containerBuilder->create( 'Settings' )->get( 'smwgQSubcategoryDepth' ) |
||
421 | ); |
||
422 | |||
423 | $propertyHierarchyLookup->setSubpropertyDepth( |
||
424 | $containerBuilder->create( 'Settings' )->get( 'smwgQSubpropertyDepth' ) |
||
425 | ); |
||
426 | |||
427 | return $propertyHierarchyLookup; |
||
428 | } ); |
||
429 | |||
430 | /** |
||
431 | * @var PropertyLabelFinder |
||
432 | */ |
||
433 | $containerBuilder->registerCallback( 'PropertyLabelFinder', function( $containerBuilder ) { |
||
434 | $containerBuilder->registerExpectedReturnType( 'PropertyLabelFinder', '\SMW\PropertyLabelFinder' ); |
||
435 | |||
436 | $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage(); |
||
437 | |||
438 | $propertyLabelFinder = new PropertyLabelFinder( |
||
439 | $containerBuilder->create( 'Store' ), |
||
440 | $extraneousLanguage->getPropertyLabels(), |
||
441 | $extraneousLanguage->getCanonicalPropertyLabels(), |
||
442 | $extraneousLanguage->getCanonicalDatatypeLabels() |
||
443 | ); |
||
444 | |||
445 | return $propertyLabelFinder; |
||
446 | } ); |
||
447 | |||
448 | /** |
||
449 | * @var TempChangeOpStore |
||
450 | */ |
||
451 | $containerBuilder->registerCallback( 'TempChangeOpStore', function( $containerBuilder ) { |
||
452 | $containerBuilder->registerExpectedReturnType( 'TempChangeOpStore', '\SMW\SQLStore\ChangeOp\TempChangeOpStore' ); |
||
453 | |||
454 | $cacheFactory = $containerBuilder->create( 'CacheFactory' ); |
||
455 | $cacheType = null; |
||
456 | |||
457 | $tempChangeOpStore = new TempChangeOpStore( |
||
458 | $cacheFactory->newMediaWikiCompositeCache( $cacheType ), |
||
459 | $cacheFactory->getCachePrefix() |
||
460 | ); |
||
461 | |||
462 | $tempChangeOpStore->setLogger( |
||
463 | $containerBuilder->singleton( 'MediaWikiLogger' ) |
||
464 | ); |
||
465 | |||
466 | return $tempChangeOpStore; |
||
467 | } ); |
||
468 | } |
||
469 | |||
471 |