Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WikibaseRepoOnParserOutputUpdaterConstructionHookHandler | |
90.91% |
10 / 11 |
|
50.00% |
1 / 2 |
4.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| onWikibaseRepoOnParserOutputUpdaterConstruction | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace EntitySchema\Wikibase\Hooks; |
| 6 | |
| 7 | use EntitySchema\Wikibase\ParserOutputUpdater\EntitySchemaStatementDataUpdater; |
| 8 | use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; |
| 9 | use Wikibase\Repo\ParserOutput\CompositeStatementDataUpdater; |
| 10 | use Wikimedia\Assert\Assert; |
| 11 | |
| 12 | /** |
| 13 | * @license GPL-2.0-or-later |
| 14 | */ |
| 15 | class WikibaseRepoOnParserOutputUpdaterConstructionHookHandler { |
| 16 | |
| 17 | private bool $entitySchemaIsRepo; |
| 18 | private ?PropertyDataTypeLookup $propertyDataTypeLookup; |
| 19 | |
| 20 | public function __construct( |
| 21 | bool $entitySchemaIsRepo, |
| 22 | ?PropertyDataTypeLookup $propertyDataTypeLookup |
| 23 | ) { |
| 24 | $this->entitySchemaIsRepo = $entitySchemaIsRepo; |
| 25 | if ( $entitySchemaIsRepo ) { |
| 26 | Assert::parameterType( PropertyDataTypeLookup::class, $propertyDataTypeLookup, '$propertyDataTypeLookup' ); |
| 27 | } |
| 28 | $this->propertyDataTypeLookup = $propertyDataTypeLookup; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Callback for the WikibaseRepoOnParserOutputUpdaterConstruction hook. |
| 33 | */ |
| 34 | public function onWikibaseRepoOnParserOutputUpdaterConstruction( |
| 35 | CompositeStatementDataUpdater $statementUpdater, |
| 36 | array &$entityUpdaters |
| 37 | ): void { |
| 38 | if ( !$this->entitySchemaIsRepo ) { |
| 39 | return; |
| 40 | } |
| 41 | $statementUpdater->addUpdater( |
| 42 | new EntitySchemaStatementDataUpdater( |
| 43 | // @phan-suppress-next-line PhanTypeMismatchArgumentNullable |
| 44 | $this->propertyDataTypeLookup |
| 45 | ) |
| 46 | ); |
| 47 | } |
| 48 | } |