Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
OverrideableRequirementHelper
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 isMet
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
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\Skins\Vector\FeatureManagement\Requirements;
22
23use MediaWiki\Request\WebRequest;
24
25/**
26 * The `OverridableConfigRequirement` allows us to define requirements that can override
27 * requirements with querystring parameters.
28 *
29 * NOTE: This API hasn't settled. It may change at any time without warning. Please don't bind to
30 * it unless you absolutely need to
31 *
32 * @package MediaWiki\Skins\Vector\FeatureManagement\Requirements
33 */
34class OverrideableRequirementHelper {
35    private WebRequest $request;
36
37    private string $requirementName;
38
39    private string $overrideName;
40
41    /**
42     * This constructor accepts all dependencies needed to determine whether
43     * the overridable config is enabled for the current user and request.
44     *
45     * @param WebRequest $request
46     * @param string $requirementName The name of the requirement presented to FeatureManager.
47     */
48    public function __construct(
49        WebRequest $request,
50        string $requirementName
51    ) {
52        $this->request = $request;
53        $this->overrideName = 'vector' . strtolower( $requirementName );
54        $this->requirementName = $requirementName;
55    }
56
57    /**
58     * Check query parameter to override config or not.
59     * Then check for AB test value.
60     * Fallback to config value.
61     *
62     * @return bool|null
63     */
64    public function isMet(): ?bool {
65        // Check query parameter.
66        if ( $this->request->getCheck( $this->overrideName ) ) {
67            return $this->request->getBool( $this->overrideName );
68        }
69        $vectorReq = 'Vector' . $this->requirementName;
70        if ( $this->request->getCheck( $vectorReq ) ) {
71            return $this->request->getBool( $vectorReq );
72        }
73        return null;
74    }
75}