Skip to content

Commit d9459b2

Browse files
regularlabstaylorotwell
authored andcommitted
[5.4] Makes cache() throw exceoption when incorrect first argument
The cache() function will return nothing when the first argument is something else than a string or array. This PR fixes that by throwing an exception when that is the case. It also improves code styling by removing the nested ifs (so less indentation) and follows the 'golden path' guideline.
1 parent 0d667f8 commit d9459b2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/Illuminate/Foundation/helpers.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,19 @@ function cache()
231231
return app('cache')->get($arguments[0], isset($arguments[1]) ? $arguments[1] : null);
232232
}
233233

234-
if (is_array($arguments[0])) {
235-
if (! isset($arguments[1])) {
236-
throw new Exception(
237-
'You must set an expiration time when putting to the cache.'
238-
);
239-
}
234+
if (! is_array($arguments[0])) {
235+
throw new Exception(
236+
'The argument passed to the cache must be a string or an array.'
237+
);
238+
}
240239

241-
return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
240+
if (! isset($arguments[1])) {
241+
throw new Exception(
242+
'You must set an expiration time when putting to the cache.'
243+
);
242244
}
245+
246+
return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
243247
}
244248
}
245249

0 commit comments

Comments
 (0)