Skip to content

Commit 8fbeb93

Browse files
committed
refactor: replace empty()
1 parent b25ff87 commit 8fbeb93

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

system/View/Cell.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c
8484
$params = $this->prepareParams($params);
8585

8686
// Is the output cached?
87-
$cacheName = ! empty($cacheName)
88-
? $cacheName
89-
: str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params));
87+
$cacheName ??= str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params));
9088

91-
if (! empty($this->cache) && $output = $this->cache->get($cacheName)) {
89+
if ($output = $this->cache->get($cacheName)) {
9290
return $output;
9391
}
9492

@@ -105,7 +103,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c
105103
: $this->renderSimpleClass($instance, $method, $params, $class);
106104

107105
// Can we cache it?
108-
if (! empty($this->cache) && $ttl !== 0) {
106+
if ($ttl !== 0) {
109107
$this->cache->save($cacheName, $output, $ttl);
110108
}
111109

@@ -119,11 +117,14 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c
119117
*
120118
* @param array|string|null $params
121119
*
122-
* @return array|null
120+
* @return array
123121
*/
124122
public function prepareParams($params)
125123
{
126-
if (empty($params) || (! is_string($params) && ! is_array($params))) {
124+
if (
125+
($params === null || $params === '' || $params === [])
126+
|| (! is_string($params) && ! is_array($params))
127+
) {
127128
return [];
128129
}
129130

@@ -139,7 +140,7 @@ public function prepareParams($params)
139140
unset($separator);
140141

141142
foreach ($params as $p) {
142-
if (! empty($p)) {
143+
if ($p !== '') {
143144
[$key, $val] = explode('=', $p);
144145

145146
$newParams[trim($key)] = trim($val, ', ');
@@ -175,7 +176,7 @@ protected function determineClass(string $library): array
175176

176177
[$class, $method] = explode(':', $library);
177178

178-
if (empty($class)) {
179+
if ($class === '') {
179180
throw ViewException::forNoCellClass();
180181
}
181182

@@ -187,7 +188,7 @@ protected function determineClass(string $library): array
187188
throw ViewException::forInvalidCellClass($class);
188189
}
189190

190-
if (empty($method)) {
191+
if ($method === '') {
191192
$method = 'index';
192193
}
193194

@@ -274,7 +275,7 @@ final protected function renderSimpleClass($instance, string $method, array $par
274275
$refParams = $refMethod->getParameters();
275276

276277
if ($paramCount === 0) {
277-
if (! empty($params)) {
278+
if ($params !== []) {
278279
throw ViewException::forMissingCellParameters($class, $method);
279280
}
280281

0 commit comments

Comments
 (0)