@@ -13,8 +13,7 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @package Zortje\MVC\Controller |
15 | 15 | */ |
16 | -class Controller |
|
17 | -{ |
|
16 | +class Controller { |
|
18 | 17 | |
19 | 18 | /** |
20 | 19 | * Controller action is publicly accessible |
@@ -92,8 +91,7 @@ discard block |
||
92 | 91 | /** |
93 | 92 | * @return string Controller name without namespace |
94 | 93 | */ |
95 | - public function getShortName() |
|
96 | - { |
|
94 | + public function getShortName() { |
|
97 | 95 | return str_replace('Controller', null, (new \ReflectionClass($this))->getShortName()); |
98 | 96 | } |
99 | 97 | |
@@ -104,8 +102,7 @@ discard block |
||
104 | 102 | * @throws ControllerActionPrivateInsufficientAuthenticationException |
105 | 103 | * @throws ControllerActionProtectedInsufficientAuthenticationException |
106 | 104 | */ |
107 | - public function setAction($action) |
|
108 | - { |
|
105 | + public function setAction($action) { |
|
109 | 106 | /** |
110 | 107 | * Check if method exists and that access has been defined |
111 | 108 | */ |
@@ -137,8 +134,7 @@ discard block |
||
137 | 134 | * |
138 | 135 | * @throws \LogicException If controller action is not set |
139 | 136 | */ |
140 | - public function callAction() |
|
141 | - { |
|
137 | + public function callAction() { |
|
142 | 138 | if (!isset($this->action)) { |
143 | 139 | throw new \LogicException('Controller action must be set before being called'); |
144 | 140 | } |
@@ -182,8 +178,7 @@ discard block |
||
182 | 178 | * |
183 | 179 | * Called right before controller action is called |
184 | 180 | */ |
185 | - protected function beforeAction() |
|
186 | - { |
|
181 | + protected function beforeAction() { |
|
187 | 182 | /** |
188 | 183 | * Set New Relic transaction name |
189 | 184 | */ |
@@ -197,8 +192,7 @@ discard block |
||
197 | 192 | * |
198 | 193 | * Called right after controller action is called, but before rendering of the view |
199 | 194 | */ |
200 | - protected function afterAction() |
|
201 | - { |
|
195 | + protected function afterAction() { |
|
202 | 196 | } |
203 | 197 | |
204 | 198 | /** |
@@ -207,8 +201,7 @@ discard block |
||
207 | 201 | * @param string $variable |
208 | 202 | * @param mixed $value |
209 | 203 | */ |
210 | - protected function set($variable, $value) |
|
211 | - { |
|
204 | + protected function set($variable, $value) { |
|
212 | 205 | $this->variables[$variable] = $value; |
213 | 206 | } |
214 | 207 | |
@@ -217,8 +210,7 @@ discard block |
||
217 | 210 | * |
218 | 211 | * @return string Layout template file path |
219 | 212 | */ |
220 | - protected function getLayoutTemplate() |
|
221 | - { |
|
213 | + protected function getLayoutTemplate() { |
|
222 | 214 | $layout = $this->layout; |
223 | 215 | |
224 | 216 | if (empty($layout)) { |
@@ -233,8 +225,7 @@ discard block |
||
233 | 225 | * |
234 | 226 | * @return string View template file path |
235 | 227 | */ |
236 | - protected function getViewTemplate() |
|
237 | - { |
|
228 | + protected function getViewTemplate() { |
|
238 | 229 | $view = $this->view; |
239 | 230 | |
240 | 231 | if (empty($view)) { |
@@ -253,8 +244,7 @@ discard block |
||
253 | 244 | * |
254 | 245 | * @throws \InvalidArgumentException If unsupported code is provided |
255 | 246 | */ |
256 | - protected function setResponseCode($code) |
|
257 | - { |
|
247 | + protected function setResponseCode($code) { |
|
258 | 248 | switch ($code) { |
259 | 249 | case 200: |
260 | 250 | $text = 'OK'; |
@@ -289,8 +279,7 @@ discard block |
||
289 | 279 | * @param string $appPath |
290 | 280 | * @param null|User $user |
291 | 281 | */ |
292 | - public function __construct(\PDO $pdo, $appPath, User $user = null) |
|
293 | - { |
|
282 | + public function __construct(\PDO $pdo, $appPath, User $user = null) { |
|
294 | 283 | $this->pdo = $pdo; |
295 | 284 | $this->appPath = $appPath; |
296 | 285 | $this->user = $user; |
@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @package Zortje\MVC\Controller |
13 | 13 | */ |
14 | -class ControllerFactory |
|
15 | -{ |
|
14 | +class ControllerFactory { |
|
16 | 15 | |
17 | 16 | /** |
18 | 17 | * @var \PDO PDO |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | * @throws ControllerInvalidSuperclassException |
40 | 39 | * @throws ControllerNonexistentException |
41 | 40 | */ |
42 | - public function create($controller) |
|
43 | - { |
|
41 | + public function create($controller) { |
|
44 | 42 | if (!class_exists($controller)) { |
45 | 43 | throw new ControllerNonexistentException([$controller]); |
46 | 44 | } elseif (!is_subclass_of($controller, Controller::class)) { |
@@ -60,8 +58,7 @@ discard block |
||
60 | 58 | * @param string $appPath |
61 | 59 | * @param null|User $user |
62 | 60 | */ |
63 | - public function __construct(\PDO $pdo, $appPath, User $user = null) |
|
64 | - { |
|
61 | + public function __construct(\PDO $pdo, $appPath, User $user = null) { |
|
65 | 62 | $this->pdo = $pdo; |
66 | 63 | $this->appPath = $appPath; |
67 | 64 | $this->user = $user; |
@@ -7,15 +7,13 @@ |
||
7 | 7 | * |
8 | 8 | * @package Zortje\MVC\Controller |
9 | 9 | */ |
10 | -class NotFoundController extends Controller |
|
11 | -{ |
|
10 | +class NotFoundController extends Controller { |
|
12 | 11 | |
13 | 12 | protected $access = [ |
14 | 13 | 'index' => Controller::ACTION_PUBLIC |
15 | 14 | ]; |
16 | 15 | |
17 | - protected function index() |
|
18 | - { |
|
16 | + protected function index() { |
|
19 | 17 | $this->setResponseCode(404); |
20 | 18 | } |
21 | 19 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @package Zortje\MVC\Model |
9 | 9 | */ |
10 | -class SQLCommand |
|
11 | -{ |
|
10 | +class SQLCommand { |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * @var String Table name |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | * |
26 | 25 | * @return string INSERT INTO query |
27 | 26 | */ |
28 | - public function insertInto() |
|
29 | - { |
|
27 | + public function insertInto() { |
|
30 | 28 | $tableColumnNames = $this->getColumnNames($this->columns); |
31 | 29 | |
32 | 30 | $columns = $this->columns; |
@@ -42,8 +40,7 @@ discard block |
||
42 | 40 | * |
43 | 41 | * @return string SELECT FROM query |
44 | 42 | */ |
45 | - public function selectFrom() |
|
46 | - { |
|
43 | + public function selectFrom() { |
|
47 | 44 | $tableColumnNames = $this->getColumnNames($this->columns); |
48 | 45 | |
49 | 46 | return "SELECT $tableColumnNames FROM `$this->tableName`;"; |
@@ -56,8 +53,7 @@ discard block |
||
56 | 53 | * |
57 | 54 | * @return string SELECT FROM query |
58 | 55 | */ |
59 | - public function selectFromWhere($keys) |
|
60 | - { |
|
56 | + public function selectFromWhere($keys) { |
|
61 | 57 | $tableColumnNames = $this->getColumnNames($this->columns); |
62 | 58 | |
63 | 59 | $where = $this->getWhereConditionFromKeys($keys); |
@@ -72,8 +68,7 @@ discard block |
||
72 | 68 | * |
73 | 69 | * @return string Column names for column list |
74 | 70 | */ |
75 | - protected function getColumnNames($columns) |
|
76 | - { |
|
71 | + protected function getColumnNames($columns) { |
|
77 | 72 | $tableColumnNames = implode('`, `', array_keys($columns)); |
78 | 73 | |
79 | 74 | return "`{$tableColumnNames}`"; |
@@ -86,8 +81,7 @@ discard block |
||
86 | 81 | * |
87 | 82 | * @return string Column names for column values |
88 | 83 | */ |
89 | - protected function getColumnValues($columns) |
|
90 | - { |
|
84 | + protected function getColumnValues($columns) { |
|
91 | 85 | $tableColumnValues = implode(', :', array_keys($columns)); |
92 | 86 | |
93 | 87 | return ":{$tableColumnValues}"; |
@@ -100,8 +94,7 @@ discard block |
||
100 | 94 | * |
101 | 95 | * @return string |
102 | 96 | */ |
103 | - protected function getWhereConditionFromKeys($keys) |
|
104 | - { |
|
97 | + protected function getWhereConditionFromKeys($keys) { |
|
105 | 98 | $where = []; |
106 | 99 | |
107 | 100 | if (is_string($keys)) { |
@@ -121,8 +114,7 @@ discard block |
||
121 | 114 | * @param String $tableName |
122 | 115 | * @param String[] $columns |
123 | 116 | */ |
124 | - public function __construct($tableName, $columns) |
|
125 | - { |
|
117 | + public function __construct($tableName, $columns) { |
|
126 | 118 | $this->tableName = $tableName; |
127 | 119 | $this->columns = $columns; |
128 | 120 | } |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @package Zortje\MVC\Model\Table\Entity |
12 | 12 | */ |
13 | -abstract class Entity |
|
14 | -{ |
|
13 | +abstract class Entity { |
|
15 | 14 | |
16 | 15 | /** |
17 | 16 | * @var array Columns |
@@ -28,8 +27,7 @@ discard block |
||
28 | 27 | * |
29 | 28 | * @return array Entity columns |
30 | 29 | */ |
31 | - public static function getColumns() |
|
32 | - { |
|
30 | + public static function getColumns() { |
|
33 | 31 | $columns = array_merge([ |
34 | 32 | 'id' => 'integer' |
35 | 33 | ], static::$columns); |
@@ -51,8 +49,7 @@ discard block |
||
51 | 49 | * @throws InvalidEntityPropertyException If entity does not have that property |
52 | 50 | * @throws InvalidValueTypeForEntityPropertyException If value is of the wrong type |
53 | 51 | */ |
54 | - public function set($key, $value) |
|
55 | - { |
|
52 | + public function set($key, $value) { |
|
56 | 53 | if (!isset(self::getColumns()[$key])) { |
57 | 54 | throw new InvalidEntityPropertyException([get_class($this), $key]); |
58 | 55 | } |
@@ -69,8 +66,7 @@ discard block |
||
69 | 66 | * |
70 | 67 | * @throws InvalidEntityPropertyException If entity does not have that property |
71 | 68 | */ |
72 | - public function get($key) |
|
73 | - { |
|
69 | + public function get($key) { |
|
74 | 70 | if (!isset(self::getColumns()[$key])) { |
75 | 71 | throw new InvalidEntityPropertyException([get_class($this), $key]); |
76 | 72 | } |
@@ -86,8 +82,7 @@ discard block |
||
86 | 82 | * |
87 | 83 | * @return array |
88 | 84 | */ |
89 | - public function toArray($includeId) |
|
90 | - { |
|
85 | + public function toArray($includeId) { |
|
91 | 86 | $array = []; |
92 | 87 | |
93 | 88 | foreach (self::getColumns() as $column => $type) { |
@@ -117,8 +112,7 @@ discard block |
||
117 | 112 | * @throws InvalidEntityPropertyException If entity does not have that property |
118 | 113 | * @throws InvalidValueTypeForEntityPropertyException If value is of the wrong type |
119 | 114 | */ |
120 | - protected function validatePropertyForValue($key, $value) |
|
121 | - { |
|
115 | + protected function validatePropertyForValue($key, $value) { |
|
122 | 116 | if (!isset(self::getColumns()[$key])) { |
123 | 117 | throw new InvalidEntityPropertyException([get_class($this), $key]); |
124 | 118 | } |
@@ -168,8 +162,7 @@ discard block |
||
168 | 162 | * @param \DateTime $modified |
169 | 163 | * @param \DateTime $created |
170 | 164 | */ |
171 | - public function __construct($id, \DateTime $modified, \DateTime $created) |
|
172 | - { |
|
165 | + public function __construct($id, \DateTime $modified, \DateTime $created) { |
|
173 | 166 | $this->set('id', $id); |
174 | 167 | $this->set('modified', $modified); |
175 | 168 | $this->set('created', $created); |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @package Zortje\MVC\Model\Table\Entity |
9 | 9 | */ |
10 | -class EntityFactory |
|
11 | -{ |
|
10 | +class EntityFactory { |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * @var String Entity class |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * |
21 | 20 | * @return object |
22 | 21 | */ |
23 | - public function createFromArray(array $array) |
|
24 | - { |
|
22 | + public function createFromArray(array $array) { |
|
25 | 23 | /** |
26 | 24 | * @var Entity $entity |
27 | 25 | */ |
@@ -51,8 +49,7 @@ discard block |
||
51 | 49 | /** |
52 | 50 | * @param string $entityClass |
53 | 51 | */ |
54 | - public function __construct($entityClass) |
|
55 | - { |
|
52 | + public function __construct($entityClass) { |
|
56 | 53 | $this->entityClass = $entityClass; |
57 | 54 | } |
58 | 55 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @package Zortje\MVC\Model\Table\Entity |
9 | 9 | */ |
10 | -class EntityProperty |
|
11 | -{ |
|
10 | +class EntityProperty { |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * @var string Entity property type |
@@ -22,8 +21,7 @@ discard block |
||
22 | 21 | * |
23 | 22 | * @return mixed Value |
24 | 23 | */ |
25 | - public function formatValueForEntity($value) |
|
26 | - { |
|
24 | + public function formatValueForEntity($value) { |
|
27 | 25 | switch ($this->type) { |
28 | 26 | case 'string': |
29 | 27 | $value = "$value"; |
@@ -53,8 +51,7 @@ discard block |
||
53 | 51 | * |
54 | 52 | * @return mixed Value |
55 | 53 | */ |
56 | - public function formatValueForDatabase($value) |
|
57 | - { |
|
54 | + public function formatValueForDatabase($value) { |
|
58 | 55 | switch ($this->type) { |
59 | 56 | case 'Date': |
60 | 57 | /** |
@@ -77,8 +74,7 @@ discard block |
||
77 | 74 | /** |
78 | 75 | * @param string $type |
79 | 76 | */ |
80 | - public function __construct($type) |
|
81 | - { |
|
77 | + public function __construct($type) { |
|
82 | 78 | $this->type = $type; |
83 | 79 | } |
84 | 80 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @package Zortje\MVC\Model\Table\Entity\Exception |
11 | 11 | */ |
12 | -class EntityClassNonexistentException extends Exception |
|
13 | -{ |
|
12 | +class EntityClassNonexistentException extends Exception { |
|
14 | 13 | |
15 | 14 | /** |
16 | 15 | * {@inheritdoc} |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | /** |
21 | 20 | * {@inheritdoc} |
22 | 21 | */ |
23 | - public function __construct($message) |
|
24 | - { |
|
22 | + public function __construct($message) { |
|
25 | 23 | parent::__construct($message); |
26 | 24 | } |
27 | 25 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @package Zortje\MVC\Model\Table\Entity\Exception |
11 | 11 | */ |
12 | -class EntityClassNotDefinedException extends Exception |
|
13 | -{ |
|
12 | +class EntityClassNotDefinedException extends Exception { |
|
14 | 13 | |
15 | 14 | /** |
16 | 15 | * {@inheritdoc} |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | /** |
21 | 20 | * {@inheritdoc} |
22 | 21 | */ |
23 | - public function __construct($message) |
|
24 | - { |
|
22 | + public function __construct($message) { |
|
25 | 23 | parent::__construct($message); |
26 | 24 | } |
27 | 25 | } |