Skip to content

Commit

Permalink
[5.4] Makes cache() throw exceoption when incorrect first argument
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
regularlabs authored and taylorotwell committed May 2, 2017
1 parent 0d667f8 commit d9459b2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,19 @@ function cache()
return app('cache')->get($arguments[0], isset($arguments[1]) ? $arguments[1] : null);
}

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

return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
if (! isset($arguments[1])) {
throw new Exception(
'You must set an expiration time when putting to the cache.'
);
}

return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
}
}

Expand Down

0 comments on commit d9459b2

Please sign in to comment.