Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
10 / 12
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractContext
83.33% covered (warning)
83.33%
10 / 12
83.33% covered (warning)
83.33%
5 / 6
8.30
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSnak
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEntity
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSnakRank
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSnakStatement
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatementGuid
66.67% covered (warning)
66.67%
4 / 6
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2
3declare( strict_types = 1 );
4
5namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Context;
6
7use InvalidArgumentException;
8use Wikibase\DataModel\Entity\StatementListProvidingEntity;
9use Wikibase\DataModel\Snak\Snak;
10use Wikibase\DataModel\Statement\Statement;
11
12/**
13 * Base implementation of some Context functions,
14 * given a snak and an entity.
15 *
16 * @license GPL-2.0-or-later
17 */
18abstract class AbstractContext implements Context {
19
20    protected StatementListProvidingEntity $entity;
21
22    protected Snak $snak;
23
24    public function __construct( StatementListProvidingEntity $entity, Snak $snak ) {
25        $this->entity = $entity;
26        $this->snak = $snak;
27    }
28
29    public function getSnak(): Snak {
30        return $this->snak;
31    }
32
33    public function getEntity(): StatementListProvidingEntity {
34        return $this->entity;
35    }
36
37    // unimplemented: getType
38
39    public function getSnakRank(): ?int {
40        return null;
41    }
42
43    public function getSnakStatement(): ?Statement {
44        return null;
45    }
46
47    // unimplemented: getCursor
48
49    /** Helper function for {@link getCursor()} implementations. */
50    protected function getStatementGuid( Statement $statement ): string {
51        $guid = $statement->getGuid();
52        if ( $guid === null ) {
53            if ( defined( 'MW_PHPUNIT_TEST' ) ) {
54                // let unit tests get away with not specifying a statement GUID:
55                // much more convenient to fake it here than to add one to all tests
56                return 'Q0$DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF';
57            } else {
58                throw new InvalidArgumentException( 'Statement for Context must have a GUID' );
59            }
60        }
61        return $guid;
62    }
63
64}