From 4aa919c09f4746ed53748e84484d1ad756d98c19 Mon Sep 17 00:00:00 2001 From: feek <5747667+mr-feek@users.noreply.github.com> Date: Mon, 22 Jun 2020 21:59:56 -0700 Subject: [PATCH] chore: psr12 (#964) --- composer.json | 4 ++-- grumphp.yml | 2 +- src/Alias.php | 1 + src/Console/EloquentCommand.php | 1 + src/Console/GeneratorCommand.php | 7 ++++-- src/Console/MetaCommand.php | 3 ++- src/Console/ModelsCommand.php | 41 +++++++++++++++++++------------- src/Eloquent.php | 1 + src/Generator.php | 11 +++++---- src/IdeHelperServiceProvider.php | 1 + src/Method.php | 1 + 11 files changed, 46 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 361ffbb..f338af2 100644 --- a/composer.json +++ b/composer.json @@ -60,8 +60,8 @@ }, "scripts": { "analyze": "psalm", - "check-style": "phpcs -p --standard=PSR2 src/", - "fix-style": "phpcbf -p --standard=PSR2 src/", + "check-style": "phpcs -p --standard=PSR12 src/", + "fix-style": "phpcbf -p --standard=PSR12 src/", "test": "phpunit" } } diff --git a/grumphp.yml b/grumphp.yml index 5ee753f..22fd7f9 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -6,7 +6,7 @@ grumphp: group: [] always_execute: false phpcs: - standard: PSR2 + standard: PSR12 warning_severity: ~ ignore_patterns: - tests/ diff --git a/src/Alias.php b/src/Alias.php index c85b129..464b259 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -1,4 +1,5 @@ error( 'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)' ); diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php index 40e8c9b..7787c99 100644 --- a/src/Console/MetaCommand.php +++ b/src/Console/MetaCommand.php @@ -1,4 +1,5 @@ output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { - $this->comment("Cannot make '$abstract': ".$e->getMessage()); + $this->comment("Cannot make '$abstract': " . $e->getMessage()); } } } diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index e1c7a55..9dee80e 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -1,4 +1,5 @@ write && $filename === $this->filename && !$this->option('nowrite')) { - if ($this->confirm( - "Do you want to overwrite the existing model files? Choose no to write to $filename instead" - ) + if ( + $this->confirm( + "Do you want to overwrite the existing model files? Choose no to write to $filename instead" + ) ) { $this->write = true; } @@ -254,7 +256,7 @@ class ModelsCommand extends Command if (!$hasDoctrine) { $this->error( - 'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. '. + 'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. ' . 'Please require that in your composer.json and run `composer update`.' ); } @@ -455,10 +457,11 @@ class ModelsCommand extends Command if ($methods) { sort($methods); foreach ($methods as $method) { - if (Str::startsWith($method, 'get') && Str::endsWith( - $method, - 'Attribute' - ) && $method !== 'getAttribute' + if ( + Str::startsWith($method, 'get') && Str::endsWith( + $method, + 'Attribute' + ) && $method !== 'getAttribute' ) { //Magic getAttribute $name = Str::snake(substr($method, 3, -9)); @@ -468,10 +471,11 @@ class ModelsCommand extends Command $type = $this->getTypeInModel($model, $type); $this->setProperty($name, $type, true, null); } - } elseif (Str::startsWith($method, 'set') && Str::endsWith( - $method, - 'Attribute' - ) && $method !== 'setAttribute' + } elseif ( + Str::startsWith($method, 'set') && Str::endsWith( + $method, + 'Attribute' + ) && $method !== 'setAttribute' ) { //Magic setAttribute $name = Str::snake(substr($method, 3, -9)); @@ -500,7 +504,8 @@ class ModelsCommand extends Command $builder = $this->getClassNameInModel($model, get_class($model->newModelQuery())); $this->setMethod($method, $builder . "|" . $this->getClassNameInModel($model, get_class($model))); - } elseif (!method_exists('Illuminate\Database\Eloquent\Model', $method) + } elseif ( + !method_exists('Illuminate\Database\Eloquent\Model', $method) && !Str::startsWith($method, 'get') ) { //Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php @@ -527,7 +532,8 @@ class ModelsCommand extends Command $begin = strpos($code, 'function('); $code = substr($code, $begin, strrpos($code, '}') - $begin + 1); - foreach (array( + foreach ( + array( 'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany', 'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough', 'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough', @@ -539,7 +545,8 @@ class ModelsCommand extends Command 'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany', 'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany', 'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany' - ) as $relation => $impl) { + ) as $relation => $impl + ) { $search = '$this->' . $relation . '('; if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) { //Resolve the relation's model to a Relation object. @@ -662,7 +669,7 @@ class ModelsCommand extends Command if ($type !== null) { $newType = $this->getTypeOverride($type); if ($nullable) { - $newType .='|null'; + $newType .= '|null'; } $this->properties[$name]['type'] = $newType; } @@ -865,7 +872,7 @@ class ModelsCommand extends Command } /** @var \Illuminate\Database\Eloquent\Model $model */ - $model = new $className; + $model = new $className(); return '\\' . get_class($model->newCollection()); } diff --git a/src/Eloquent.php b/src/Eloquent.php index d84435d..e2125e9 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -5,6 +5,7 @@ * * @author Charles A. Peterson */ + namespace Barryvdh\LaravelIdeHelper; use Illuminate\Console\Command; diff --git a/src/Generator.php b/src/Generator.php index afe2fed..7f8b138 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -1,4 +1,5 @@ $method(); } @@ -97,7 +98,7 @@ class Generator foreach ($aliases as $alias) { $functions = array(); foreach ($alias->getMethods() as $method) { - $functions[$method->getName()] = '('. $method->getParamsWithDefault().')'; + $functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')'; } $classes[$alias->getAlias()] = array( 'functions' => $functions, @@ -123,8 +124,10 @@ class Generator $this->interfaces['\Illuminate\Contracts\Auth\Authenticatable'] = $defaultUserModel; try { - if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true) - && app()->bound('auth')) { + if ( + class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true) + && app()->bound('auth') + ) { if (class_exists('\Illuminate\Foundation\Application')) { $authMethod = version_compare(Application::VERSION, '5.2', '>=') ? 'guard' : 'driver'; } else { diff --git a/src/IdeHelperServiceProvider.php b/src/IdeHelperServiceProvider.php index ff4bf4e..6988ea6 100644 --- a/src/IdeHelperServiceProvider.php +++ b/src/IdeHelperServiceProvider.php @@ -1,4 +1,5 @@