Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
72.73% |
8 / 11 |
|
71.43% |
5 / 7 |
CRAP | |
0.00% |
0 / 1 |
PageContent | |
72.73% |
8 / 11 |
|
71.43% |
5 / 7 |
9.30 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRoles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasRole | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
checkRole | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getModel | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getFormat | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getContent | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
1.12 |
1 | <?php |
2 | /** |
3 | * Copyright (C) 2011-2022 Wikimedia Foundation and others. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | */ |
19 | |
20 | namespace MediaWiki\Parser\Parsoid\Config; |
21 | |
22 | use InvalidArgumentException; |
23 | use MediaWiki\Revision\RevisionRecord; |
24 | use Wikimedia\Parsoid\Config\PageContent as IPageContent; |
25 | |
26 | /** |
27 | * PageContent implementation for MediaWiki |
28 | * |
29 | * @since 1.39 |
30 | */ |
31 | class PageContent extends IPageContent { |
32 | private RevisionRecord $rev; |
33 | |
34 | /** |
35 | * @param RevisionRecord $rev |
36 | */ |
37 | public function __construct( RevisionRecord $rev ) { |
38 | $this->rev = $rev; |
39 | } |
40 | |
41 | /** @inheritDoc */ |
42 | public function getRoles(): array { |
43 | return $this->rev->getSlotRoles(); |
44 | } |
45 | |
46 | /** @inheritDoc */ |
47 | public function hasRole( string $role ): bool { |
48 | return $this->rev->hasSlot( $role ); |
49 | } |
50 | |
51 | /** |
52 | * Throw if the revision doesn't have the named role |
53 | * @param string $role |
54 | * @throws InvalidArgumentException |
55 | */ |
56 | private function checkRole( string $role ): void { |
57 | if ( !$this->rev->hasSlot( $role ) ) { |
58 | throw new InvalidArgumentException( "PageContent does not have role '$role'" ); |
59 | } |
60 | } |
61 | |
62 | /** @inheritDoc */ |
63 | public function getModel( string $role ): string { |
64 | $this->checkRole( $role ); |
65 | return $this->rev->getContent( $role )->getModel(); |
66 | } |
67 | |
68 | /** @inheritDoc */ |
69 | public function getFormat( string $role ): string { |
70 | $this->checkRole( $role ); |
71 | return $this->rev->getContent( $role )->getDefaultFormat(); |
72 | } |
73 | |
74 | /** @inheritDoc */ |
75 | public function getContent( string $role ): string { |
76 | $this->checkRole( $role ); |
77 | return $this->rev->getContentOrThrow( $role )->serialize(); |
78 | } |
79 | |
80 | } |