From d9459b2f8bec4a807e7ba2b3301de4c5248aa933 Mon Sep 17 00:00:00 2001 From: Peter van Westen Date: Tue, 2 May 2017 11:04:50 +0200 Subject: [PATCH] [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. --- src/Illuminate/Foundation/helpers.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 7b108491ae31..5688dced0fea 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -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]); } }