| Conditions | 4 |
| Paths | 5 |
| Total Lines | 22 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | public function rules(): array |
||
| 16 | { |
||
| 17 | if (Request::METHOD_DELETE === $this->method()) { |
||
| 18 | // No rules are required for deleting. |
||
| 19 | return []; |
||
| 20 | } |
||
| 21 | $rules = [ |
||
| 22 | 'category_name' => ['required', 'string', 'min:1', 'max:200'], |
||
| 23 | 'slug' => ['required', 'alpha_dash', 'max:100', 'min:1'], |
||
| 24 | 'category_description' => ['nullable', 'string', 'min:1', 'max:5000'], |
||
| 25 | ]; |
||
| 26 | |||
| 27 | if (Request::METHOD_POST === $this->method()) { |
||
| 28 | $rules['slug'][] = Rule::unique('blog_etc_categories', 'slug'); |
||
| 29 | } |
||
| 30 | |||
| 31 | if (in_array($this->method(), [Request::METHOD_PUT, Request::METHOD_PATCH], true)) { |
||
| 32 | $rules['slug'][] = Rule::unique('blog_etc_categories', 'slug') |
||
| 33 | ->ignore($this->route()->parameter('categoryId')); |
||
| 34 | } |
||
| 35 | |||
| 36 | return $rules; |
||
| 37 | } |
||
| 39 |