Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 40
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 / 40
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 / 5
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     * @var string[]
42     */
43    private $entityTypes;
44    /**
45     * @var ContentLanguages
46     */
47    private $termsLanguages;
48    /**
49     * @var LanguageNameLookup
50     */
51    private $languageNameLookup;
52    /**
53     * @var EntityFactory
54     */
55    private $entityFactory;
56    /**
57     * @var EntityNamespaceLookup
58     */
59    private $entityNamespaceLookup;
60
61    /**
62     * @param string[] $entityTypes
63     * @param ContentLanguages $termsLanguages
64     * @param LanguageNameLookup $languageNameLookup
65     * @param EntityFactory $entityFactory
66     * @param EntityNamespaceLookup $entityNamespaceLookup
67     */
68    public function __construct(
69        array $entityTypes,
70        ContentLanguages $termsLanguages,
71        LanguageNameLookup $languageNameLookup,
72        EntityFactory $entityFactory,
73        EntityNamespaceLookup $entityNamespaceLookup
74    ) {
75        $this->entityTypes = $entityTypes;
76        $this->termsLanguages = $termsLanguages;
77        $this->languageNameLookup = $languageNameLookup;
78        $this->entityFactory = $entityFactory;
79        $this->entityNamespaceLookup = $entityNamespaceLookup;
80    }
81
82    public function createSpecialEntitiesWithoutLabel(): SpecialEntitiesWithoutPage {
83        $supportedEntityTypes = [];
84        foreach ( $this->entityTypes as $entityType ) {
85            if ( $this->entityFactory->newEmpty( $entityType ) instanceof LabelsProvider ) {
86                $supportedEntityTypes[] = $entityType;
87            }
88        }
89        return new SpecialEntitiesWithoutPage(
90            'EntitiesWithoutLabel',
91            TermIndexEntry::TYPE_LABEL,
92            'wikibasecirrus-entitieswithoutlabel-legend',
93            $supportedEntityTypes,
94            $this->termsLanguages,
95            $this->languageNameLookup,
96            $this->entityNamespaceLookup
97        );
98    }
99
100    public function createSpecialEntitiesWithoutDescription(): SpecialEntitiesWithoutPage {
101        $supportedEntityTypes = [];
102        foreach ( $this->entityTypes as $entityType ) {
103            if ( $this->entityFactory->newEmpty( $entityType ) instanceof DescriptionsProvider ) {
104                $supportedEntityTypes[] = $entityType;
105            }
106        }
107        return new SpecialEntitiesWithoutPage(
108            'EntitiesWithoutDescription',
109            TermIndexEntry::TYPE_DESCRIPTION,
110            'wikibasecirrus-entitieswithoutdescription-legend',
111            $supportedEntityTypes,
112            $this->termsLanguages,
113            $this->languageNameLookup,
114            $this->entityNamespaceLookup
115        );
116    }
117
118}