litefeel /
writing-on-github
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * API Persist client. |
||||
| 4 | * @package Writing_On_GitHub |
||||
| 5 | */ |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * Class Writing_On_GitHub_Persist_Client |
||||
| 9 | */ |
||||
| 10 | class Writing_On_GitHub_Persist_Client extends Writing_On_GitHub_Base_Client { |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * Get the data for the current user. |
||||
| 14 | * |
||||
| 15 | * @return array |
||||
| 16 | */ |
||||
| 17 | 1 | protected function export_user() { |
|||
| 18 | 1 | $user_id = get_current_user_id(); |
|||
| 19 | 1 | $user = get_userdata( $user_id ); |
|||
| 20 | |||||
| 21 | 1 | if ( $user ) { |
|||
| 22 | return array( |
||||
| 23 | 'name' => $user->display_name, |
||||
| 24 | 'email' => $user->user_email, |
||||
| 25 | ); |
||||
| 26 | } |
||||
| 27 | |||||
| 28 | 1 | return false; |
|||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 29 | } |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Delete the file. |
||||
| 33 | * |
||||
| 34 | * @return array |
||||
| 35 | */ |
||||
| 36 | 1 | public function delete_file( $path, $sha, $message ) { |
|||
| 37 | 1 | $body = new stdClass(); |
|||
| 38 | 1 | $body->message = $message; |
|||
| 39 | 1 | $body->sha = $sha; |
|||
| 40 | 1 | $body->branch = $this->branch(); |
|||
| 41 | |||||
| 42 | 1 | if ( $author = $this->export_user() ) { |
|||
| 43 | $body->author = $author; |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | 1 | return $this->call( 'DELETE', $this->content_endpoint( $path ), $body ); |
|||
|
0 ignored issues
–
show
$body of type stdClass is incompatible with the type array expected by parameter $body of Writing_On_GitHub_Base_Client::call().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Create the file. |
||||
| 51 | * |
||||
| 52 | * @return array |
||||
| 53 | */ |
||||
| 54 | public function create_file( $blob, $message ) { |
||||
| 55 | $body = $blob->to_body(); |
||||
| 56 | $body->message = $message; |
||||
| 57 | $body->branch = $this->branch(); |
||||
| 58 | unset($body->sha); |
||||
| 59 | |||||
| 60 | if ( $author = $this->export_user() ) { |
||||
| 61 | $body->author = $author; |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
||||
|
0 ignored issues
–
show
|
|||||
| 65 | } |
||||
| 66 | |||||
| 67 | /** |
||||
| 68 | * Update the file. |
||||
| 69 | * |
||||
| 70 | * @return array |
||||
| 71 | */ |
||||
| 72 | public function update_file( $blob, $message ) { |
||||
| 73 | $body = $blob->to_body(); |
||||
| 74 | $body->message = $message; |
||||
| 75 | $body->branch = $this->branch(); |
||||
| 76 | |||||
| 77 | if ( $author = $this->export_user() ) { |
||||
| 78 | $body->author = $author; |
||||
| 79 | } |
||||
| 80 | |||||
| 81 | return $this->call( 'PUT', $this->content_endpoint( $blob->path() ), $body ); |
||||
|
0 ignored issues
–
show
|
|||||
| 82 | } |
||||
| 83 | } |
||||
| 84 |