Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
EntityRevisionLookupLexemeRetriever
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLexeme
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getLexemeWriteModel
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare( strict_types = 1 );
4
5namespace Wikibase\Lexeme\DataAccess\Store;
6
7use Wikibase\Lexeme\Domain\Model\Lexeme as LexemeWriteModel;
8use Wikibase\Lexeme\Domain\Model\LexemeId;
9use Wikibase\Lexeme\Domain\Model\ReadModel\Lexeme;
10use Wikibase\Lexeme\Domain\Services\LexemeRetriever;
11use Wikibase\Lexeme\Domain\Services\LexemeWriteModelRetriever;
12use Wikibase\Lib\Store\EntityRevisionLookup;
13use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
14
15/**
16 * @license GPL-2.0-or-later
17 */
18class EntityRevisionLookupLexemeRetriever implements LexemeRetriever, LexemeWriteModelRetriever {
19
20    public function __construct(
21        private EntityRevisionLookup $entityRevisionLookup,
22        private LexemeReadModelConverter $lexemeReadModelConverter,
23    ) {
24    }
25
26    public function getLexeme( LexemeId $lexemeId ): ?Lexeme {
27        $lexeme = $this->getLexemeWriteModel( $lexemeId );
28
29        if ( $lexeme === null ) {
30            return null;
31        }
32
33        return $this->lexemeReadModelConverter->convert( $lexeme );
34    }
35
36    public function getLexemeWriteModel( LexemeId $lexemeId ): ?LexemeWriteModel {
37        try {
38            $entityRevision = $this->entityRevisionLookup->getEntityRevision( $lexemeId );
39        } catch ( RevisionedUnresolvedRedirectException ) {
40            return null;
41        }
42
43        if ( !$entityRevision ) {
44            return null;
45        }
46
47        /** @var LexemeWriteModel $lexeme */
48        $lexeme = $entityRevision->getEntity();
49        '@phan-var LexemeWriteModel $lexeme';
50
51        return $lexeme;
52    }
53
54}