Debian Codegraph @

extensions/AbuseFilter/includes/Filter/Flags.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\AbuseFilter\Filter;
4
5 /**
6 * (Mutable) value object to represent flags that can be *manually* set on a filter.
7 */
8 class Flags {
9 /** @var bool */
10 private $enabled;
11 /** @var bool */
12 private $deleted;
13 /** @var bool */
14 private $hidden;
15 /** @var bool */
16 private $protected;
17 /** @var int */
18 private $privacyLevel;
19 /** @var bool */
20 private $global;
21
22 public const FILTER_PUBLIC = 0b00;
23 public const FILTER_HIDDEN = 0b01;
24 public const FILTER_USES_PROTECTED_VARS = 0b10;
25
26 /**
27 * @param bool $enabled
28 * @param bool $deleted
29 * @param int $privacyLevel
30 * @param bool $global
31 */
32 public function __construct( bool $enabled, bool $deleted, int $privacyLevel, bool $global ) {
33 $this->enabled = $enabled;
34 $this->deleted = $deleted;
35 $this->hidden = (bool)( self::FILTER_HIDDEN & $privacyLevel );
36 $this->protected = (bool)( self::FILTER_USES_PROTECTED_VARS & $privacyLevel );
37 $this->privacyLevel = $privacyLevel;
38 $this->global = $global;
39 }
40
41 /**
42 * @return bool
43 */
44 public function getEnabled(): bool {
45 return $this->enabled;
46 }
47
48 /**
49 * @param bool $enabled
50 */
51 public function setEnabled( bool $enabled ): void {
52 $this->enabled = $enabled;
53 }
54
55 /**
56 * @return bool
57 */
58 public function getDeleted(): bool {
59 return $this->deleted;
60 }
61
62 /**
63 * @param bool $deleted
64 */
65 public function setDeleted( bool $deleted ): void {
66 $this->deleted = $deleted;
67 }
68
69 /**
70 * @return bool
71 */
72 public function getHidden(): bool {
73 return $this->hidden;
74 }
75
76 /**
77 * @param bool $hidden
78 */
79 public function setHidden( bool $hidden ): void {
80 $this->hidden = $hidden;
81 $this->updatePrivacyLevel();
82 }
83
84 /**
85 * @return bool
86 */
87 public function getProtected(): bool {
88 return $this->protected;
89 }
90
91 /**
92 * @param bool $protected
93 */
94 public function setProtected( bool $protected ): void {
95 $this->protected = $protected;
96 $this->updatePrivacyLevel();
97 }
98
99 private function updatePrivacyLevel() {
100 $hidden = $this->hidden ? self::FILTER_HIDDEN : 0;
101 $protected = $this->protected ? self::FILTER_USES_PROTECTED_VARS : 0;
102 $this->privacyLevel = $hidden | $protected;
103 }
104
105 /**
106 * @return int
107 */
108 public function getPrivacyLevel(): int {
109 return $this->privacyLevel;
110 }
111
112 /**
113 * @return bool
114 */
115 public function getGlobal(): bool {
116 return $this->global;
117 }
118
119 /**
120 * @param bool $global
121 */
122 public function setGlobal( bool $global ): void {
123 $this->global = $global;
124 }
125 }