Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
HeadingItemTrait | |
0.00% |
0 / 9 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
getName | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
getHeadingLevel | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
isPlaceholderHeading | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
jsonSerialize | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
isSubscribable | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\DiscussionTools\ThreadItem; |
4 | |
5 | trait HeadingItemTrait { |
6 | // phpcs:disable Squiz.WhiteSpace, MediaWiki.Commenting |
7 | // Required ThreadItem methods (listed for Phan) |
8 | abstract public function getName(): string; |
9 | // Required HeadingItem methods (listed for Phan) |
10 | abstract public function getHeadingLevel(): int; |
11 | abstract public function isPlaceholderHeading(): bool; |
12 | // phpcs:enable |
13 | |
14 | /** |
15 | * @inheritDoc |
16 | * @suppress PhanTraitParentReference |
17 | */ |
18 | public function jsonSerialize( bool $deep = false, ?callable $callback = null ): array { |
19 | return array_merge( [ |
20 | 'headingLevel' => $this->isPlaceholderHeading() ? null : $this->getHeadingLevel(), |
21 | // Used for topic subscriptions. Not added to CommentItem's yet as there is |
22 | // no use case for it. |
23 | 'name' => $this->getName(), |
24 | ], parent::jsonSerialize( $deep, $callback ) ); |
25 | } |
26 | |
27 | /** |
28 | * Check whether this heading can be used for topic subscriptions. |
29 | */ |
30 | public function isSubscribable(): bool { |
31 | return ( |
32 | // Placeholder headings have nothing to attach the button to. |
33 | !$this->isPlaceholderHeading() && |
34 | // We only allow subscribing to level 2 headings, because the user interface for sub-headings |
35 | // would be difficult to present. |
36 | $this->getHeadingLevel() === 2 && |
37 | // Check if the name corresponds to a section that contain no comments (only sub-sections). |
38 | // They can't be distinguished from each other, so disallow subscribing. |
39 | $this->getName() !== 'h-' |
40 | ); |
41 | } |
42 | } |