@@ -42,8 +42,9 @@ |
||
42 | 42 | */ |
43 | 43 | public static function getDecoded($data, $key) |
44 | 44 | { |
45 | - if (!Any::isArray($data)) |
|
46 | - $data = self::decode($data); |
|
45 | + if (!Any::isArray($data)) { |
|
46 | + $data = self::decode($data); |
|
47 | + } |
|
47 | 48 | |
48 | 49 | return $data === false ? null : $data[$key]; |
49 | 50 | } |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | public static function convertToDatetime($rawDate, $format = 'd.m.Y') |
29 | 29 | { |
30 | 30 | // convert timestamp to date format |
31 | - if (Any::isInt($rawDate)) |
|
32 | - $rawDate = date(\DateTime::ATOM, $rawDate); |
|
31 | + if (Any::isInt($rawDate)) { |
|
32 | + $rawDate = date(\DateTime::ATOM, $rawDate); |
|
33 | + } |
|
33 | 34 | |
34 | 35 | try { |
35 | 36 | $object = new \DateTime($rawDate); |
@@ -61,15 +62,17 @@ discard block |
||
61 | 62 | // convert to timestamp |
62 | 63 | $timestamp = $raw; |
63 | 64 | // raw can be instance of eloquent active record object, convert to str |
64 | - if (!Any::isInt($raw)) |
|
65 | - $timestamp = self::convertToTimestamp((string)$timestamp); |
|
65 | + if (!Any::isInt($raw)) { |
|
66 | + $timestamp = self::convertToTimestamp((string)$timestamp); |
|
67 | + } |
|
66 | 68 | |
67 | 69 | // calculate difference between tomorrow day midnight and passed date |
68 | 70 | $diff = time() - $timestamp; |
69 | 71 | |
70 | 72 | // date in future, lets return as is |
71 | - if ($diff < 0) |
|
72 | - return self::convertToDatetime($timestamp, static::FORMAT_TO_SECONDS); |
|
73 | + if ($diff < 0) { |
|
74 | + return self::convertToDatetime($timestamp, static::FORMAT_TO_SECONDS); |
|
75 | + } |
|
73 | 76 | |
74 | 77 | // calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks! |
75 | 78 | $deltaSec = $diff % 60; |
@@ -86,8 +89,9 @@ discard block |
||
86 | 89 | // sounds like more then 1 day's ago |
87 | 90 | if ($deltaDays > 1) { |
88 | 91 | // sounds like more then 2 week ago, just return as is |
89 | - if ($deltaDays > 14) |
|
90 | - return self::convertToDatetime($timestamp, static::FORMAT_TO_HOUR); |
|
92 | + if ($deltaDays > 14) { |
|
93 | + return self::convertToDatetime($timestamp, static::FORMAT_TO_HOUR); |
|
94 | + } |
|
91 | 95 | |
92 | 96 | return App::$Translate->get('DateHuman', '%days% days ago', ['days' => (int)$deltaDays]); |
93 | 97 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | { |
94 | 94 | // looks like a single tag, <img src="" class="" />, <hr class="" /> |
95 | 95 | if (Arr::in($name, self::$singleTags)) { |
96 | - return '<' . $name . self::applyProperties($properties) . ' />'; |
|
97 | - } elseif(Arr::in($name, self::$containerTags)) { // looks like a container tag, <div class=""></div> |
|
98 | - return '<' . $name . self::applyProperties($properties) . '>' . $content . '</' . $name . '>'; |
|
96 | + return '<'.$name.self::applyProperties($properties).' />'; |
|
97 | + } elseif (Arr::in($name, self::$containerTags)) { // looks like a container tag, <div class=""></div> |
|
98 | + return '<'.$name.self::applyProperties($properties).'>'.$content.'</'.$name.'>'; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // empty response |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | } |
123 | 123 | // sounds like single standalone property, ex required, selected etc |
124 | 124 | if ($value === null || $value === false) { |
125 | - $build .= ' ' . htmlentities($property, ENT_QUOTES, "UTF-8"); |
|
125 | + $build .= ' '.htmlentities($property, ENT_QUOTES, "UTF-8"); |
|
126 | 126 | } else { // sounds like a classic key="value" property |
127 | - $build .= ' ' . htmlentities($property, ENT_QUOTES, "UTF-8") . '="' . htmlentities($value, ENT_QUOTES, "UTF-8") . '"'; |
|
127 | + $build .= ' '.htmlentities($property, ENT_QUOTES, "UTF-8").'="'.htmlentities($value, ENT_QUOTES, "UTF-8").'"'; |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | return $build; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | // set mobile collapse id for toggle |
37 | 37 | $mobCollapseId = $elements['collapseId']; |
38 | 38 | if (Any::isEmpty($mobCollapseId)) |
39 | - $mobCollapseId = Str::randomLatin(mt_rand(6,12)) . mt_rand(1, 99); |
|
39 | + $mobCollapseId = Str::randomLatin(mt_rand(6, 12)).mt_rand(1, 99); |
|
40 | 40 | |
41 | 41 | // set element id for toggle |
42 | 42 | $ulId = 1; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | // generate output dom of bootstrap navbar |
98 | 98 | $dom = new Dom(); |
99 | 99 | $body = $dom->div(function() use ($leftBuild, $rightBuild, $itemsStatic){ |
100 | - return $leftBuild . $itemsStatic . $rightBuild; |
|
100 | + return $leftBuild.$itemsStatic.$rightBuild; |
|
101 | 101 | }, ['class' => 'collapse navbar-collapse', 'id' => $mobCollapseId]); |
102 | 102 | |
103 | 103 | // drow <nav @properties>@next</nav> |
@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | $header = $dom->div(function() use ($dom, $elements, $mobCollapseId){ |
109 | 109 | // drow <button @collapse>@next</button> |
110 | 110 | $collapseButton = $dom->button(function() use ($dom){ |
111 | - $toggleItem = $dom->span(function(){ |
|
111 | + $toggleItem = $dom->span(function() { |
|
112 | 112 | return 'Toggle menu'; |
113 | 113 | }, ['class' => 'sr-only']); |
114 | 114 | $toggleIcon = null; |
115 | 115 | for ($i = 0; $i < 3; $i++) { |
116 | - $toggleIcon .= $dom->span(function(){ |
|
116 | + $toggleIcon .= $dom->span(function() { |
|
117 | 117 | return null; |
118 | 118 | }, ['class' => 'icon-bar']); |
119 | 119 | } |
120 | - return $toggleItem . $toggleIcon; |
|
121 | - }, ['type' => 'button', 'class' => 'navbar-toggle collapsed', 'data-toggle' => 'collapse', 'data-target' => '#' . $mobCollapseId]); |
|
120 | + return $toggleItem.$toggleIcon; |
|
121 | + }, ['type' => 'button', 'class' => 'navbar-toggle collapsed', 'data-toggle' => 'collapse', 'data-target' => '#'.$mobCollapseId]); |
|
122 | 122 | // drow <div @brand>@brandtext<?div> |
123 | 123 | $brand = null; |
124 | 124 | if (isset($elements['brand'])) { |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | }, $elements['brand']['property']); |
134 | 134 | } |
135 | 135 | } |
136 | - return $collapseButton . $brand; |
|
136 | + return $collapseButton.$brand; |
|
137 | 137 | }, ['class' => 'navbar-header']); |
138 | 138 | // return header and body concat |
139 | - return $header . $body; |
|
139 | + return $header.$body; |
|
140 | 140 | }, $elements['container']); |
141 | 141 | }, $elements['nav']); |
142 | 142 | } |
@@ -24,19 +24,22 @@ |
||
24 | 24 | public static function display(array $elements): ?string |
25 | 25 | { |
26 | 26 | // check if elements passed well |
27 | - if (!isset($elements['items']) || count($elements['items']) < 1) |
|
28 | - return null; |
|
27 | + if (!isset($elements['items']) || count($elements['items']) < 1) { |
|
28 | + return null; |
|
29 | + } |
|
29 | 30 | |
30 | 31 | // set default bootstrap properties if not defined |
31 | 32 | $elements['property']['class'] = Str::concat(' ', 'nav', $elements['property']['class']); |
32 | 33 | $elements['nav']['class'] = Str::concat(' ', 'navbar', $elements['nav']['class']); |
33 | - if (!$elements['container']) |
|
34 | - $elements['container'] = 'container-fluid'; |
|
34 | + if (!$elements['container']) { |
|
35 | + $elements['container'] = 'container-fluid'; |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // set mobile collapse id for toggle |
37 | 39 | $mobCollapseId = $elements['collapseId']; |
38 | - if (Any::isEmpty($mobCollapseId)) |
|
39 | - $mobCollapseId = Str::randomLatin(mt_rand(6,12)) . mt_rand(1, 99); |
|
40 | + if (Any::isEmpty($mobCollapseId)) { |
|
41 | + $mobCollapseId = Str::randomLatin(mt_rand(6,12)) . mt_rand(1, 99); |
|
42 | + } |
|
40 | 43 | |
41 | 44 | // set element id for toggle |
42 | 45 | $ulId = 1; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | // check if model has attribute |
78 | 78 | if (!property_exists($this->model, $rootName)) { |
79 | 79 | if (App::$Debug) |
80 | - App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error'); |
|
80 | + App::$Debug->addMessage('Field "'.$name.'" ('.$field.') is not defined in model: ['.get_class($this->model).']', 'error'); |
|
81 | 81 | |
82 | 82 | return null; |
83 | 83 | } |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | // prepare default layer if not passed |
86 | 86 | $layer = $this->findFieldLayer($field, $layer); |
87 | 87 | // prepare html attributes, object value |
88 | - $attr = $this->model->getFormName() . '-' . $rootName; |
|
88 | + $attr = $this->model->getFormName().'-'.$rootName; |
|
89 | 89 | $label = $this->model->getLabel($name); |
90 | 90 | $value = $this->model->{$rootName}; |
91 | 91 | // check if dot-nested array used and update attr name |
92 | 92 | if ($rootName !== $name) { |
93 | 93 | $nesting = trim(strstr($name, '.'), '.'); |
94 | - $attr .= '-' . Str::replace('.', '-', $nesting); |
|
94 | + $attr .= '-'.Str::replace('.', '-', $nesting); |
|
95 | 95 | $value = Arr::getByPath($nesting, $value); |
96 | 96 | } |
97 | 97 |
@@ -52,32 +52,38 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __call(string $field, ?array $arguments = null): ?string |
54 | 54 | { |
55 | - if ($arguments === null || count($arguments) < 1) |
|
56 | - return null; |
|
55 | + if ($arguments === null || count($arguments) < 1) { |
|
56 | + return null; |
|
57 | + } |
|
57 | 58 | |
58 | 59 | // get named arguments from passed array |
59 | 60 | $name = (string)$arguments[0]; |
60 | 61 | $rootName = $name; |
61 | 62 | // set root element name if array dot-nested notation found |
62 | - if (Str::contains('.', $name)) |
|
63 | - $rootName = strstr($rootName, '.', true); |
|
63 | + if (Str::contains('.', $name)) { |
|
64 | + $rootName = strstr($rootName, '.', true); |
|
65 | + } |
|
64 | 66 | // define properties, helper and layer |
65 | 67 | $properties = null; |
66 | 68 | $helper = null; |
67 | 69 | $layer = null; |
68 | - if (isset($arguments[1])) |
|
69 | - $properties = (array)$arguments[1]; |
|
70 | + if (isset($arguments[1])) { |
|
71 | + $properties = (array)$arguments[1]; |
|
72 | + } |
|
70 | 73 | |
71 | - if (isset($arguments[2])) |
|
72 | - $helper = (string)$arguments[2]; |
|
74 | + if (isset($arguments[2])) { |
|
75 | + $helper = (string)$arguments[2]; |
|
76 | + } |
|
73 | 77 | |
74 | - if (isset($arguments[3])) |
|
75 | - $layer = (string)$arguments[3]; |
|
78 | + if (isset($arguments[3])) { |
|
79 | + $layer = (string)$arguments[3]; |
|
80 | + } |
|
76 | 81 | |
77 | 82 | // check if model has attribute |
78 | 83 | if (!property_exists($this->model, $rootName)) { |
79 | - if (App::$Debug) |
|
80 | - App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error'); |
|
84 | + if (App::$Debug) { |
|
85 | + App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error'); |
|
86 | + } |
|
81 | 87 | |
82 | 88 | return null; |
83 | 89 | } |
@@ -100,8 +106,9 @@ discard block |
||
100 | 106 | $elementDOM = $constructor->makeTag($name, $value, $properties); |
101 | 107 | |
102 | 108 | // if item is hidden - return tag without assign of global template |
103 | - if ($field === 'hidden') |
|
104 | - return $elementDOM; |
|
109 | + if ($field === 'hidden') { |
|
110 | + return $elementDOM; |
|
111 | + } |
|
105 | 112 | |
106 | 113 | // prepare output html |
107 | 114 | try { |
@@ -112,8 +119,9 @@ discard block |
||
112 | 119 | 'help' => self::nohtml($helper) |
113 | 120 | ]); |
114 | 121 | } catch (SyntaxException $e) { |
115 | - if (App::$Debug) |
|
116 | - App::$Debug->addException($e); |
|
122 | + if (App::$Debug) { |
|
123 | + App::$Debug->addException($e); |
|
124 | + } |
|
117 | 125 | return null; |
118 | 126 | } |
119 | 127 | } |
@@ -126,8 +134,9 @@ discard block |
||
126 | 134 | */ |
127 | 135 | private function findFieldLayer(?string $type = null, ?string $layer = null): ?string |
128 | 136 | { |
129 | - if ($layer !== null) |
|
130 | - return $layer; |
|
137 | + if ($layer !== null) { |
|
138 | + return $layer; |
|
139 | + } |
|
131 | 140 | |
132 | 141 | switch ($type) { |
133 | 142 | case 'checkbox': |
@@ -36,7 +36,7 @@ |
||
36 | 36 | $options = $this->properties['options']; |
37 | 37 | unset($this->properties['options']); |
38 | 38 | if (!Any::isIterable($options)) |
39 | - throw new SyntaxException('Select field ' . self::nohtml($this->name) . ' have no iterable options'); |
|
39 | + throw new SyntaxException('Select field '.self::nohtml($this->name).' have no iterable options'); |
|
40 | 40 | // value is not used there |
41 | 41 | unset($this->properties['value']); |
42 | 42 | // options is defined as key->value array? |
@@ -35,8 +35,9 @@ |
||
35 | 35 | // get options from properties |
36 | 36 | $options = $this->properties['options']; |
37 | 37 | unset($this->properties['options']); |
38 | - if (!Any::isIterable($options)) |
|
39 | - throw new SyntaxException('Select field ' . self::nohtml($this->name) . ' have no iterable options'); |
|
38 | + if (!Any::isIterable($options)) { |
|
39 | + throw new SyntaxException('Select field ' . self::nohtml($this->name) . ' have no iterable options'); |
|
40 | + } |
|
40 | 41 | // value is not used there |
41 | 42 | unset($this->properties['value']); |
42 | 43 | // options is defined as key->value array? |
@@ -41,7 +41,7 @@ |
||
41 | 41 | // get options from properties |
42 | 42 | $options = $this->properties['options']; |
43 | 43 | if (!Any::isIterable($options)) |
44 | - throw new SyntaxException('Radio field ' . self::nohtml($this->name) . ' have no iterable options'); |
|
44 | + throw new SyntaxException('Radio field '.self::nohtml($this->name).' have no iterable options'); |
|
45 | 45 | |
46 | 46 | unset($this->properties['options'], $this->properties['value']); |
47 | 47 |
@@ -40,8 +40,9 @@ |
||
40 | 40 | { |
41 | 41 | // get options from properties |
42 | 42 | $options = $this->properties['options']; |
43 | - if (!Any::isIterable($options)) |
|
44 | - throw new SyntaxException('Radio field ' . self::nohtml($this->name) . ' have no iterable options'); |
|
43 | + if (!Any::isIterable($options)) { |
|
44 | + throw new SyntaxException('Radio field ' . self::nohtml($this->name) . ' have no iterable options'); |
|
45 | + } |
|
45 | 46 | |
46 | 47 | unset($this->properties['options'], $this->properties['value']); |
47 | 48 |
@@ -30,8 +30,9 @@ |
||
30 | 30 | */ |
31 | 31 | public function make() |
32 | 32 | { |
33 | - if (isset($this->properties['value'])) |
|
34 | - unset($this->properties['value']); |
|
33 | + if (isset($this->properties['value'])) { |
|
34 | + unset($this->properties['value']); |
|
35 | + } |
|
35 | 36 | |
36 | 37 | $this->properties['type'] = 'password'; |
37 | 38 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | } |
36 | 36 | // get image link |
37 | 37 | $image = App::$Captcha->get(); |
38 | - $response = '<img id="src-secure-image" src="' . $image . '" alt="captcha" onClick="this.src=\''.$image.'&rnd=\'+Math.random()" />'; |
|
38 | + $response = '<img id="src-secure-image" src="'.$image.'" alt="captcha" onClick="this.src=\''.$image.'&rnd=\'+Math.random()" />'; |
|
39 | 39 | // render response tag with image |
40 | 40 | $this->properties['type'] = 'text'; |
41 | 41 | $response .= self::buildSingleTag('input', $this->properties); |