From e20bd143aa32063b92c314a8a811a3468d1e5656 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Thu, 31 Aug 2017 23:43:42 +0200 Subject: [PATCH] Get rid of all useless else return --- src/Illuminate/Bus/Dispatcher.php | 8 ++++---- src/Illuminate/Cache/CacheManager.php | 16 ++++++++-------- .../Console/Scheduling/CommandBuilder.php | 4 ++-- .../Database/Connectors/PostgresConnector.php | 4 ++-- .../Database/Connectors/SqlServerConnector.php | 8 ++++---- .../Database/Migrations/MigrationCreator.php | 6 ++---- src/Illuminate/Database/Migrations/Migrator.php | 12 ++++++------ src/Illuminate/Database/Query/Builder.php | 7 +++---- .../Database/Query/Grammars/MySqlGrammar.php | 4 ++-- src/Illuminate/Events/Dispatcher.php | 16 ++++++++-------- src/Illuminate/Filesystem/FilesystemAdapter.php | 8 ++++---- src/Illuminate/Filesystem/FilesystemManager.php | 4 ++-- .../Foundation/Console/ListenerMakeCommand.php | 8 ++++---- .../Foundation/Console/TestMakeCommand.php | 8 ++++---- .../Foundation/Testing/TestResponse.php | 4 ++-- src/Illuminate/Foundation/helpers.php | 8 ++++---- src/Illuminate/Mail/Mailable.php | 4 ++-- src/Illuminate/Routing/ResourceRegistrar.php | 4 ++-- src/Illuminate/Routing/RouteUrlGenerator.php | 8 ++++---- src/Illuminate/Routing/UrlGenerator.php | 8 ++++---- src/Illuminate/Session/SessionManager.php | 4 ++-- src/Illuminate/Support/Arr.php | 4 ++-- src/Illuminate/Support/Collection.php | 4 ++-- src/Illuminate/Support/Manager.php | 11 ++++++----- .../Validation/ValidationRuleParser.php | 4 ++-- tests/Database/DatabaseConnectorTest.php | 14 +++++++------- 26 files changed, 94 insertions(+), 96 deletions(-) diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 9733b442f9c3..1a7b9a4087a9 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -71,9 +71,9 @@ public function dispatch($command) { if ($this->queueResolver && $this->commandShouldBeQueued($command)) { return $this->dispatchToQueue($command); - } else { - return $this->dispatchNow($command); } + + return $this->dispatchNow($command); } /** @@ -155,9 +155,9 @@ public function dispatchToQueue($command) if (method_exists($command, 'queue')) { return $command->queue($queue, $command); - } else { - return $this->pushCommandToQueue($queue, $command); } + + return $this->pushCommandToQueue($queue, $command); } /** diff --git a/src/Illuminate/Cache/CacheManager.php b/src/Illuminate/Cache/CacheManager.php index f52053c9b0bf..19721aa471e7 100755 --- a/src/Illuminate/Cache/CacheManager.php +++ b/src/Illuminate/Cache/CacheManager.php @@ -98,15 +98,15 @@ protected function resolve($name) if (isset($this->customCreators[$config['driver']])) { return $this->callCustomCreator($config); - } else { - $driverMethod = 'create'.ucfirst($config['driver']).'Driver'; - - if (method_exists($this, $driverMethod)) { - return $this->{$driverMethod}($config); - } else { - throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported."); - } } + + $driverMethod = 'create'.ucfirst($config['driver']).'Driver'; + + if (method_exists($this, $driverMethod)) { + return $this->{$driverMethod}($config); + } + + throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported."); } /** diff --git a/src/Illuminate/Console/Scheduling/CommandBuilder.php b/src/Illuminate/Console/Scheduling/CommandBuilder.php index acf60dd60484..4e37a0d7c402 100644 --- a/src/Illuminate/Console/Scheduling/CommandBuilder.php +++ b/src/Illuminate/Console/Scheduling/CommandBuilder.php @@ -17,9 +17,9 @@ public function buildCommand(Event $event) { if ($event->runInBackground) { return $this->buildBackgroundCommand($event); - } else { - return $this->buildForegroundCommand($event); } + + return $this->buildForegroundCommand($event); } /** diff --git a/src/Illuminate/Database/Connectors/PostgresConnector.php b/src/Illuminate/Database/Connectors/PostgresConnector.php index 0581b8b2aa5a..5129b4b4474d 100755 --- a/src/Illuminate/Database/Connectors/PostgresConnector.php +++ b/src/Illuminate/Database/Connectors/PostgresConnector.php @@ -106,9 +106,9 @@ protected function formatSchema($schema) { if (is_array($schema)) { return '"'.implode('", "', $schema).'"'; - } else { - return '"'.$schema.'"'; } + + return '"'.$schema.'"'; } /** diff --git a/src/Illuminate/Database/Connectors/SqlServerConnector.php b/src/Illuminate/Database/Connectors/SqlServerConnector.php index 397538281d08..5472ff9fa96f 100755 --- a/src/Illuminate/Database/Connectors/SqlServerConnector.php +++ b/src/Illuminate/Database/Connectors/SqlServerConnector.php @@ -47,9 +47,9 @@ protected function getDsn(array $config) return $this->getDblibDsn($config); } elseif ($this->prefersOdbc($config)) { return $this->getOdbcDsn($config); - } else { - return $this->getSqlSrvDsn($config); } + + return $this->getSqlSrvDsn($config); } /** @@ -158,9 +158,9 @@ protected function buildHostString(array $config, $separator) { if (isset($config['port']) && ! empty($config['port'])) { return $config['host'].$separator.$config['port']; - } else { - return $config['host']; } + + return $config['host']; } /** diff --git a/src/Illuminate/Database/Migrations/MigrationCreator.php b/src/Illuminate/Database/Migrations/MigrationCreator.php index 29bae7add9f4..1ccc09adde24 100755 --- a/src/Illuminate/Database/Migrations/MigrationCreator.php +++ b/src/Illuminate/Database/Migrations/MigrationCreator.php @@ -97,11 +97,9 @@ protected function getStub($table, $create) // We also have stubs for creating new tables and modifying existing tables // to save the developer some typing when they are creating a new tables // or modifying existing tables. We'll grab the appropriate stub here. - else { - $stub = $create ? 'create.stub' : 'update.stub'; + $stub = $create ? 'create.stub' : 'update.stub'; - return $this->files->get($this->stubPath()."/{$stub}"); - } + return $this->files->get($this->stubPath()."/{$stub}"); } /** diff --git a/src/Illuminate/Database/Migrations/Migrator.php b/src/Illuminate/Database/Migrations/Migrator.php index 535bb316facd..45979389f62e 100755 --- a/src/Illuminate/Database/Migrations/Migrator.php +++ b/src/Illuminate/Database/Migrations/Migrator.php @@ -204,9 +204,9 @@ public function rollback($paths = [], array $options = []) $this->note('Nothing to rollback.'); return []; - } else { - return $this->rollbackMigrations($migrations, $paths, $options); } + + return $this->rollbackMigrations($migrations, $paths, $options); } /** @@ -219,9 +219,9 @@ protected function getMigrationsForRollback(array $options) { if (($steps = $options['step'] ?? 0) > 0) { return $this->repository->getMigrations($steps); - } else { - return $this->repository->getLast(); } + + return $this->repository->getLast(); } /** @@ -281,9 +281,9 @@ public function reset($paths = [], $pretend = false) $this->note('Nothing to rollback.'); return []; - } else { - return $this->resetMigrations($migrations, $paths, $pretend); } + + return $this->resetMigrations($migrations, $paths, $pretend); } /** diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 54f84a93e3b6..fa3f93c168da 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -284,9 +284,8 @@ protected function parseSubSelect($query) return [$query->toSql(), $query->getBindings()]; } elseif (is_string($query)) { return [$query, []]; - } else { - throw new InvalidArgumentException; } + throw new InvalidArgumentException; } /** @@ -1771,9 +1770,9 @@ public function getCountForPagination($columns = ['*']) return 0; } elseif (is_object($results[0])) { return (int) $results[0]->aggregate; - } else { - return (int) array_change_key_case((array) $results[0])['aggregate']; } + + return (int) array_change_key_case((array) $results[0])['aggregate']; } /** diff --git a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php index 6943c147a07c..4403a25724b1 100755 --- a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php @@ -144,9 +144,9 @@ protected function compileUpdateColumns($values) return collect($values)->map(function ($value, $key) { if ($this->isJsonSelector($key)) { return $this->compileJsonUpdateColumn($key, new JsonExpression($value)); - } else { - return $this->wrap($key).' = '.$this->parameter($value); } + + return $this->wrap($key).' = '.$this->parameter($value); })->implode(', '); } diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index 28115a7d798a..d99031cf0269 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -345,9 +345,9 @@ public function makeListener($listener, $wildcard = false) return function ($event, $payload) use ($listener, $wildcard) { if ($wildcard) { return $listener($event, $payload); - } else { - return $listener(...array_values($payload)); } + + return $listener(...array_values($payload)); }; } @@ -363,11 +363,11 @@ public function createClassListener($listener, $wildcard = false) return function ($event, $payload) use ($listener, $wildcard) { if ($wildcard) { return call_user_func($this->createClassCallable($listener), $event, $payload); - } else { - return call_user_func_array( - $this->createClassCallable($listener), $payload - ); } + + return call_user_func_array( + $this->createClassCallable($listener), $payload + ); }; } @@ -383,9 +383,9 @@ protected function createClassCallable($listener) if ($this->handlerShouldBeQueued($class)) { return $this->createQueuedHandlerCallable($class, $method); - } else { - return [$this->container->make($class), $method]; } + + return [$this->container->make($class), $method]; } /** diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index 4253298876a2..5735a800d82f 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -332,9 +332,9 @@ public function url($path) return $this->getAwsUrl($adapter, $path); } elseif ($adapter instanceof LocalAdapter) { return $this->getLocalUrl($path); - } else { - throw new RuntimeException('This driver does not support retrieving URLs.'); } + + throw new RuntimeException('This driver does not support retrieving URLs.'); } /** @@ -375,9 +375,9 @@ protected function getLocalUrl($path) // are really supposed to use. We will remove the public from this path here. if (Str::contains($path, '/storage/public/')) { return Str::replaceFirst('/public/', '/', $path); - } else { - return $path; } + + return $path; } /** diff --git a/src/Illuminate/Filesystem/FilesystemManager.php b/src/Illuminate/Filesystem/FilesystemManager.php index 7bf8c008034e..53ee57174c8e 100644 --- a/src/Illuminate/Filesystem/FilesystemManager.php +++ b/src/Illuminate/Filesystem/FilesystemManager.php @@ -120,9 +120,9 @@ protected function resolve($name) if (method_exists($this, $driverMethod)) { return $this->{$driverMethod}($config); - } else { - throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported."); } + + throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported."); } /** diff --git a/src/Illuminate/Foundation/Console/ListenerMakeCommand.php b/src/Illuminate/Foundation/Console/ListenerMakeCommand.php index bcf6892c7119..ce3e25ef059f 100644 --- a/src/Illuminate/Foundation/Console/ListenerMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ListenerMakeCommand.php @@ -67,11 +67,11 @@ protected function getStub() return $this->option('event') ? __DIR__.'/stubs/listener-queued.stub' : __DIR__.'/stubs/listener-queued-duck.stub'; - } else { - return $this->option('event') - ? __DIR__.'/stubs/listener.stub' - : __DIR__.'/stubs/listener-duck.stub'; } + + return $this->option('event') + ? __DIR__.'/stubs/listener.stub' + : __DIR__.'/stubs/listener-duck.stub'; } /** diff --git a/src/Illuminate/Foundation/Console/TestMakeCommand.php b/src/Illuminate/Foundation/Console/TestMakeCommand.php index 15b8cdf85368..eb418e255f8e 100644 --- a/src/Illuminate/Foundation/Console/TestMakeCommand.php +++ b/src/Illuminate/Foundation/Console/TestMakeCommand.php @@ -37,9 +37,9 @@ protected function getStub() { if ($this->option('unit')) { return __DIR__.'/stubs/unit-test.stub'; - } else { - return __DIR__.'/stubs/test.stub'; } + + return __DIR__.'/stubs/test.stub'; } /** @@ -65,9 +65,9 @@ protected function getDefaultNamespace($rootNamespace) { if ($this->option('unit')) { return $rootNamespace.'\Unit'; - } else { - return $rootNamespace.'\Feature'; } + + return $rootNamespace.'\Feature'; } /** diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index 4b867e048bdc..ad9d58171476 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -390,9 +390,9 @@ public function decodeResponseJson() if (is_null($decodedResponse) || $decodedResponse === false) { if ($this->exception) { throw $this->exception; - } else { - PHPUnit::fail('Invalid JSON was returned from the route.'); } + + PHPUnit::fail('Invalid JSON was returned from the route.'); } return $decodedResponse; diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 9589a1f63de6..e8810ce2699f 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -150,9 +150,9 @@ function auth($guard = null) { if (is_null($guard)) { return app(AuthFactory::class); - } else { - return app(AuthFactory::class)->guard($guard); } + + return app(AuthFactory::class)->guard($guard); } } @@ -482,9 +482,9 @@ function factory() return $factory->of($arguments[0], $arguments[1])->times($arguments[2] ?? null); } elseif (isset($arguments[1])) { return $factory->of($arguments[0])->times($arguments[1]); - } else { - return $factory->of($arguments[0]); } + + return $factory->of($arguments[0]); } } diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 49da90a20072..e55465ee76f9 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -539,9 +539,9 @@ protected function hasRecipient($address, $name = null, $property = 'to') return collect($this->{$property})->contains(function ($actual) use ($expected) { if (! isset($expected['name'])) { return $actual['address'] == $expected['address']; - } else { - return $actual == $expected; } + + return $actual == $expected; }); } diff --git a/src/Illuminate/Routing/ResourceRegistrar.php b/src/Illuminate/Routing/ResourceRegistrar.php index 5209e9e9279a..21023e42d8b8 100644 --- a/src/Illuminate/Routing/ResourceRegistrar.php +++ b/src/Illuminate/Routing/ResourceRegistrar.php @@ -433,8 +433,8 @@ public static function verbs(array $verbs = []) { if (empty($verbs)) { return static::$verbs; - } else { - static::$verbs = array_merge(static::$verbs, $verbs); } + + static::$verbs = array_merge(static::$verbs, $verbs); } } diff --git a/src/Illuminate/Routing/RouteUrlGenerator.php b/src/Illuminate/Routing/RouteUrlGenerator.php index 7e7b73fb1b1f..2d3e35ae0721 100644 --- a/src/Illuminate/Routing/RouteUrlGenerator.php +++ b/src/Illuminate/Routing/RouteUrlGenerator.php @@ -140,9 +140,9 @@ protected function getRouteScheme($route) return 'http://'; } elseif ($route->httpsOnly()) { return 'https://'; - } else { - return $this->url->formatScheme(null); } + + return $this->url->formatScheme(null); } /** @@ -212,9 +212,9 @@ protected function replaceNamedParameters($path, &$parameters) return Arr::pull($parameters, $m[1]); } elseif (isset($this->defaultParameters[$m[1]])) { return $this->defaultParameters[$m[1]]; - } else { - return $m[0]; } + + return $m[0]; }, $path); } diff --git a/src/Illuminate/Routing/UrlGenerator.php b/src/Illuminate/Routing/UrlGenerator.php index 3e9481047c0b..7726e39576dd 100755 --- a/src/Illuminate/Routing/UrlGenerator.php +++ b/src/Illuminate/Routing/UrlGenerator.php @@ -142,9 +142,9 @@ public function previous($fallback = false) return $url; } elseif ($fallback) { return $this->to($fallback); - } else { - return $this->to('/'); } + + return $this->to('/'); } /** @@ -351,9 +351,9 @@ protected function formatAction($action) { if ($this->rootNamespace && ! (strpos($action, '\\') === 0)) { return $this->rootNamespace.'\\'.$action; - } else { - return trim($action, '\\'); } + + return trim($action, '\\'); } /** diff --git a/src/Illuminate/Session/SessionManager.php b/src/Illuminate/Session/SessionManager.php index f8ad802504b0..6aef0516a67f 100755 --- a/src/Illuminate/Session/SessionManager.php +++ b/src/Illuminate/Session/SessionManager.php @@ -165,9 +165,9 @@ protected function buildSession($handler) { if ($this->app['config']['session.encrypt']) { return $this->buildEncryptedSession($handler); - } else { - return new Store($this->app['config']['session.cookie'], $handler); } + + return new Store($this->app['config']['session.cookie'], $handler); } /** diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 43d7953d1ea4..737d9b62fcc2 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -213,9 +213,9 @@ public static function flatten($array, $depth = INF) return array_merge($result, [$item]); } elseif ($depth === 1) { return array_merge($result, array_values($item)); - } else { - return array_merge($result, static::flatten($item, $depth - 1)); } + + return array_merge($result, static::flatten($item, $depth - 1)); }, []); } diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 0ea82955c340..f560069176f6 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1561,9 +1561,9 @@ public function jsonSerialize() return json_decode($value->toJson(), true); } elseif ($value instanceof Arrayable) { return $value->toArray(); - } else { - return $value; } + + return $value; }, $this->items); } diff --git a/src/Illuminate/Support/Manager.php b/src/Illuminate/Support/Manager.php index 592776c2c859..0a420c1a708e 100755 --- a/src/Illuminate/Support/Manager.php +++ b/src/Illuminate/Support/Manager.php @@ -81,13 +81,14 @@ protected function createDriver($driver) // drivers using their own customized driver creator Closure to create it. if (isset($this->customCreators[$driver])) { return $this->callCustomCreator($driver); - } else { - $method = 'create'.Str::studly($driver).'Driver'; + } + + $method = 'create'.Str::studly($driver).'Driver'; - if (method_exists($this, $method)) { - return $this->$method(); - } + if (method_exists($this, $method)) { + return $this->$method(); } + throw new InvalidArgumentException("Driver [$driver] not supported."); } diff --git a/src/Illuminate/Validation/ValidationRuleParser.php b/src/Illuminate/Validation/ValidationRuleParser.php index 96a89baf0252..43a28db989d8 100644 --- a/src/Illuminate/Validation/ValidationRuleParser.php +++ b/src/Illuminate/Validation/ValidationRuleParser.php @@ -87,9 +87,9 @@ protected function explodeExplicitRule($rule) return explode('|', $rule); } elseif (is_object($rule)) { return [$this->prepareRule($rule)]; - } else { - return array_map([$this, 'prepareRule'], $rule); } + + return array_map([$this, 'prepareRule'], $rule); } /** diff --git a/tests/Database/DatabaseConnectorTest.php b/tests/Database/DatabaseConnectorTest.php index 0e9e1c3ce249..feded710f6cd 100755 --- a/tests/Database/DatabaseConnectorTest.php +++ b/tests/Database/DatabaseConnectorTest.php @@ -171,13 +171,13 @@ protected function getDsn(array $config) $charset = isset($config['charset']) ? ';charset='.$config['charset'] : ''; return "dblib:host={$host}{$port};dbname={$database}{$charset}{$appname}"; - } else { - $port = isset($config['port']) ? ','.$port : ''; - $appname = isset($config['appname']) ? ';APP='.$config['appname'] : ''; - $readonly = isset($config['readonly']) ? ';ApplicationIntent=ReadOnly' : ''; - $pooling = (isset($config['pooling']) && $config['pooling'] == false) ? ';ConnectionPooling=0' : ''; - - return "sqlsrv:Server={$host}{$port};Database={$database}{$readonly}{$pooling}{$appname}"; } + + $port = isset($config['port']) ? ','.$port : ''; + $appname = isset($config['appname']) ? ';APP='.$config['appname'] : ''; + $readonly = isset($config['readonly']) ? ';ApplicationIntent=ReadOnly' : ''; + $pooling = (isset($config['pooling']) && $config['pooling'] == false) ? ';ConnectionPooling=0' : ''; + + return "sqlsrv:Server={$host}{$port};Database={$database}{$readonly}{$pooling}{$appname}"; } }