Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LexemeRdfBuilder
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
 addEntity
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace Wikibase\Lexeme\Presentation\Rdf;
4
5use Wikibase\DataModel\Entity\EntityDocument;
6use Wikibase\Repo\Rdf\EntityRdfBuilder;
7use Wikibase\Repo\Rdf\FullStatementRdfBuilderFactory;
8use Wikibase\Repo\Rdf\RdfProducer;
9use Wikibase\Repo\Rdf\TruthyStatementRdfBuilderFactory;
10
11/**
12 * @license GPL-2.0-or-later
13 */
14class LexemeRdfBuilder implements EntityRdfBuilder {
15
16    private ?EntityRdfBuilder $truthyStatementRdfBuilder = null;
17    private ?EntityRdfBuilder $fullStatementRdfBuilder = null;
18    private EntityRdfBuilder $lexemeSpecificComponentsRdfBuilder;
19
20    public function __construct(
21        int $flavorFlags,
22        TruthyStatementRdfBuilderFactory $truthyStatementRdfBuilderFactory,
23        FullStatementRdfBuilderFactory $fullStatementRdfBuilderFactory,
24        EntityRdfBuilder $lexemeSpecificComponentsRdfBuilder
25    ) {
26        if ( $flavorFlags & RdfProducer::PRODUCE_TRUTHY_STATEMENTS ) {
27            $this->truthyStatementRdfBuilder = $truthyStatementRdfBuilderFactory->getTruthyStatementRdfBuilder(
28                $flavorFlags
29            );
30        }
31        if ( $flavorFlags & RdfProducer::PRODUCE_ALL_STATEMENTS ) {
32            $fullStatementRdfBuilder = $fullStatementRdfBuilderFactory->getFullStatementRdfBuilder(
33                $flavorFlags
34            );
35            $this->fullStatementRdfBuilder = $fullStatementRdfBuilder;
36        }
37        $this->lexemeSpecificComponentsRdfBuilder = $lexemeSpecificComponentsRdfBuilder;
38    }
39
40    public function addEntity( EntityDocument $entity ): void {
41        if ( $this->truthyStatementRdfBuilder ) {
42            $this->truthyStatementRdfBuilder->addEntity( $entity );
43        }
44        if ( $this->fullStatementRdfBuilder ) {
45            $this->fullStatementRdfBuilder->addEntity( $entity );
46        }
47        $this->lexemeSpecificComponentsRdfBuilder->addEntity( $entity );
48    }
49}