Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageSet
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 5
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
30
 jsonSerialize
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 fromArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getOption
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getOptionName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types=1 );
3
4namespace MediaWiki\Extension\TranslationNotifications\Utilities;
5
6use InvalidArgumentException;
7use JsonSerializable;
8
9/**
10 * Stores and validates possible options for a group of languages
11 * to which users should be notified.
12 *
13 * @author Eugene Wang'ombe
14 * @license GPL-2.0-or-later
15 * @since 2022.10
16 */
17class LanguageSet implements JsonSerializable {
18    public const ALL = 1;
19    public const SOME = 2;
20    public const ALL_EXCEPT_SOME = 3;
21
22    private int $option;
23    private string $optionName;
24
25    public function __construct( int $option ) {
26        $this->option = $option;
27
28        switch ( $option ) {
29            case self::ALL:
30                $this->optionName = 'ALL';
31                break;
32            case self::SOME:
33                $this->optionName = 'SOME';
34                break;
35            case self::ALL_EXCEPT_SOME:
36                $this->optionName = 'ALL EXCEPT SOME';
37                break;
38            default:
39                throw new InvalidArgumentException( "Invalid option: $option" );
40        }
41    }
42
43    public function jsonSerialize(): array {
44        return [
45            'option' => $this->option,
46            'optionName' => $this->optionName
47        ];
48    }
49
50    public static function fromArray( array $data ): self {
51        return new self( (int)$data[ 'option' ] );
52    }
53
54    public function getOption(): int {
55        return $this->option;
56    }
57
58    public function getOptionName(): string {
59        return $this->optionName;
60    }
61}