From b99b76da0d1b95cc6d3f79daba2d3d5703992ada Mon Sep 17 00:00:00 2001 From: Mateus Junges Date: Sun, 9 Jun 2019 17:12:28 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Commands/DumpAutoload.php | 3 +- src/Controllers/PipeDreamAPIController.php | 33 ++++++++-------- src/Controllers/PipeDreamWebController.php | 12 +++--- src/PipeDreamServiceProvider.php | 30 +++++++------- src/ProjectFileManager.php | 46 +++++++++++----------- src/routes/routes.php | 11 +++--- 6 files changed, 68 insertions(+), 67 deletions(-) diff --git a/src/Commands/DumpAutoload.php b/src/Commands/DumpAutoload.php index e2fe104..ade576c 100644 --- a/src/Commands/DumpAutoload.php +++ b/src/Commands/DumpAutoload.php @@ -32,6 +32,7 @@ class DumpAutoload extends Command * Create a new command instance. * * @param Composer $composer + * * @return void */ public function __construct(Composer $composer) @@ -54,4 +55,4 @@ public function handle() $this->composer->dumpOptimized() ); } -} \ No newline at end of file +} diff --git a/src/Controllers/PipeDreamAPIController.php b/src/Controllers/PipeDreamAPIController.php index b6fce02..349bd56 100644 --- a/src/Controllers/PipeDreamAPIController.php +++ b/src/Controllers/PipeDreamAPIController.php @@ -2,13 +2,13 @@ namespace PipeDream\Laravel\Controllers; +use Artisan; +use File; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; -use File; +use Illuminate\Routing\Controller as BaseController; use PipeDream\Laravel\ProjectFileManager; -use Artisan; class PipeDreamAPIController extends BaseController { @@ -21,17 +21,16 @@ public function __construct() public function templates() { - return $this->getTemplates(); } public function scripts() { return [ - "migrate", - "seed" + 'migrate', + 'seed', ]; - } + } public function build() { @@ -40,7 +39,7 @@ public function build() // Optionally reverse the previous design iteration // This is useful to remove previous mistakes and timestamp conflicts - $this->args->reverseHistory? $this->project->reverseHistory() : null; + $this->args->reverseHistory ? $this->project->reverseHistory() : null; // Write the files generated $this->project->write($this->args->reviewFiles); @@ -54,12 +53,10 @@ public function build() // Ensure migrations are autoloaded exec('cd .. && composer dumpautoload'); // whats wrong with this package command??!! - //Artisan::call('dump-autoload'); - - + //Artisan::call('dump-autoload'); return response([ - "message" => "Successfully stored files!" + 'message' => 'Successfully stored files!', ], 200); } @@ -70,7 +67,8 @@ private function setupProjectEnvironment() ); } - private function deleteDefaultMigrations() { + private function deleteDefaultMigrations() + { $this->project->delete(json_decode(' [ { @@ -82,7 +80,7 @@ private function deleteDefaultMigrations() { ] ')); } - + private function pathToFileName($path) { return substr($path, strrpos($path, '/') + 1); @@ -90,9 +88,10 @@ private function pathToFileName($path) private function getTemplates() { - return collect(glob(__DIR__ . '/../templates/*'))->reduce(function($allFiles, $path) { + return collect(glob(__DIR__.'/../templates/*'))->reduce(function ($allFiles, $path) { $allFiles[$this->pathToFileName($path)] = File::get($path); + return $allFiles; }, collect([])); } -} \ No newline at end of file +} diff --git a/src/Controllers/PipeDreamWebController.php b/src/Controllers/PipeDreamWebController.php index 5b503fc..364b7ec 100644 --- a/src/Controllers/PipeDreamWebController.php +++ b/src/Controllers/PipeDreamWebController.php @@ -12,10 +12,10 @@ public function index() PipeDreamServiceProvider::publishAssets(); return view('pipe-dream::spa')->with([ - "settings" => [ - "isSandboxed" => env('PIPEDREAM_IS_SANDBOXED', false), - "appName" => request()->path() - ] - ]); + 'settings' => [ + 'isSandboxed' => env('PIPEDREAM_IS_SANDBOXED', false), + 'appName' => request()->path(), + ], + ]); } -} \ No newline at end of file +} diff --git a/src/PipeDreamServiceProvider.php b/src/PipeDreamServiceProvider.php index d33334e..a51c416 100644 --- a/src/PipeDreamServiceProvider.php +++ b/src/PipeDreamServiceProvider.php @@ -3,7 +3,6 @@ namespace PipeDream\Laravel; use Illuminate\Support\ServiceProvider; -use Illuminate\Support\Collection; use PipeDream\Laravel\Commands\DumpAutoload; class PipeDreamServiceProvider extends ServiceProvider @@ -16,7 +15,7 @@ class PipeDreamServiceProvider extends ServiceProvider public function register() { $this->commands([ - DumpAutoload::class + DumpAutoload::class, ]); } @@ -38,33 +37,34 @@ public function boot() * So resorting to do it every new page load * Please fix this */ - public static function publishAssets() { + public static function publishAssets() + { \File::copyDirectory( - __DIR__ . '/public', + __DIR__.'/public', public_path('vendor/pipe-dream/laravel') ); \File::copy( - __DIR__ . '/../data/dataTypeGithubDump.js', + __DIR__.'/../data/dataTypeGithubDump.js', public_path('vendor/pipe-dream/laravel/data/github.js') - ); + ); } - + private function registerStorages() { - $this->app['config']["filesystems.disks.self"] = [ + $this->app['config']['filesystems.disks.self'] = [ 'driver' => 'local', - 'root' => base_path(), + 'root' => base_path(), ]; - $this->app['config']["filesystems.disks.pipe-dream"] = [ + $this->app['config']['filesystems.disks.pipe-dream'] = [ 'driver' => 'local', - 'root' => storage_path('pipe-dream'), + 'root' => storage_path('pipe-dream'), ]; - - $this->app['config']["filesystems.disks.pipe-dream.sandbox"] = [ + + $this->app['config']['filesystems.disks.pipe-dream.sandbox'] = [ 'driver' => 'local', - 'root' => storage_path('pipe-dream/sandbox'), - ]; + 'root' => storage_path('pipe-dream/sandbox'), + ]; } } diff --git a/src/ProjectFileManager.php b/src/ProjectFileManager.php index 8168af2..6572081 100644 --- a/src/ProjectFileManager.php +++ b/src/ProjectFileManager.php @@ -2,15 +2,17 @@ namespace PipeDream\Laravel; -use stdClass; -use Storage; use File; +use Storage; -class ProjectFileManager { +class ProjectFileManager +{ public function __construct($isSandboxed) { $this->isSandboxed = $isSandboxed; - if($this->isSandboxed) $this->setupSandboxProject(); + if ($this->isSandboxed) { + $this->setupSandboxProject(); + } $this->history = []; } @@ -23,27 +25,27 @@ public function write($files) { $this->recordCurrentStateFor($files); - collect($files)->each(function($file) { + collect($files)->each(function ($file) { $this->storage()->put($file->path, $file->content); - }); + }); } public function delete($files) { $this->recordCurrentStateFor($files); - collect($files)->each(function($file) { + collect($files)->each(function ($file) { $this->storage()->delete($file->path); - }); - } + }); + } public function reverseHistory() { - collect($this->loadHistory())->each(function($content, $path) { - if($content == null) { + collect($this->loadHistory())->each(function ($content, $path) { + if ($content == null) { return $this->storage()->delete($path); } - + $this->storage()->put($path, $content); }); } @@ -59,15 +61,15 @@ public function persistHistory() /*********** PRIVATE ************************************************** */ private function setupSandboxProject() { - app()['config']["filesystems.disks.pipe-dream-sandbox-project"] = [ + app()['config']['filesystems.disks.pipe-dream-sandbox-project'] = [ 'driver' => 'local', - 'root' => storage_path("pipe-dream/sandbox/test-project"), - ]; - - if(!Storage::disk('pipe-dream')->exists('sandbox/test-project')) { + 'root' => storage_path('pipe-dream/sandbox/test-project'), + ]; + + if (!Storage::disk('pipe-dream')->exists('sandbox/test-project')) { File::copyDirectory( storage_path('pipe-dream/laravel-including-vendors'), - storage_path("pipe-dream/sandbox/test-project") + storage_path('pipe-dream/sandbox/test-project') ); } } @@ -81,17 +83,17 @@ private function loadHistory() private function storage() { return Storage::disk( - $this->isSandboxed ? "pipe-dream-sandbox-project" : 'self' + $this->isSandboxed ? 'pipe-dream-sandbox-project' : 'self' ); } private function recordCurrentStateFor($files) { - collect($files)->each(function($file) { - $this->history[$file->path] = + collect($files)->each(function ($file) { + $this->history[$file->path] = $this->storage()->has($file->path) ? $this->storage()->get($file->path) : null; }); } -} \ No newline at end of file +} diff --git a/src/routes/routes.php b/src/routes/routes.php index 117aa8f..6e2d3d2 100644 --- a/src/routes/routes.php +++ b/src/routes/routes.php @@ -1,14 +1,13 @@ -group(function () { - Route::post('/build', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@build'); + Route::post('/build', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@build'); Route::get('/scripts', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@scripts'); Route::get('/templates', '\PipeDream\Laravel\Controllers\PipeDreamAPIController@templates'); - -}); \ No newline at end of file +});