From 7a7bc0b25bb3472275167a851fd05dd80cc7ce7f Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Tue, 29 Nov 2016 10:00:34 -0600 Subject: [PATCH 1/3] Fixes issue #16575 - add file exists check to ModelFactory.php file when performing app:name command --- src/Illuminate/Foundation/Console/AppNameCommand.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Console/AppNameCommand.php b/src/Illuminate/Foundation/Console/AppNameCommand.php index 111147552c95..1e86d6c21d5b 100644 --- a/src/Illuminate/Foundation/Console/AppNameCommand.php +++ b/src/Illuminate/Foundation/Console/AppNameCommand.php @@ -223,9 +223,10 @@ protected function setServicesConfigNamespace() */ protected function setDatabaseFactoryNamespaces() { - $this->replaceIn( - $this->laravel->databasePath().'/factories/ModelFactory.php', $this->currentRoot, $this->argument('name') - ); + $modelFactoryFile = $this->laravel->databasePath().'/factories/ModelFactory.php'; + if ($this->files->exists($modelFactoryFile)) { + $this->replaceIn($modelFactoryFile, $this->currentRoot, $this->argument('name')); + } } /** From 9b5cd619a441dbd436a0353d0f4ddb97288369b5 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Tue, 29 Nov 2016 10:04:21 -0600 Subject: [PATCH 2/3] match coding conventions regarding whitespace --- src/Illuminate/Foundation/Console/AppNameCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Foundation/Console/AppNameCommand.php b/src/Illuminate/Foundation/Console/AppNameCommand.php index 1e86d6c21d5b..d772501ff840 100644 --- a/src/Illuminate/Foundation/Console/AppNameCommand.php +++ b/src/Illuminate/Foundation/Console/AppNameCommand.php @@ -224,6 +224,7 @@ protected function setServicesConfigNamespace() protected function setDatabaseFactoryNamespaces() { $modelFactoryFile = $this->laravel->databasePath().'/factories/ModelFactory.php'; + if ($this->files->exists($modelFactoryFile)) { $this->replaceIn($modelFactoryFile, $this->currentRoot, $this->argument('name')); } From 49147544fb40e0342260146b470555e6ada16914 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Thu, 1 Dec 2016 08:49:16 -0600 Subject: [PATCH 3/3] app:name file existence check - moved file existence check into the replaceIn() functionality of the command --- src/Illuminate/Foundation/Console/AppNameCommand.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Foundation/Console/AppNameCommand.php b/src/Illuminate/Foundation/Console/AppNameCommand.php index d772501ff840..923654f3a644 100644 --- a/src/Illuminate/Foundation/Console/AppNameCommand.php +++ b/src/Illuminate/Foundation/Console/AppNameCommand.php @@ -223,11 +223,9 @@ protected function setServicesConfigNamespace() */ protected function setDatabaseFactoryNamespaces() { - $modelFactoryFile = $this->laravel->databasePath().'/factories/ModelFactory.php'; - - if ($this->files->exists($modelFactoryFile)) { - $this->replaceIn($modelFactoryFile, $this->currentRoot, $this->argument('name')); - } + $this->replaceIn( + $this->laravel->databasePath().'/factories/ModelFactory.php', $this->currentRoot, $this->argument('name') + ); } /** @@ -240,7 +238,9 @@ protected function setDatabaseFactoryNamespaces() */ protected function replaceIn($path, $search, $replace) { - $this->files->put($path, str_replace($search, $replace, $this->files->get($path))); + if ($this->files->exists($path)) { + $this->files->put($path, str_replace($search, $replace, $this->files->get($path))); + } } /**