Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| DatabaseThreadItem | |
0.00% |
0 / 12 |
|
0.00% |
0 / 12 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRevision | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addReply | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getReplies | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTranscludedFrom | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLevel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isCanonicalPermalink | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\DiscussionTools\ThreadItem; |
| 4 | |
| 5 | use JsonSerializable; |
| 6 | use MediaWiki\Page\ProperPageIdentity; |
| 7 | use MediaWiki\Revision\RevisionRecord; |
| 8 | |
| 9 | class DatabaseThreadItem implements JsonSerializable, ThreadItem { |
| 10 | use ThreadItemTrait; |
| 11 | |
| 12 | /** @var self[] */ |
| 13 | private array $replies = []; |
| 14 | |
| 15 | public function __construct( |
| 16 | private readonly ProperPageIdentity $page, |
| 17 | private readonly RevisionRecord $rev, |
| 18 | private readonly string $type, |
| 19 | private readonly string $name, |
| 20 | private readonly string $id, |
| 21 | private readonly ?self $parent, |
| 22 | private readonly bool|string $transcludedFrom, |
| 23 | private readonly int $level, |
| 24 | ) { |
| 25 | } |
| 26 | |
| 27 | public function getPage(): ProperPageIdentity { |
| 28 | return $this->page; |
| 29 | } |
| 30 | |
| 31 | public function getRevision(): RevisionRecord { |
| 32 | return $this->rev; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @inheritDoc |
| 37 | */ |
| 38 | public function getName(): string { |
| 39 | return $this->name; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param self $reply Reply comment |
| 44 | */ |
| 45 | public function addReply( self $reply ): void { |
| 46 | $this->replies[] = $reply; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @inheritDoc |
| 51 | */ |
| 52 | public function getId(): string { |
| 53 | return $this->id; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @inheritDoc |
| 58 | */ |
| 59 | public function getType(): string { |
| 60 | return $this->type; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @inheritDoc |
| 65 | * @return self|null |
| 66 | */ |
| 67 | public function getParent(): ?ThreadItem { |
| 68 | return $this->parent; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @inheritDoc |
| 73 | * @return self[] |
| 74 | */ |
| 75 | public function getReplies(): array { |
| 76 | return $this->replies; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @inheritDoc |
| 81 | */ |
| 82 | public function getTranscludedFrom() { |
| 83 | return $this->transcludedFrom; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @inheritDoc |
| 88 | */ |
| 89 | public function getLevel(): int { |
| 90 | return $this->level; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * An item can generate the canonical permalink if it is not transcluded from another page, |
| 95 | * and it was found in the current revision of its page. |
| 96 | */ |
| 97 | public function isCanonicalPermalink(): bool { |
| 98 | return $this->getRevision()->isCurrent() && !is_string( $this->getTranscludedFrom() ); |
| 99 | } |
| 100 | } |