| Total Complexity | 3 | 
| Total Lines | 62 | 
| Duplicated Lines | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php declare(strict_types=1);  | 
            ||
| 8 | class PageState extends StateMachine  | 
            ||
| 9 | { | 
            ||
| 10 | // column key that refers to the current state in db  | 
            ||
| 11 | const KEY = 'current_state';  | 
            ||
| 12 | |||
| 13 | // Offline states  | 
            ||
| 14 | const DRAFT = 'draft';  | 
            ||
| 15 | const ARCHIVED = 'archived';  | 
            ||
| 16 | const DELETED = 'deleted'; // soft deleted  | 
            ||
| 17 | |||
| 18 | // Online states  | 
            ||
| 19 | const PUBLISHED = 'published';  | 
            ||
| 20 | |||
| 21 | protected $states = [  | 
            ||
| 22 | self::DRAFT,  | 
            ||
| 23 | self::ARCHIVED,  | 
            ||
| 24 | self::DELETED,  | 
            ||
| 25 | |||
| 26 | self::PUBLISHED,  | 
            ||
| 27 | ];  | 
            ||
| 28 | |||
| 29 | protected $transitions = [  | 
            ||
| 30 | 'publish' => [  | 
            ||
| 31 | 'from' => [self::DRAFT],  | 
            ||
| 32 | 'to' => self::PUBLISHED,  | 
            ||
| 33 | ],  | 
            ||
| 34 | 'unpublish' => [  | 
            ||
| 35 | 'from' => [self::PUBLISHED],  | 
            ||
| 36 | 'to' => self::DRAFT,  | 
            ||
| 37 | ],  | 
            ||
| 38 | 'archive' => [  | 
            ||
| 39 | 'from' => [self::PUBLISHED, self::DRAFT],  | 
            ||
| 40 | 'to' => self::ARCHIVED,  | 
            ||
| 41 | ],  | 
            ||
| 42 | 'unarchive' => [  | 
            ||
| 43 | 'from' => [self::ARCHIVED],  | 
            ||
| 44 | 'to' => self::DRAFT,  | 
            ||
| 45 | ],  | 
            ||
| 46 | 'delete' => [  | 
            ||
| 47 | 'from' => [self::ARCHIVED, self::DRAFT],  | 
            ||
| 48 | 'to' => self::DELETED,  | 
            ||
| 49 | ],  | 
            ||
| 50 | ];  | 
            ||
| 51 | |||
| 52 | public static function make(StatefulContract $model)  | 
            ||
| 53 |     { | 
            ||
| 54 | return new static($model, static::KEY);  | 
            ||
| 55 | }  | 
            ||
| 56 | |||
| 57 | public function isOffline(): bool  | 
            ||
| 58 |     { | 
            ||
| 59 | return in_array($this->statefulContract->stateOf(static::KEY), [  | 
            ||
| 60 | static::DRAFT,  | 
            ||
| 61 | static::ARCHIVED,  | 
            ||
| 62 | static::DELETED,  | 
            ||
| 63 | ]);  | 
            ||
| 64 | }  | 
            ||
| 65 | |||
| 66 | public function isOnline(): bool  | 
            ||
| 70 | ]);  | 
            ||
| 71 | }  | 
            ||
| 72 | }  | 
            ||
| 73 |