| Conditions | 5 |
| Paths | 5 |
| Total Lines | 20 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 3 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 14 | public function handle(Command $command) |
||
| 15 | { |
||
| 16 | if (!get_post($command->id)) { |
||
| 17 | return false; |
||
| 18 | } |
||
| 19 | if (!glsr()->can('edit_others_posts')) { |
||
| 20 | $meta = (Database::class)->get($command->id, 'pinned'); |
||
| 21 | return wp_validate_boolean($meta); |
||
| 22 | } |
||
| 23 | if (is_null($command->pinned)) { |
||
| 24 | $meta = glsr(Database::class)->get($command->id, 'pinned'); |
||
| 25 | $command->pinned = !wp_validate_boolean($meta); |
||
| 26 | } else { |
||
| 27 | $notice = $command->pinned |
||
| 28 | ? __('Review pinned.', 'site-reviews') |
||
| 29 | : __('Review unpinned.', 'site-reviews'); |
||
| 30 | glsr(Notice::class)->addSuccess($notice); |
||
| 31 | } |
||
| 32 | glsr(Database::class)->update($command->id, 'pinned', $command->pinned); |
||
| 33 | return $command->pinned; |
||
| 34 | } |
||
| 36 |