@@ -4,11 +4,11 @@ |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -trait CheckTrait{ |
|
| 7 | +trait CheckTrait { |
|
| 8 | 8 | |
| 9 | 9 | protected function check_method(string $method) |
| 10 | 10 | { |
| 11 | - if(!method_exists($this, $method)){ |
|
| 11 | + if (!method_exists($this, $method)) { |
|
| 12 | 12 | throw new Exception("Filter {$method} not found in ".get_class($this).'.'); |
| 13 | 13 | } |
| 14 | 14 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace HnrAzevedo\Filter; |
| 4 | 4 | |
| 5 | -class Filter{ |
|
| 5 | +class Filter { |
|
| 6 | 6 | use CheckTrait; |
| 7 | 7 | |
| 8 | 8 | protected array $messages = []; |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | protected function treat(string $filter): void |
| 35 | 35 | { |
| 36 | - if(array_key_exists($filter,$this->treat)){ |
|
| 36 | + if (array_key_exists($filter, $this->treat)) { |
|
| 37 | 37 | $treat = $this->treat[$filter]; |
| 38 | 38 | $this->$treat(); |
| 39 | 39 | } |
@@ -2,18 +2,18 @@ |
||
| 2 | 2 | |
| 3 | 3 | use HnrAzevedo\Filter\Filter; |
| 4 | 4 | |
| 5 | -class User extends Filter{ |
|
| 5 | +class User extends Filter { |
|
| 6 | 6 | |
| 7 | 7 | public function user_in(): bool |
| 8 | 8 | { |
| 9 | 9 | /* Set message to be displayed in case of error */ |
| 10 | - $this->addMessage('user_in','User required to be logged in.'); |
|
| 10 | + $this->addMessage('user_in', 'User required to be logged in.'); |
|
| 11 | 11 | |
| 12 | 12 | /* OPTIONAL: Defines function to be executed before the error is returned to the client */ |
| 13 | - $this->addTreat('user_in','report_notLogged'); |
|
| 13 | + $this->addTreat('user_in', 'report_notLogged'); |
|
| 14 | 14 | |
| 15 | 15 | /* Test something and return your result */ |
| 16 | - return (array_key_exists('user',$_SESSION)); |
|
| 16 | + return (array_key_exists('user', $_SESSION)); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function report_notLogged(): void |
@@ -7,6 +7,6 @@ |
||
| 7 | 7 | |
| 8 | 8 | $filter = new User(); |
| 9 | 9 | |
| 10 | -if(!$filter->check('user_in')){ |
|
| 10 | +if (!$filter->check('user_in')) { |
|
| 11 | 11 | echo $filter->getMessage('user_in'); |
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |