Completed
Push — master ( a440d3...fc9fa3 )
by
unknown
08:37 queued 13s
created

OutputPageEntityViewChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare( strict_types=1 );
4
5
namespace Wikibase\Repo\Hooks\Helpers;
6
7
use OutputPage;
8
use Wikibase\Repo\Content\EntityContentFactory;
9
10
/**
11
 * @license GPL-2.0-or-later
12
 */
13
class OutputPageEntityViewChecker {
14
15
	private $entityContentFactory;
16
17
	public function __construct( EntityContentFactory $entityContentFactory ) {
18
		$this->entityContentFactory = $entityContentFactory;
19
	}
20
21
	public function hasEntityView( OutputPage $out ): bool {
22
		return $this->isEntityArticlePage( $out ) || $this->hasEntityId( $out );
23
	}
24
25
	private function isEntityArticlePage( OutputPage $out ): bool {
26
		$title = $out->getTitle();
27
28
		return $out->isArticle() && $title &&
29
			$this->entityContentFactory->isEntityContentModel( $title->getContentModel() );
30
	}
31
32
	private function hasEntityId( OutputPage $out ): bool {
33
		return array_key_exists( 'wbEntityId', $out->getJsConfigVars() );
34
	}
35
36
}
37