| Conditions | 8 |
| Paths | 11 |
| Total Lines | 35 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 13.8319 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 35 | 1 | public function create( $username, $password, $email = null ) { |
|
| 36 | 1 | if ( !is_string( $username ) ) { |
|
| 37 | throw new InvalidArgumentException( '$username should be a string' ); |
||
| 38 | } |
||
| 39 | 1 | if ( !is_string( $password ) ) { |
|
| 40 | throw new InvalidArgumentException( '$password should be a string' ); |
||
| 41 | } |
||
| 42 | 1 | if ( !is_string( $email ) && !is_null( $email ) ) { |
|
| 43 | throw new InvalidArgumentException( '$email should be a string or null' ); |
||
| 44 | } |
||
| 45 | |||
| 46 | $params = [ |
||
| 47 | 1 | 'name' => $username, |
|
| 48 | 1 | 'password' => $password, |
|
| 49 | ]; |
||
| 50 | |||
| 51 | 1 | if ( !is_null( $email ) ) { |
|
| 52 | $params['email'] = $email; |
||
| 53 | } |
||
| 54 | |||
| 55 | 1 | $result = $this->api->postRequest( new SimpleRequest( 'createaccount', $params ) ); |
|
| 56 | 1 | if ( $result['createaccount']['result'] == 'NeedToken' ) { |
|
| 57 | $result = $this->api->postRequest( |
||
| 58 | new SimpleRequest( |
||
| 59 | 'createaccount', |
||
| 60 | array_merge( [ 'token' => $result['createaccount']['token'] ], $params ) |
||
| 61 | ) |
||
| 62 | ); |
||
| 63 | } |
||
| 64 | 1 | if ( $result['createaccount']['result'] === 'Success' ) { |
|
| 65 | return true; |
||
| 66 | } |
||
| 67 | |||
| 68 | 1 | return false; |
|
| 69 | } |
||
| 70 | |||
| 72 |