Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ModuleMode
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 getModuleMode
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace MediaWiki\Rest\Module;
4
5/**
6 * Describes the set of functionality applied to a module by the REST API framework.
7 * Module modes are determined by the module's audience designation, and can be overridden
8 * by the RestModuleOverrides config variable.
9 *
10 * Module modes are backed by strings corresponding to the modes in the RestModuleOverrides
11 * config variable.
12 *
13 * @since 1.47
14 */
15enum ModuleMode: string {
16    case DISABLED = 'disabled';         // treated as if the module does not exist
17    case HIDDEN = 'hidden';             // callable, excluded from /discovery and the REST Sandbox
18    case DISCOVERABLE = 'discoverable'; // callable, listed in /discovery, excluded from the REST Sandbox
19    case PUBLISHED = 'published';       // callable, listed in /discovery and the REST Sandbox
20
21    /**
22     * Gets the module mode for a given audience designation
23     *
24     * @param ?AudienceDesignation $ad The audience designation
25     *
26     * @return ModuleMode
27     */
28    public static function getModuleMode( ?AudienceDesignation $ad ): ModuleMode {
29        if ( $ad === null ) {
30            return self::DISABLED;
31        }
32
33        return match ( $ad ) {
34            AudienceDesignation::PUBLIC => self::PUBLISHED,
35            AudienceDesignation::INTERNAL => self::PUBLISHED,
36            AudienceDesignation::BETA => self::PUBLISHED,
37            AudienceDesignation::NONE => self::PUBLISHED,
38        };
39    }
40}