@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | $selection = []; |
34 | 34 | |
35 | - foreach ($this->definition->paramsSecure() as $field) $selection[] = ('ent.' . $field); |
|
35 | + foreach ($this->definition->paramsSecure() as $field) $selection[] = ('ent.'.$field); |
|
36 | 36 | |
37 | 37 | # ------------------------ |
38 | 38 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | $order_by = []; |
47 | 47 | |
48 | - foreach ($this->castOrderBy($data) as $field => $direction) $order_by[] = ('ent.' . $field . ' ' . $direction); |
|
48 | + foreach ($this->castOrderBy($data) as $field => $direction) $order_by[] = ('ent.'.$field.' '.$direction); |
|
49 | 49 | |
50 | 50 | # ------------------------ |
51 | 51 |
@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | |
17 | 17 | foreach ($data as $field => $direction) { |
18 | 18 | |
19 | - if (false === ($param = $this->definition->param($field))) continue; |
|
19 | + if (false === ($param = $this->definition->param($field))) { |
|
20 | + continue; |
|
21 | + } |
|
20 | 22 | |
21 | 23 | $order_by[$param->name] = ((strtoupper($direction) !== 'DESC') ? 'ASC' : 'DESC'); |
22 | 24 | } |
@@ -32,7 +34,9 @@ discard block |
||
32 | 34 | |
33 | 35 | $selection = []; |
34 | 36 | |
35 | - foreach ($this->definition->paramsSecure() as $field) $selection[] = ('ent.' . $field); |
|
37 | + foreach ($this->definition->paramsSecure() as $field) { |
|
38 | + $selection[] = ('ent.' . $field); |
|
39 | + } |
|
36 | 40 | |
37 | 41 | # ------------------------ |
38 | 42 | |
@@ -45,7 +49,9 @@ discard block |
||
45 | 49 | |
46 | 50 | $order_by = []; |
47 | 51 | |
48 | - foreach ($this->castOrderBy($data) as $field => $direction) $order_by[] = ('ent.' . $field . ' ' . $direction); |
|
52 | + foreach ($this->castOrderBy($data) as $field => $direction) { |
|
53 | + $order_by[] = ('ent.' . $field . ' ' . $direction); |
|
54 | + } |
|
49 | 55 | |
50 | 56 | # ------------------------ |
51 | 57 |
@@ -2,7 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace Modules\Entitizer\Utils { |
4 | 4 | |
5 | - use Modules\Entitizer, Dataset as Config; |
|
5 | + use Modules\Entitizer; |
|
6 | + use Dataset as Config; |
|
6 | 7 | |
7 | 8 | abstract class Collection { |
8 | 9 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | return (0 !== $parent_id) ? (("JOIN " . static::$table_relations . " rel ") . |
14 | 14 | |
15 | - ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
15 | + ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
16 | 16 | |
17 | 17 | ("JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id"); |
18 | 18 | } |
@@ -23,13 +23,13 @@ discard block |
||
23 | 23 | |
24 | 24 | return ("SELECT " . $this->getSelection() . ", COALESCE(par.ancestor, 0) as parent_id ") . |
25 | 25 | |
26 | - ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
26 | + ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
27 | 27 | |
28 | - ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
28 | + ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
29 | 29 | |
30 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
30 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
31 | 31 | |
32 | - ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, " . $this->getOrderBy($order_by)); |
|
32 | + ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, " . $this->getOrderBy($order_by)); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | # Get count query |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | return ("SELECT COUNT(DISTINCT ent.id) as count FROM " . static::$table . " ent ") . |
40 | 40 | |
41 | - $this->getQueryJoin($parent_id); |
|
41 | + $this->getQueryJoin($parent_id); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | # Get depth query |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM " . static::$table . " ent ") . |
49 | 49 | |
50 | - $this->getQueryJoin($parent_id); |
|
50 | + $this->getQueryJoin($parent_id); |
|
51 | 51 | |
52 | 52 | # ------------------------ |
53 | 53 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | $query = ("SELECT " . $this->getSelection() . " FROM " . static::$table . " ent ") . |
130 | 130 | |
131 | - ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
131 | + ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
132 | 132 | |
133 | 133 | ("WHERE rel.descendant = " . $parent_id . " ORDER BY rel.depth DESC"); |
134 | 134 |
@@ -10,33 +10,31 @@ discard block |
||
10 | 10 | |
11 | 11 | protected function getQueryJoin(int $parent_id) { |
12 | 12 | |
13 | - return (0 !== $parent_id) ? (("JOIN " . static::$table_relations . " rel ") . |
|
13 | + return (0 !== $parent_id) ? (("JOIN ".static::$table_relations." rel "). |
|
14 | 14 | |
15 | - ("ON rel.ancestor = " . $parent_id . " AND rel.descendant = ent.id AND rel.depth >= 1")) : |
|
16 | - |
|
17 | - ("JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id"); |
|
15 | + ("ON rel.ancestor = ".$parent_id." AND rel.descendant = ent.id AND rel.depth >= 1")) : ("JOIN ".static::$table_relations." rel ON rel.descendant = ent.id"); |
|
18 | 16 | } |
19 | 17 | |
20 | 18 | # Get select query |
21 | 19 | |
22 | 20 | private function getSelectQuery(int $parent_id, array $config, array $order_by) { |
23 | 21 | |
24 | - return ("SELECT " . $this->getSelection() . ", COALESCE(par.ancestor, 0) as parent_id ") . |
|
22 | + return ("SELECT ".$this->getSelection().", COALESCE(par.ancestor, 0) as parent_id "). |
|
25 | 23 | |
26 | - ("FROM " . static::$table . " ent " . $this->getQueryJoin($parent_id) . " ") . |
|
24 | + ("FROM ".static::$table." ent ".$this->getQueryJoin($parent_id)." "). |
|
27 | 25 | |
28 | - ("LEFT JOIN " . static::$table_relations . " par ON par.descendant = ent.id AND par.depth = 1 ") . |
|
26 | + ("LEFT JOIN ".static::$table_relations." par ON par.descendant = ent.id AND par.depth = 1 "). |
|
29 | 27 | |
30 | - (('' !== ($condition = $this->getCondition($config))) ? ("WHERE " . $condition . " ") : "") . |
|
28 | + (('' !== ($condition = $this->getCondition($config))) ? ("WHERE ".$condition." ") : ""). |
|
31 | 29 | |
32 | - ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, " . $this->getOrderBy($order_by)); |
|
30 | + ("GROUP BY ent.id ORDER BY MAX(rel.depth) ASC, ".$this->getOrderBy($order_by)); |
|
33 | 31 | } |
34 | 32 | |
35 | 33 | # Get count query |
36 | 34 | |
37 | 35 | private function getCountQuery(int $parent_id) { |
38 | 36 | |
39 | - return ("SELECT COUNT(DISTINCT ent.id) as count FROM " . static::$table . " ent ") . |
|
37 | + return ("SELECT COUNT(DISTINCT ent.id) as count FROM ".static::$table." ent "). |
|
40 | 38 | |
41 | 39 | $this->getQueryJoin($parent_id); |
42 | 40 | } |
@@ -45,7 +43,7 @@ discard block |
||
45 | 43 | |
46 | 44 | private function getDepthQuery(int $parent_id) { |
47 | 45 | |
48 | - $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM " . static::$table . " ent ") . |
|
46 | + $query = ("SELECT COUNT(DISTINCT rel.depth) as depth FROM ".static::$table." ent "). |
|
49 | 47 | |
50 | 48 | $this->getQueryJoin($parent_id); |
51 | 49 | |
@@ -126,11 +124,11 @@ discard block |
||
126 | 124 | |
127 | 125 | # Process query |
128 | 126 | |
129 | - $query = ("SELECT " . $this->getSelection() . " FROM " . static::$table . " ent ") . |
|
127 | + $query = ("SELECT ".$this->getSelection()." FROM ".static::$table." ent "). |
|
130 | 128 | |
131 | - ("JOIN " . static::$table_relations . " rel ON rel.ancestor = ent.id ") . |
|
129 | + ("JOIN ".static::$table_relations." rel ON rel.ancestor = ent.id "). |
|
132 | 130 | |
133 | - ("WHERE rel.descendant = " . $parent_id . " ORDER BY rel.depth DESC"); |
|
131 | + ("WHERE rel.descendant = ".$parent_id." ORDER BY rel.depth DESC"); |
|
134 | 132 | |
135 | 133 | # Select path |
136 | 134 |
@@ -58,13 +58,17 @@ discard block |
||
58 | 58 | |
59 | 59 | public function subtree(int $parent_id = 0, array $config = [], array $order_by = []) { |
60 | 60 | |
61 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
61 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
62 | + return false; |
|
63 | + } |
|
62 | 64 | |
63 | 65 | # Select entities |
64 | 66 | |
65 | 67 | $query = $this->getSelectQuery($parent_id, $config, $order_by); |
66 | 68 | |
67 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
69 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
70 | + return false; |
|
71 | + } |
|
68 | 72 | |
69 | 73 | # Process results |
70 | 74 | |
@@ -88,13 +92,17 @@ discard block |
||
88 | 92 | |
89 | 93 | public function subtreeCount(int $parent_id = 0) { |
90 | 94 | |
91 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
95 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
96 | + return false; |
|
97 | + } |
|
92 | 98 | |
93 | 99 | # Get count |
94 | 100 | |
95 | 101 | $query = $this->getCountQuery($parent_id); |
96 | 102 | |
97 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
103 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
104 | + return false; |
|
105 | + } |
|
98 | 106 | |
99 | 107 | # ------------------------ |
100 | 108 | |
@@ -105,13 +113,17 @@ discard block |
||
105 | 113 | |
106 | 114 | public function subtreeDepth(int $parent_id = 0) { |
107 | 115 | |
108 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
116 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
117 | + return false; |
|
118 | + } |
|
109 | 119 | |
110 | 120 | # Get depth |
111 | 121 | |
112 | 122 | $query = $this->getDepthQuery($parent_id); |
113 | 123 | |
114 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
124 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
125 | + return false; |
|
126 | + } |
|
115 | 127 | |
116 | 128 | # ------------------------ |
117 | 129 | |
@@ -122,7 +134,9 @@ discard block |
||
122 | 134 | |
123 | 135 | public function path(int $parent_id = 0) { |
124 | 136 | |
125 | - if (!(static::$nesting && ($parent_id >= 0))) return false; |
|
137 | + if (!(static::$nesting && ($parent_id >= 0))) { |
|
138 | + return false; |
|
139 | + } |
|
126 | 140 | |
127 | 141 | # Process query |
128 | 142 | |
@@ -134,13 +148,17 @@ discard block |
||
134 | 148 | |
135 | 149 | # Select path |
136 | 150 | |
137 | - if (!(DB::send($query) && DB::getLast()->status)) return false; |
|
151 | + if (!(DB::send($query) && DB::getLast()->status)) { |
|
152 | + return false; |
|
153 | + } |
|
138 | 154 | |
139 | 155 | # Process results |
140 | 156 | |
141 | 157 | $path = []; |
142 | 158 | |
143 | - while (null !== ($data = DB::getLast()->getRow())) $path[] = Entitizer::dataset(static::$table, $data)->data(); |
|
159 | + while (null !== ($data = DB::getLast()->getRow())) { |
|
160 | + $path[] = Entitizer::dataset(static::$table, $data)->data(); |
|
161 | + } |
|
144 | 162 | |
145 | 163 | # ------------------------ |
146 | 164 |
@@ -10,7 +10,9 @@ |
||
10 | 10 | |
11 | 11 | public function add(string $name, string $table, string $field, string $delete = null, string $update = null) { |
12 | 12 | |
13 | - if ((false === $this->definition->param($name)) || isset($this->list[$name])) return; |
|
13 | + if ((false === $this->definition->param($name)) || isset($this->list[$name])) { |
|
14 | + return; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | $this->list[$name] = new Definition\Item\Foreign($name, $table, $field, $delete, $update); |
16 | 18 | } |
@@ -12,9 +12,13 @@ |
||
12 | 12 | |
13 | 13 | public static function get(string $table) { |
14 | 14 | |
15 | - if (!isset(static::$classes[$table])) throw new Exception\General(static::$error_message); |
|
15 | + if (!isset(static::$classes[$table])) { |
|
16 | + throw new Exception\General(static::$error_message); |
|
17 | + } |
|
16 | 18 | |
17 | - if (!isset(static::$cache[$table])) static::$cache[$table] = new static::$classes[$table]; |
|
19 | + if (!isset(static::$cache[$table])) { |
|
20 | + static::$cache[$table] = new static::$classes[$table]; |
|
21 | + } |
|
18 | 22 | |
19 | 23 | # ------------------------ |
20 | 24 |
@@ -25,9 +25,13 @@ |
||
25 | 25 | |
26 | 26 | public static function get(string $table, int $id = 0) { |
27 | 27 | |
28 | - if (!isset(self::$classes[$table])) throw new Exception\General(self::$error_message); |
|
28 | + if (!isset(self::$classes[$table])) { |
|
29 | + throw new Exception\General(self::$error_message); |
|
30 | + } |
|
29 | 31 | |
30 | - if (isset(self::$cache[$table][$id])) return self::$cache[$table][$id]; |
|
32 | + if (isset(self::$cache[$table][$id])) { |
|
33 | + return self::$cache[$table][$id]; |
|
34 | + } |
|
31 | 35 | |
32 | 36 | $entity = new self::$classes[$table]; $entity->init($id); |
33 | 37 |
@@ -10,7 +10,9 @@ |
||
10 | 10 | |
11 | 11 | public function add(string $name, string $table, string $field, string $delete = null, string $update = null) { |
12 | 12 | |
13 | - if ((false === $this->definition->param($name)) || isset($this->list[$name])) return; |
|
13 | + if ((false === $this->definition->param($name)) || isset($this->list[$name])) { |
|
14 | + return; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | $this->list[$name] = new Definition\Item\Foreign($name, $table, $field, $delete, $update); |
16 | 18 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * If a validator was not given, a default validator will be used to convert a given variable type to a default's type. |
30 | 30 | * In a case the conversion fails an existing value will not be changed |
31 | 31 | * |
32 | - * @return the current dataset object |
|
32 | + * @return null|Dataset current dataset object |
|
33 | 33 | */ |
34 | 34 | |
35 | 35 | public function addParam(string $name, $default, callable $validator = null) { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * Add multiple params |
50 | 50 | * |
51 | - * @return the current dataset object |
|
51 | + * @return Dataset current dataset object |
|
52 | 52 | */ |
53 | 53 | |
54 | 54 | public function addParams(array $data) { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * Update a value |
63 | 63 | * |
64 | - * @return true on success, false on error, or null if the param does not exist |
|
64 | + * @return null|boolean on success, false on error, or null if the param does not exist |
|
65 | 65 | */ |
66 | 66 | |
67 | 67 | public function set(string $name, $value) { |
@@ -34,7 +34,9 @@ discard block |
||
34 | 34 | |
35 | 35 | public function addParam(string $name, $default, callable $validator = null) { |
36 | 36 | |
37 | - if ('' === $name) return; |
|
37 | + if ('' === $name) { |
|
38 | + return; |
|
39 | + } |
|
38 | 40 | |
39 | 41 | $this->data[$name] = $default; $this->defaults[$name] = $default; |
40 | 42 | |
@@ -53,7 +55,9 @@ discard block |
||
53 | 55 | |
54 | 56 | public function addParams(array $data) { |
55 | 57 | |
56 | - foreach ($data as $name => $value) if (is_scalar($name)) $this->addParam($name, $value); |
|
58 | + foreach ($data as $name => $value) { |
|
59 | + if (is_scalar($name)) $this->addParam($name, $value); |
|
60 | + } |
|
57 | 61 | |
58 | 62 | return $this; |
59 | 63 | } |
@@ -66,16 +70,16 @@ discard block |
||
66 | 70 | |
67 | 71 | public function set(string $name, $value) { |
68 | 72 | |
69 | - if (!isset($this->validators[$name])) return null; |
|
73 | + if (!isset($this->validators[$name])) { |
|
74 | + return null; |
|
75 | + } |
|
70 | 76 | |
71 | 77 | try { |
72 | 78 | |
73 | - if (null === ($value = $this->validators[$name]($value))) return false; |
|
74 | - |
|
75 | - else { $this->data[$name] = $value; return true; } |
|
76 | - } |
|
77 | - |
|
78 | - catch (TypeError $e) { return false; } |
|
79 | + if (null === ($value = $this->validators[$name]($value))) { |
|
80 | + return false; |
|
81 | + } else { $this->data[$name] = $value; return true; } |
|
82 | + } catch (TypeError $e) { return false; } |
|
79 | 83 | } |
80 | 84 | |
81 | 85 | /** |
@@ -90,7 +94,9 @@ discard block |
||
90 | 94 | |
91 | 95 | foreach ($data as $name => $value) { |
92 | 96 | |
93 | - if (null !== ($value = $this->set($name, $value))) $setted[$name] = $value; |
|
97 | + if (null !== ($value = $this->set($name, $value))) { |
|
98 | + $setted[$name] = $value; |
|
99 | + } |
|
94 | 100 | } |
95 | 101 | |
96 | 102 | # ------------------------ |
@@ -106,16 +112,18 @@ discard block |
||
106 | 112 | |
107 | 113 | public function cast(string $name, $value) { |
108 | 114 | |
109 | - if (!isset($this->validators[$name])) return null; |
|
115 | + if (!isset($this->validators[$name])) { |
|
116 | + return null; |
|
117 | + } |
|
110 | 118 | |
111 | 119 | try { |
112 | 120 | |
113 | - if (null !== ($value = $this->validators[$name]($value))) return $value; |
|
114 | - |
|
115 | - else return $this->data[$name]; |
|
116 | - } |
|
117 | - |
|
118 | - catch (TypeError $e) { return $this->data[$name]; } |
|
121 | + if (null !== ($value = $this->validators[$name]($value))) { |
|
122 | + return $value; |
|
123 | + } else { |
|
124 | + return $this->data[$name]; |
|
125 | + } |
|
126 | + } catch (TypeError $e) { return $this->data[$name]; } |
|
119 | 127 | } |
120 | 128 | |
121 | 129 | /** |
@@ -130,7 +138,9 @@ discard block |
||
130 | 138 | |
131 | 139 | foreach ($data as $name => $value) { |
132 | 140 | |
133 | - if (null !== ($value = $this->cast($name, $value))) $casted[$name] = $value; |
|
141 | + if (null !== ($value = $this->cast($name, $value))) { |
|
142 | + $casted[$name] = $value; |
|
143 | + } |
|
134 | 144 | } |
135 | 145 | |
136 | 146 | # ------------------------ |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Validate a date using a given format |
16 | 16 | * |
17 | - * @return the formatted date or false on failure |
|
17 | + * @return string|null formatted date or false on failure |
|
18 | 18 | */ |
19 | 19 | |
20 | 20 | public static function validate(string $date, string $format) { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * Get a date from a given timestamp and format it according to a given pattern. |
68 | 68 | * If the timestamp is null, a current time will be used |
69 | 69 | * |
70 | - * @return the formatted date or false if a non-numeric value is used for timestamp |
|
70 | + * @return string formatted date or false if a non-numeric value is used for timestamp |
|
71 | 71 | */ |
72 | 72 | |
73 | 73 | public static function get(string $format = DATE_FORMAT_STANDART, int $time = null) { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | /** |
79 | 79 | * Get a day from a given timestamp. If the timestamp is null, a current time will be used |
80 | 80 | * |
81 | - * @return the formatted day or false if a non-numeric value is used for timestamp |
|
81 | + * @return string formatted day or false if a non-numeric value is used for timestamp |
|
82 | 82 | */ |
83 | 83 | |
84 | 84 | public static function getDay(int $time = null) { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * Get a month from a given timestamp. If the timestamp is null, a current time will be used |
91 | 91 | * |
92 | - * @return the formatted month or false if a non-numeric value is used for timestamp |
|
92 | + * @return string formatted month or false if a non-numeric value is used for timestamp |
|
93 | 93 | */ |
94 | 94 | |
95 | 95 | public static function getMonth(int $time = null) { |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * Get a year from a given timestamp. If the timestamp is null, a current time will be used |
102 | 102 | * |
103 | - * @return the formatted year or false if a non-numeric value is used for timestamp |
|
103 | + * @return string formatted year or false if a non-numeric value is used for timestamp |
|
104 | 104 | */ |
105 | 105 | |
106 | 106 | public static function getYear(int $time = null) { |
@@ -19,9 +19,13 @@ discard block |
||
19 | 19 | |
20 | 20 | public static function validate(string $date, string $format) { |
21 | 21 | |
22 | - if (false === ($datetime = date_create_from_format($format, $date))) return false; |
|
22 | + if (false === ($datetime = date_create_from_format($format, $date))) { |
|
23 | + return false; |
|
24 | + } |
|
23 | 25 | |
24 | - if (false === ($formatted = $datetime->format($format))) return false; |
|
26 | + if (false === ($formatted = $datetime->format($format))) { |
|
27 | + return false; |
|
28 | + } |
|
25 | 29 | |
26 | 30 | # ------------------------ |
27 | 31 | |
@@ -58,7 +62,9 @@ discard block |
||
58 | 62 | |
59 | 63 | public static function validateYear(int $year) { |
60 | 64 | |
61 | - if (false === ($year = self::validate($year, 'Y'))) return false; |
|
65 | + if (false === ($year = self::validate($year, 'Y'))) { |
|
66 | + return false; |
|
67 | + } |
|
62 | 68 | |
63 | 69 | return (($year > '1900') ? (($year > self::getYear()) ? self::getYear() : $year) : '1900'); |
64 | 70 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * Get an extnesion of a file |
191 | 191 | * |
192 | - * @return a string or false if check_exists is true and the file does not actually exists |
|
192 | + * @return string string or false if check_exists is true and the file does not actually exists |
|
193 | 193 | */ |
194 | 194 | |
195 | 195 | public static function getExtension(string $file_name, bool $check_exists = true) { |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | /** |
212 | 212 | * Get file contents |
213 | 213 | * |
214 | - * @return the read data or false on failure |
|
214 | + * @return string read data or false on failure |
|
215 | 215 | */ |
216 | 216 | |
217 | 217 | public static function getContents(string $file_name) { |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | |
24 | 24 | if (($name === '.') || ($name === '..')) continue; |
25 | 25 | |
26 | - if (@$checker($dir_name . $name)) yield $name; |
|
26 | + if (@$checker($dir_name.$name)) yield $name; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | closedir($handler); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | foreach (array_diff($list, ['.', '..']) as $name) { |
95 | 95 | |
96 | - $name = ($dir_name . '/' . $name); |
|
96 | + $name = ($dir_name.'/'.$name); |
|
97 | 97 | |
98 | 98 | if (@is_dir($name)) self::removeDir($name, true); |
99 | 99 |
@@ -21,9 +21,13 @@ discard block |
||
21 | 21 | |
22 | 22 | while (false !== ($name = readdir($handler))) { |
23 | 23 | |
24 | - if (($name === '.') || ($name === '..')) continue; |
|
24 | + if (($name === '.') || ($name === '..')) { |
|
25 | + continue; |
|
26 | + } |
|
25 | 27 | |
26 | - if (@$checker($dir_name . $name)) yield $name; |
|
28 | + if (@$checker($dir_name . $name)) { |
|
29 | + yield $name; |
|
30 | + } |
|
27 | 31 | } |
28 | 32 | |
29 | 33 | closedir($handler); |
@@ -36,7 +40,9 @@ discard block |
||
36 | 40 | |
37 | 41 | private static function getInfo(string $file_name, int $param, bool $check_exists = true) { |
38 | 42 | |
39 | - if ($check_exists && !self::isFile($file_name)) return false; |
|
43 | + if ($check_exists && !self::isFile($file_name)) { |
|
44 | + return false; |
|
45 | + } |
|
40 | 46 | |
41 | 47 | return pathinfo($file_name, $param); |
42 | 48 | } |
@@ -95,9 +101,11 @@ discard block |
||
95 | 101 | |
96 | 102 | $name = ($dir_name . '/' . $name); |
97 | 103 | |
98 | - if (@is_dir($name)) self::removeDir($name, true); |
|
99 | - |
|
100 | - else if (@is_file($name)) self::removeFile($name); |
|
104 | + if (@is_dir($name)) { |
|
105 | + self::removeDir($name, true); |
|
106 | + } else if (@is_file($name)) { |
|
107 | + self::removeFile($name); |
|
108 | + } |
|
101 | 109 | } |
102 | 110 | } |
103 | 111 | |
@@ -123,7 +131,9 @@ discard block |
||
123 | 131 | |
124 | 132 | public static function iterateDirs(string $dir_name) { |
125 | 133 | |
126 | - foreach (self::getList($dir_name, 'is_dir') as $name) yield $name; |
|
134 | + foreach (self::getList($dir_name, 'is_dir') as $name) { |
|
135 | + yield $name; |
|
136 | + } |
|
127 | 137 | } |
128 | 138 | |
129 | 139 | /** |
@@ -132,7 +142,9 @@ discard block |
||
132 | 142 | |
133 | 143 | public static function iterateFiles(string $dir_name) { |
134 | 144 | |
135 | - foreach (self::getList($dir_name, 'is_file') as $name) yield $name; |
|
145 | + foreach (self::getList($dir_name, 'is_file') as $name) { |
|
146 | + yield $name; |
|
147 | + } |
|
136 | 148 | } |
137 | 149 | |
138 | 150 | /** |
@@ -238,7 +250,9 @@ discard block |
||
238 | 250 | |
239 | 251 | public static function include(string $file_name) { |
240 | 252 | |
241 | - if ((strtolower(self::getExtension($file_name)) !== 'php')) return false; |
|
253 | + if ((strtolower(self::getExtension($file_name)) !== 'php')) { |
|
254 | + return false; |
|
255 | + } |
|
242 | 256 | |
243 | 257 | return @include $file_name; |
244 | 258 | } |