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