Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ReadOnlyConstraint
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 checkConstraint
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getLegacyStatus
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\EditPage\Constraint;
22
23use StatusValue;
24use Wikimedia\Rdbms\ReadOnlyMode;
25
26/**
27 * Verify site is not in read only mode
28 *
29 * @since 1.36
30 * @internal
31 * @author DannyS712
32 */
33class ReadOnlyConstraint implements IEditConstraint {
34
35    /** @var ReadOnlyMode */
36    private $readOnlyMode;
37
38    /** @var string|null */
39    private $result;
40
41    /**
42     * @param ReadOnlyMode $readOnlyMode
43     */
44    public function __construct( ReadOnlyMode $readOnlyMode ) {
45        $this->readOnlyMode = $readOnlyMode;
46    }
47
48    public function checkConstraint(): string {
49        $this->result = $this->readOnlyMode->isReadOnly() ?
50            self::CONSTRAINT_FAILED :
51            self::CONSTRAINT_PASSED;
52        return $this->result;
53    }
54
55    public function getLegacyStatus(): StatusValue {
56        $statusValue = StatusValue::newGood();
57
58        if ( $this->result === self::CONSTRAINT_FAILED ) {
59            // Saved that this is read only in case getLegacyStatus is called
60            // after the read only ends, because it still caused the failure
61            $statusValue->fatal( 'readonlytext' );
62            $statusValue->value = self::AS_READ_ONLY_PAGE;
63        }
64
65        return $statusValue;
66    }
67
68}