| @@ -38,21 +38,21 @@ discard block | ||
| 38 | 38 | public function getColumns() | 
| 39 | 39 |      { | 
| 40 | 40 | // Se nenhuma coluna foi definida todas serão retornadas | 
| 41 | - if(!isset($this->payload['columns']) || !is_array($this->payload['columns'])) | |
| 41 | + if (!isset($this->payload['columns']) || !is_array($this->payload['columns'])) | |
| 42 | 42 | return ['*']; | 
| 43 | 43 | |
| 44 | 44 | $regex = '/^[a-zA-Z_][a-zA-Z0-9_]*$/'; | 
| 45 | 45 | $columns = array(); | 
| 46 | 46 | |
| 47 | -        foreach ($this->payload['columns'] as $column){ | |
| 47 | +        foreach ($this->payload['columns'] as $column) { | |
| 48 | 48 | // Valida o nome da coluna | 
| 49 | - if(!is_string($column) || !preg_match($regex, $column)) | |
| 49 | + if (!is_string($column) || !preg_match($regex, $column)) | |
| 50 | 50 | throw new InvalidColumnNameException(); | 
| 51 | 51 | |
| 52 | 52 | $columns[] = $column; | 
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | - if(count($columns) == 0) | |
| 55 | + if (count($columns) == 0) | |
| 56 | 56 | return ['*']; | 
| 57 | 57 | |
| 58 | 58 | return $columns; | 
| @@ -65,10 +65,10 @@ discard block | ||
| 65 | 65 | */ | 
| 66 | 66 | public function getLimit() | 
| 67 | 67 |      { | 
| 68 | - if(!isset($this->payload['limit'])) | |
| 68 | + if (!isset($this->payload['limit'])) | |
| 69 | 69 | return null; | 
| 70 | 70 | |
| 71 | - if(!is_int($this->payload['limit'])) | |
| 71 | + if (!is_int($this->payload['limit'])) | |
| 72 | 72 | return null; | 
| 73 | 73 | |
| 74 | 74 | return $this->payload['limit']; | 
| @@ -83,12 +83,12 @@ discard block | ||
| 83 | 83 |      { | 
| 84 | 84 | $allowed = ['ASC', 'DESC']; | 
| 85 | 85 | |
| 86 | - if(!isset($this->payload['order']) || !is_array($this->payload['order'])) | |
| 86 | + if (!isset($this->payload['order']) || !is_array($this->payload['order'])) | |
| 87 | 87 | return ''; | 
| 88 | 88 | |
| 89 | 89 | $orders = array(); | 
| 90 | 90 | |
| 91 | -        foreach ($this->payload['order'] as $order){ | |
| 91 | +        foreach ($this->payload['order'] as $order) { | |
| 92 | 92 |              $columns  = implode(', ', $order[0]); | 
| 93 | 93 | $command = in_array($order[1], $allowed) ? $order[1] : 'ASC'; | 
| 94 | 94 |              $orders[] = "{$columns}, {$command}"; | 
| @@ -104,7 +104,7 @@ discard block | ||
| 104 | 104 | */ | 
| 105 | 105 | public function getWhere() | 
| 106 | 106 |      { | 
| 107 | - if(!is_array($this->payload['where'])) | |
| 107 | + if (!is_array($this->payload['where'])) | |
| 108 | 108 | return []; | 
| 109 | 109 | |
| 110 | 110 | $adapter = new WhereAdapter(); | 
| @@ -38,22 +38,25 @@ discard block | ||
| 38 | 38 | public function getColumns() | 
| 39 | 39 |      { | 
| 40 | 40 | // Se nenhuma coluna foi definida todas serão retornadas | 
| 41 | - if(!isset($this->payload['columns']) || !is_array($this->payload['columns'])) | |
| 42 | - return ['*']; | |
| 41 | +        if(!isset($this->payload['columns']) || !is_array($this->payload['columns'])) { | |
| 42 | + return ['*']; | |
| 43 | + } | |
| 43 | 44 | |
| 44 | 45 | $regex = '/^[a-zA-Z_][a-zA-Z0-9_]*$/'; | 
| 45 | 46 | $columns = array(); | 
| 46 | 47 | |
| 47 | 48 |          foreach ($this->payload['columns'] as $column){ | 
| 48 | 49 | // Valida o nome da coluna | 
| 49 | - if(!is_string($column) || !preg_match($regex, $column)) | |
| 50 | - throw new InvalidColumnNameException(); | |
| 50 | +            if(!is_string($column) || !preg_match($regex, $column)) { | |
| 51 | + throw new InvalidColumnNameException(); | |
| 52 | + } | |
| 51 | 53 | |
| 52 | 54 | $columns[] = $column; | 
| 53 | 55 | } | 
| 54 | 56 | |
| 55 | - if(count($columns) == 0) | |
| 56 | - return ['*']; | |
| 57 | +        if(count($columns) == 0) { | |
| 58 | + return ['*']; | |
| 59 | + } | |
| 57 | 60 | |
| 58 | 61 | return $columns; | 
| 59 | 62 | } | 
| @@ -65,11 +68,13 @@ discard block | ||
| 65 | 68 | */ | 
| 66 | 69 | public function getLimit() | 
| 67 | 70 |      { | 
| 68 | - if(!isset($this->payload['limit'])) | |
| 69 | - return null; | |
| 71 | +        if(!isset($this->payload['limit'])) { | |
| 72 | + return null; | |
| 73 | + } | |
| 70 | 74 | |
| 71 | - if(!is_int($this->payload['limit'])) | |
| 72 | - return null; | |
| 75 | +        if(!is_int($this->payload['limit'])) { | |
| 76 | + return null; | |
| 77 | + } | |
| 73 | 78 | |
| 74 | 79 | return $this->payload['limit']; | 
| 75 | 80 | } | 
| @@ -83,8 +88,9 @@ discard block | ||
| 83 | 88 |      { | 
| 84 | 89 | $allowed = ['ASC', 'DESC']; | 
| 85 | 90 | |
| 86 | - if(!isset($this->payload['order']) || !is_array($this->payload['order'])) | |
| 87 | - return ''; | |
| 91 | +        if(!isset($this->payload['order']) || !is_array($this->payload['order'])) { | |
| 92 | + return ''; | |
| 93 | + } | |
| 88 | 94 | |
| 89 | 95 | $orders = array(); | 
| 90 | 96 | |
| @@ -104,8 +110,9 @@ discard block | ||
| 104 | 110 | */ | 
| 105 | 111 | public function getWhere() | 
| 106 | 112 |      { | 
| 107 | - if(!is_array($this->payload['where'])) | |
| 108 | - return []; | |
| 113 | +        if(!is_array($this->payload['where'])) { | |
| 114 | + return []; | |
| 115 | + } | |
| 109 | 116 | |
| 110 | 117 | $adapter = new WhereAdapter(); | 
| 111 | 118 | $where = $adapter->fromArray($this->payload['where']); | 
| @@ -52,7 +52,7 @@ | ||
| 52 | 52 | */ | 
| 53 | 53 | public function getProtectedColumns() | 
| 54 | 54 |      { | 
| 55 | - if(is_null($this->protectedColumns)) | |
| 55 | + if (is_null($this->protectedColumns)) | |
| 56 | 56 | $this->protectedColumns = []; | 
| 57 | 57 | |
| 58 | 58 | return $this->protectedColumns; | 
| @@ -52,8 +52,9 @@ | ||
| 52 | 52 | */ | 
| 53 | 53 | public function getProtectedColumns() | 
| 54 | 54 |      { | 
| 55 | - if(is_null($this->protectedColumns)) | |
| 56 | - $this->protectedColumns = []; | |
| 55 | +        if(is_null($this->protectedColumns)) { | |
| 56 | + $this->protectedColumns = []; | |
| 57 | + } | |
| 57 | 58 | |
| 58 | 59 | return $this->protectedColumns; | 
| 59 | 60 | } | 
| @@ -54,17 +54,17 @@ | ||
| 54 | 54 | public function fromArray(array $jWhere) | 
| 55 | 55 |      { | 
| 56 | 56 | $where = new Where(); | 
| 57 | -        foreach($jWhere as $item){ | |
| 58 | -            if(is_array($item)){ | |
| 59 | -                if(!in_array($item[0], $this->allowed)) { | |
| 57 | +        foreach ($jWhere as $item) { | |
| 58 | +            if (is_array($item)) { | |
| 59 | +                if (!in_array($item[0], $this->allowed)) { | |
| 60 | 60 | throw new InvalidCommandException(); | 
| 61 | 61 | } | 
| 62 | 62 | $method = $item[0]; | 
| 63 | 63 | unset($item[0]); | 
| 64 | 64 | call_user_func_array([$where, $method], $item); | 
| 65 | 65 | } | 
| 66 | -            if(is_string($item)){ | |
| 67 | - if(in_array($item, $this->allowed)) | |
| 66 | +            if (is_string($item)) { | |
| 67 | + if (in_array($item, $this->allowed)) | |
| 68 | 68 | call_user_func([$where, $item]); | 
| 69 | 69 | } | 
| 70 | 70 | } | 
| @@ -64,8 +64,9 @@ | ||
| 64 | 64 | call_user_func_array([$where, $method], $item); | 
| 65 | 65 | } | 
| 66 | 66 |              if(is_string($item)){ | 
| 67 | - if(in_array($item, $this->allowed)) | |
| 68 | - call_user_func([$where, $item]); | |
| 67 | +                if(in_array($item, $this->allowed)) { | |
| 68 | + call_user_func([$where, $item]); | |
| 69 | + } | |
| 69 | 70 | } | 
| 70 | 71 | } | 
| 71 | 72 | return $where; |