| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Upgrade status. |
| 23 | 23 | * |
| 24 | - * @var array | |
| 24 | + * @var array{total:int,progress:int,currentTask:null|array{name:string,total:int,progress:int}}|null | |
| 25 | 25 | */ |
| 26 | 26 | public $status = [ |
| 27 | 27 | 'total' => 0, |
| 28 | 28 | 'progress' => 0, |
| @@ -31,11 +31,13 @@ | ||
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Update the status of the upgrade. |
| 34 | 34 | * |
| 35 | - * @param array $status Status to update. | |
| 35 | + * @param array{total?:int|null,progress?:int|null,curentTask?:string|null} $status Status to update. | |
| 36 | + * | |
| 37 | + * @return void | |
| 36 | 38 | */ |
| 37 | - public function update_status( $status = [] ) { | |
| 39 | + public function update_status( $status ) { | |
| 38 | 40 | $defaults = [ |
| 39 | 41 | 'total' => 0, |
| 40 | 42 | 'progress' => 0, |
| 41 | 43 | 'currentTask' => null, |
| @@ -53,11 +55,13 @@ | ||
| 53 | 55 | |
| 54 | 56 | /** |
| 55 | 57 | * Update the status of the current task. |
| 56 | 58 | * |
| 57 | - * @param array|null $task_status Status to update. | |
| 59 | + * @param array{total?:int,progress?:int,curentTask?:string}|null $task_status Status to update. | |
| 60 | + * | |
| 61 | + * @return void | |
| 58 | 62 | */ |
| 59 | - public function update_task_status( $task_status = [] ) { | |
| 63 | + public function update_task_status( $task_status ) { | |
| 60 | 64 | $defaults = [ |
| 61 | 65 | 'name' => '', |
| 62 | 66 | 'total' => 0, |
| 63 | 67 | 'progress' => 0, |
| @@ -81,9 +85,9 @@ | ||
| 81 | 85 | /** |
| 82 | 86 | * Send an event to the client. |
| 83 | 87 | * |
| 84 | 88 | * @param string $event Event name. |
| 85 | - * @param array $data Data to send. | |
| 89 | + * @param mixed $data Data to send. | |
| 86 | 90 | * |
| 87 | 91 | * @return void |
| 88 | 92 | */ |
| 89 | 93 | public function send_event( $event, $data = [] ) { |
| @@ -93,9 +97,9 @@ | ||
| 93 | 97 | if ( ! empty( $data['message'] ) ) { |
| 94 | 98 | plugin( 'logging' )->log( $data['message'] ); |
| 95 | 99 | } |
| 96 | 100 | |
| 97 | - $data = is_string( $data ) ? $data : \wp_json_encode( $data ); | |
| 101 | + $data = \wp_json_encode( $data ); | |
| 98 | 102 | |
| 99 | 103 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 100 | 104 | echo "event: {$event}" . PHP_EOL; |
| 101 | 105 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -109,8 +113,10 @@ | ||
| 109 | 113 | * Start the upgrade process. |
| 110 | 114 | * |
| 111 | 115 | * @param int $total Number of upgrades. |
| 112 | 116 | * @param string $message Message to send. |
| 117 | + * | |
| 118 | + * @return void | |
| 113 | 119 | */ |
| 114 | 120 | public function start_upgrades( $total, $message = null ) { |
| 115 | 121 | $this->update_status( [ |
| 116 | 122 | 'total' => $total, |
| @@ -126,8 +132,10 @@ | ||
| 126 | 132 | /** |
| 127 | 133 | * Complete the upgrade process. |
| 128 | 134 | * |
| 129 | 135 | * @param string $message Message to send. |
| 136 | + * | |
| 137 | + * @return void | |
| 130 | 138 | */ |
| 131 | 139 | public function complete_upgrades( $message = null ) { |
| 132 | 140 | $this->update_status( [ |
| 133 | 141 | 'progress' => $this->status['total'], |
| @@ -144,8 +152,10 @@ | ||
| 144 | 152 | * |
| 145 | 153 | * @param string $name Task name. |
| 146 | 154 | * @param int $task_steps Number of steps in the task. |
| 147 | 155 | * @param string $message Message to send. |
| 156 | + * | |
| 157 | + * @return void | |
| 148 | 158 | */ |
| 149 | 159 | public function start_task( $name, $task_steps = 1, $message = null ) { |
| 150 | 160 | $this->update_task_status( [ |
| 151 | 161 | 'name' => $name, |
| @@ -161,8 +171,10 @@ | ||
| 161 | 171 | /** |
| 162 | 172 | * Update the progress of the current task. |
| 163 | 173 | * |
| 164 | 174 | * @param int $progress Progress of the task. |
| 175 | + * | |
| 176 | + * @return void | |
| 165 | 177 | */ |
| 166 | 178 | public function update_task_progress( $progress ) { |
| 167 | 179 | $this->update_task_status( [ |
| 168 | 180 | 'progress' => $progress, |
| @@ -174,8 +186,10 @@ | ||
| 174 | 186 | /** |
| 175 | 187 | * Complete the current task. |
| 176 | 188 | * |
| 177 | 189 | * @param string $message Message to send. |
| 190 | + * | |
| 191 | + * @return void | |
| 178 | 192 | */ |
| 179 | 193 | public function complete_task( $message = null ) { |
| 180 | 194 | $task_status = $this->status['currentTask']; |
| 181 | 195 | |