Conditions | 6 |
Paths | 4 |
Total Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
23 | public function protect( Page $page, array $protections, array $extraParams = [] ): bool { |
||
24 | if ( !is_array( $protections ) || empty( $protections ) ) { |
||
25 | throw new InvalidArgumentException( |
||
26 | '$protections must be an array with keys and values' |
||
27 | ); |
||
28 | } |
||
29 | |||
30 | $params = [ |
||
31 | 'pageid' => $page->getId(), |
||
32 | 'token' => $this->api->getToken( 'protect' ), |
||
33 | ]; |
||
34 | $protectionsString = ''; |
||
35 | foreach ( $protections as $action => $value ) { |
||
36 | if ( !is_string( $action ) || !is_string( $value ) ) { |
||
37 | throw new InvalidArgumentException( |
||
38 | 'All keys and elements of $protections must be strings' |
||
39 | ); |
||
40 | } |
||
41 | $protectionsString = $action . '=' . $value . '|'; |
||
42 | } |
||
43 | $params['protections'] = rtrim( $protectionsString, '|' ); |
||
44 | |||
45 | $this->api->postRequest( |
||
46 | new SimpleRequest( 'protect', array_merge( $extraParams, $params ) ) |
||
47 | ); |
||
48 | |||
49 | return true; |
||
50 | } |
||
51 | |||
53 |