Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.84% |
7 / 19 |
|
8.33% |
1 / 12 |
CRAP | |
0.00% |
0 / 1 |
| PPNode_Hash_Attr | |
38.89% |
7 / 18 |
|
8.33% |
1 / 12 |
51.57 | |
0.00% |
0 / 1 |
| __construct | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
2.01 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getNextSibling | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getChildren | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFirstChild | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getChildrenOfType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLength | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| item | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| splitArg | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| splitExt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| splitHeading | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @ingroup Parser |
| 6 | */ |
| 7 | |
| 8 | namespace MediaWiki\Parser; |
| 9 | |
| 10 | use InvalidArgumentException; |
| 11 | use LogicException; |
| 12 | use Stringable; |
| 13 | |
| 14 | /** |
| 15 | * @ingroup Parser |
| 16 | */ |
| 17 | // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps |
| 18 | class PPNode_Hash_Attr implements Stringable, PPNode { |
| 19 | |
| 20 | /** @var string */ |
| 21 | public $name; |
| 22 | /** @var string */ |
| 23 | public $value; |
| 24 | /** @var array */ |
| 25 | private $store; |
| 26 | /** @var int */ |
| 27 | private $index; |
| 28 | |
| 29 | /** |
| 30 | * Construct an object using the data from $store[$index]. The rest of the |
| 31 | * store array can be accessed via getNextSibling(). |
| 32 | * |
| 33 | * @param array $store |
| 34 | * @param int $index |
| 35 | */ |
| 36 | public function __construct( array $store, $index ) { |
| 37 | $descriptor = $store[$index]; |
| 38 | if ( $descriptor[PPNode_Hash_Tree::NAME][0] !== '@' ) { |
| 39 | throw new InvalidArgumentException( __METHOD__ . ': invalid name in attribute descriptor' ); |
| 40 | } |
| 41 | $this->name = substr( $descriptor[PPNode_Hash_Tree::NAME], 1 ); |
| 42 | $this->value = $descriptor[PPNode_Hash_Tree::CHILDREN][0]; |
| 43 | $this->store = $store; |
| 44 | $this->index = $index; |
| 45 | } |
| 46 | |
| 47 | public function __toString() { |
| 48 | return "<@{$this->name}>" . htmlspecialchars( $this->value, ENT_COMPAT ) . "</@{$this->name}>"; |
| 49 | } |
| 50 | |
| 51 | /** @inheritDoc */ |
| 52 | public function getName() { |
| 53 | return $this->name; |
| 54 | } |
| 55 | |
| 56 | /** @inheritDoc */ |
| 57 | public function getNextSibling() { |
| 58 | return PPNode_Hash_Tree::factory( $this->store, $this->index + 1 ); |
| 59 | } |
| 60 | |
| 61 | /** @inheritDoc */ |
| 62 | public function getChildren() { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | /** @inheritDoc */ |
| 67 | public function getFirstChild() { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | /** @inheritDoc */ |
| 72 | public function getChildrenOfType( $name ) { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | /** @inheritDoc */ |
| 77 | public function getLength() { |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | /** @inheritDoc */ |
| 82 | public function item( $i ) { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | /** @inheritDoc */ |
| 87 | public function splitArg() { |
| 88 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 89 | throw new LogicException( __METHOD__ . ': not supported' ); |
| 90 | } |
| 91 | |
| 92 | /** @inheritDoc */ |
| 93 | public function splitExt() { |
| 94 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 95 | throw new LogicException( __METHOD__ . ': not supported' ); |
| 96 | } |
| 97 | |
| 98 | /** @inheritDoc */ |
| 99 | public function splitHeading() { |
| 100 | // @phan-suppress-previous-line PhanPluginNeverReturnMethod |
| 101 | throw new LogicException( __METHOD__ . ': not supported' ); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** @deprecated class alias since 1.43 */ |
| 106 | class_alias( PPNode_Hash_Attr::class, 'PPNode_Hash_Attr' ); |