Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
AccessLevelTrait | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
highestAccessLevel | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo; |
4 | |
5 | trait AccessLevelTrait { |
6 | /** |
7 | * Get the highest access level user has permissions for. |
8 | * |
9 | * @param string[] $permissions |
10 | * @return ?string null if the user has no rights to see IP information |
11 | */ |
12 | public function highestAccessLevel( array $permissions ): ?string { |
13 | // An ordered list of the access levels for viewing IP infomation, ordered |
14 | // from lowest to highest level. |
15 | // Should be kept up-to-date with DefaultPresenter::VIEWING_RIGHTS |
16 | $levels = [ |
17 | 'ipinfo-view-basic', |
18 | 'ipinfo-view-full', |
19 | ]; |
20 | |
21 | $highestLevel = null; |
22 | foreach ( $levels as $level ) { |
23 | if ( in_array( $level, $permissions ) ) { |
24 | $highestLevel = $level; |
25 | } |
26 | } |
27 | |
28 | return $highestLevel; |
29 | } |
30 | } |