| Conditions | 6 |
| Paths | 5 |
| Total Lines | 26 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 36 | public function create( $username, $password, $email = null ) { |
||
| 37 | if ( !is_string( $username ) ) { |
||
| 38 | throw new InvalidArgumentException( '$username should be a string' ); |
||
| 39 | } |
||
| 40 | if ( !is_string( $password ) ) { |
||
| 41 | throw new InvalidArgumentException( '$password should be a string' ); |
||
| 42 | } |
||
| 43 | if ( !is_string( $email ) && !is_null( $email ) ) { |
||
| 44 | throw new InvalidArgumentException( '$email should be a string or null' ); |
||
| 45 | } |
||
| 46 | |||
| 47 | $params = [ |
||
| 48 | 'createreturnurl' => $this->api->getApiUrl(), |
||
| 49 | 'createtoken' => $this->api->getToken( 'createaccount' ), |
||
| 50 | 'username' => $username, |
||
| 51 | 'password' => $password, |
||
| 52 | 'retype' => $password, |
||
| 53 | ]; |
||
| 54 | |||
| 55 | if ( !is_null( $email ) ) { |
||
| 56 | $params['email'] = $email; |
||
| 57 | } |
||
| 58 | |||
| 59 | $result = $this->api->postRequest( new SimpleRequest( 'createaccount', $params ) ); |
||
| 60 | return $result['createaccount']['status'] === 'PASS'; |
||
| 61 | } |
||
| 62 | |||
| 64 |