Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
SpecialEntitiesWithoutPageFactory
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 6
110
0.00% covered (danger)
0.00%
0 / 1
 newFromGlobalState
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 newSpecialEntitiesWithoutLabel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newSpecialEntitiesWithoutDescription
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 createSpecialEntitiesWithoutLabel
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
12
 createSpecialEntitiesWithoutDescription
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Wikibase\Search\Elastic;
4
5use Wikibase\DataModel\Term\DescriptionsProvider;
6use Wikibase\DataModel\Term\LabelsProvider;
7use Wikibase\Lib\ContentLanguages;
8use Wikibase\Lib\EntityFactory;
9use Wikibase\Lib\LanguageNameLookup;
10use Wikibase\Lib\Store\EntityNamespaceLookup;
11use Wikibase\Lib\TermIndexEntry;
12use Wikibase\Repo\WikibaseRepo;
13
14/**
15 * Factory to create special pages.
16 *
17 * @license GPL-2.0-or-later
18 * @author Bene* < benestar.wikimedia@gmail.com >
19 */
20class SpecialEntitiesWithoutPageFactory {
21
22    private static function newFromGlobalState(): self {
23        return new self(
24            WikibaseRepo::getLocalEntityTypes(),
25            WikibaseRepo::getTermsLanguages(),
26            WikibaseRepo::getLanguageNameLookupFactory()->getForAutonyms(),
27            WikibaseRepo::getEntityFactory(),
28            WikibaseRepo::getEntityNamespaceLookup()
29        );
30    }
31
32    public static function newSpecialEntitiesWithoutLabel(): SpecialEntitiesWithoutPage {
33        return self::newFromGlobalState()->createSpecialEntitiesWithoutLabel();
34    }
35
36    public static function newSpecialEntitiesWithoutDescription(): SpecialEntitiesWithoutPage {
37        return self::newFromGlobalState()->createSpecialEntitiesWithoutDescription();
38    }
39
40    /**
41     * @param string[] $entityTypes
42     * @param ContentLanguages $termsLanguages
43     * @param LanguageNameLookup $languageNameLookup
44     * @param EntityFactory $entityFactory
45     * @param EntityNamespaceLookup $entityNamespaceLookup
46     */
47    public function __construct(
48        private readonly array $entityTypes,
49        private readonly ContentLanguages $termsLanguages,
50        private readonly LanguageNameLookup $languageNameLookup,
51        private readonly EntityFactory $entityFactory,
52        private readonly EntityNamespaceLookup $entityNamespaceLookup,
53    ) {
54    }
55
56    public function createSpecialEntitiesWithoutLabel(): SpecialEntitiesWithoutPage {
57        $supportedEntityTypes = [];
58        foreach ( $this->entityTypes as $entityType ) {
59            if ( $this->entityFactory->newEmpty( $entityType ) instanceof LabelsProvider ) {
60                $supportedEntityTypes[] = $entityType;
61            }
62        }
63        return new SpecialEntitiesWithoutPage(
64            'EntitiesWithoutLabel',
65            TermIndexEntry::TYPE_LABEL,
66            'wikibasecirrus-entitieswithoutlabel-legend',
67            $supportedEntityTypes,
68            $this->termsLanguages,
69            $this->languageNameLookup,
70            $this->entityNamespaceLookup
71        );
72    }
73
74    public function createSpecialEntitiesWithoutDescription(): SpecialEntitiesWithoutPage {
75        $supportedEntityTypes = [];
76        foreach ( $this->entityTypes as $entityType ) {
77            if ( $this->entityFactory->newEmpty( $entityType ) instanceof DescriptionsProvider ) {
78                $supportedEntityTypes[] = $entityType;
79            }
80        }
81        return new SpecialEntitiesWithoutPage(
82            'EntitiesWithoutDescription',
83            TermIndexEntry::TYPE_DESCRIPTION,
84            'wikibasecirrus-entitieswithoutdescription-legend',
85            $supportedEntityTypes,
86            $this->termsLanguages,
87            $this->languageNameLookup,
88            $this->entityNamespaceLookup
89        );
90    }
91
92}