Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.00% |
7 / 10 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ZObjectPage | |
70.00% |
7 / 10 |
|
85.71% |
6 / 7 |
9.73 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| newSuccess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| newFatal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getWikiPage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getErrors | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isOK | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTitle | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WikiLambda wrapper object for WikiPage creation status |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 8 | * @license MIT |
| 9 | */ |
| 10 | |
| 11 | namespace MediaWiki\Extension\WikiLambda; |
| 12 | |
| 13 | use MediaWiki\Extension\WikiLambda\ZObjects\ZError; |
| 14 | use MediaWiki\Page\WikiPage; |
| 15 | use MediaWiki\Title\Title; |
| 16 | |
| 17 | class ZObjectPage { |
| 18 | |
| 19 | /** |
| 20 | * @var WikiPage |
| 21 | */ |
| 22 | private $page = null; |
| 23 | |
| 24 | /** |
| 25 | * @var ZError |
| 26 | */ |
| 27 | private $errors = null; |
| 28 | |
| 29 | /** |
| 30 | * @param WikiPage|null $page |
| 31 | * @param ZError|null $errors |
| 32 | */ |
| 33 | private function __construct( $page, $errors = null ) { |
| 34 | $this->page = $page; |
| 35 | $this->errors = $errors; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Create an instance of a successful ZObjectPage wrapping a WikiPage object |
| 40 | * |
| 41 | * @param WikiPage $page |
| 42 | * @return ZObjectPage |
| 43 | */ |
| 44 | public static function newSuccess( $page ) { |
| 45 | return new self( $page ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Create an instance of a fatal ZObjectPage wrapping a ZError object |
| 50 | * |
| 51 | * @param ZError $errors |
| 52 | * @return ZObjectPage |
| 53 | */ |
| 54 | public static function newFatal( $errors ) { |
| 55 | return new self( null, $errors ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get the WikiPage of this ZObjectPage |
| 60 | * |
| 61 | * @return WikiPage|null |
| 62 | */ |
| 63 | public function getWikiPage() { |
| 64 | return $this->page; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get the errors of this ZObjectPage |
| 69 | * |
| 70 | * @return ZError|null |
| 71 | */ |
| 72 | public function getErrors() { |
| 73 | return $this->errors; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get whether this ZObjectPage has a page set |
| 78 | * |
| 79 | * @return bool |
| 80 | */ |
| 81 | public function isOK(): bool { |
| 82 | return ( $this->page !== null ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Get the Title of this ZObjectPage if OK |
| 87 | * |
| 88 | * @return Title|null |
| 89 | */ |
| 90 | public function getTitle() { |
| 91 | if ( $this->isOK() ) { |
| 92 | return $this->page->getTitle(); |
| 93 | } |
| 94 | return null; |
| 95 | } |
| 96 | } |