mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
[CODESTYLE] Replace phpcs with php-cs-fixer (#1030)
* composer require --dev friendsofphp/php-cs-fixer:^2 * php-cs-fixer: ignore cache and custom local config file * php-cs-fixer: initial config * php-cs-fixer: replace commands in composer * php-cs-fixer: add PSR12 "as good as it currently gets" * php-cs-fixer: apply PSR12 to codebase * tests: add workaround to keep unused imports for snapshot testing * php-cs-fixer: apply no_unused_imports * php-cs-fixer: apply array_syntax short * php-cs-fixer: apply single_quote * php-cs-fixer: switch ordered_imports sort_algorithm to alpha Let's be opinionated here for consistency * php-cs-fixer: split between non-tests and tests and share config * php-cs-fixer: apply declare_strict_types for tests * php-cs-fixer: apply fully_qualified_strict_types * php-cs-fixer: apply space_after_semicolon * php-cs-fixer: apply trailing_comma_in_multiline_array * php-cs-fixer: apply trim_array_spaces * php-cs-fixer: apply unary_operator_spaces * php-cs-fixer: apply whitespace_after_comma_in_array * php-cs-fixer: apply native_function_invocation * php-cs-fixer: apply concat_space * grumphp: reflect we're using phpcsfixer now * composer remove --dev squizlabs/php_codesniffer * gha: simplify fix-style approach Not really necessary to remove packages and then manually prevent unrelated commits creeping in Co-authored-by: Barry vd. Heuvel <[email protected]>
This commit is contained in:
co-authored by
Barry vd. Heuvel
parent
a96add6981
commit
764bc02b84
@@ -15,8 +15,8 @@ use Barryvdh\LaravelIdeHelper\Eloquent;
|
||||
use Barryvdh\LaravelIdeHelper\Generator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
/**
|
||||
* A command to generate autocomplete information for your IDE
|
||||
@@ -25,7 +25,6 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
*/
|
||||
class GeneratorCommand extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
@@ -59,7 +58,8 @@ class GeneratorCommand extends Command
|
||||
* @param \Illuminate\View\Factory $view
|
||||
*/
|
||||
public function __construct(
|
||||
/*ConfigRepository */ $config,
|
||||
/*ConfigRepository */
|
||||
$config,
|
||||
Filesystem $files,
|
||||
/* Illuminate\View\Factory */
|
||||
$view
|
||||
@@ -105,9 +105,9 @@ class GeneratorCommand extends Command
|
||||
|
||||
$helpers = '';
|
||||
if ($this->option('helpers') || ($this->config->get('ide-helper.include_helpers'))) {
|
||||
foreach ($this->config->get('ide-helper.helper_files', array()) as $helper) {
|
||||
foreach ($this->config->get('ide-helper.helper_files', []) as $helper) {
|
||||
if (file_exists($helper)) {
|
||||
$helpers .= str_replace(array('<?php', '?>'), '', $this->files->get($helper));
|
||||
$helpers .= str_replace(['<?php', '?>'], '', $this->files->get($helper));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -134,10 +134,10 @@ class GeneratorCommand extends Command
|
||||
//Use a sqlite database in memory, to avoid connection errors on Database facades
|
||||
$this->config->set(
|
||||
'database.connections.sqlite',
|
||||
array(
|
||||
[
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
)
|
||||
]
|
||||
);
|
||||
$this->config->set('database.default', 'sqlite');
|
||||
}
|
||||
@@ -151,11 +151,11 @@ class GeneratorCommand extends Command
|
||||
{
|
||||
$filename = $this->config->get('ide-helper.filename');
|
||||
|
||||
return array(
|
||||
array(
|
||||
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename
|
||||
),
|
||||
);
|
||||
return [
|
||||
[
|
||||
'filename', InputArgument::OPTIONAL, 'The path to the helper file', $filename,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,11 +168,11 @@ class GeneratorCommand extends Command
|
||||
$format = $this->config->get('ide-helper.format');
|
||||
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
|
||||
|
||||
return array(
|
||||
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
|
||||
array('write_mixins', "W", InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins),
|
||||
array('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
|
||||
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
|
||||
);
|
||||
return [
|
||||
['format', 'F', InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format],
|
||||
['write_mixins', 'W', InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins],
|
||||
['helpers', 'H', InputOption::VALUE_NONE, 'Include the helper files'],
|
||||
['memory', 'M', InputOption::VALUE_NONE, 'Use sqlite memory driver'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
*/
|
||||
class MetaCommand extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* The console command name.
|
||||
*
|
||||
@@ -87,7 +86,7 @@ class MetaCommand extends Command
|
||||
|
||||
$this->registerClassAutoloadExceptions();
|
||||
|
||||
$bindings = array();
|
||||
$bindings = [];
|
||||
foreach ($this->getAbstracts() as $abstract) {
|
||||
// Validator and seeder cause problems
|
||||
if (in_array($abstract, ['validator', 'seeder'])) {
|
||||
@@ -161,9 +160,9 @@ class MetaCommand extends Command
|
||||
{
|
||||
$filename = $this->config->get('ide-helper.meta_filename');
|
||||
|
||||
return array(
|
||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename),
|
||||
);
|
||||
return [
|
||||
['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,10 +58,10 @@ class ModelsCommand extends Command
|
||||
|
||||
protected $write_model_magic_where;
|
||||
protected $write_model_relation_count_properties;
|
||||
protected $properties = array();
|
||||
protected $methods = array();
|
||||
protected $properties = [];
|
||||
protected $methods = [];
|
||||
protected $write = false;
|
||||
protected $dirs = array();
|
||||
protected $dirs = [];
|
||||
protected $reset;
|
||||
protected $keep_text;
|
||||
protected $phpstorm_noinspections;
|
||||
@@ -146,9 +146,9 @@ class ModelsCommand extends Command
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return array(
|
||||
array('model', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', array()),
|
||||
);
|
||||
return [
|
||||
['model', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Which models to include', []],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,20 +158,20 @@ class ModelsCommand extends Command
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return array(
|
||||
array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename),
|
||||
array('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
||||
'The model dir, supports glob patterns', array()),
|
||||
array('write', 'W', InputOption::VALUE_NONE, 'Write to Model file'),
|
||||
array('nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'),
|
||||
array('reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'),
|
||||
array('smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'),
|
||||
array('phpstorm-noinspections', 'p', InputOption::VALUE_NONE,
|
||||
return [
|
||||
['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file', $this->filename],
|
||||
['dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
|
||||
'The model dir, supports glob patterns', [], ],
|
||||
['write', 'W', InputOption::VALUE_NONE, 'Write to Model file'],
|
||||
['nowrite', 'N', InputOption::VALUE_NONE, 'Don\'t write to Model file'],
|
||||
['reset', 'R', InputOption::VALUE_NONE, 'Remove the original phpdocs instead of appending'],
|
||||
['smart-reset', 'r', InputOption::VALUE_NONE, 'Refresh the properties/methods list, but keep the text'],
|
||||
['phpstorm-noinspections', 'p', InputOption::VALUE_NONE,
|
||||
'Add PhpFullyQualifiedNameUsageInspection and PhpUnnecessaryFullyQualifiedNameInspection PHPStorm ' .
|
||||
'noinspection tags'
|
||||
),
|
||||
array('ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''),
|
||||
);
|
||||
'noinspection tags',
|
||||
],
|
||||
['ignore', 'I', InputOption::VALUE_OPTIONAL, 'Which models to ignore', ''],
|
||||
];
|
||||
}
|
||||
|
||||
protected function generateDocs($loadModels, $ignore = '')
|
||||
@@ -195,7 +195,7 @@ class ModelsCommand extends Command
|
||||
if (empty($loadModels)) {
|
||||
$models = $this->loadModels();
|
||||
} else {
|
||||
$models = array();
|
||||
$models = [];
|
||||
foreach ($loadModels as $model) {
|
||||
$models = array_merge($models, explode(',', $model));
|
||||
}
|
||||
@@ -203,7 +203,7 @@ class ModelsCommand extends Command
|
||||
|
||||
$ignore = array_merge(
|
||||
explode(',', $ignore),
|
||||
$this->laravel['config']->get('ide-helper.ignored_models', array())
|
||||
$this->laravel['config']->get('ide-helper.ignored_models', [])
|
||||
);
|
||||
|
||||
foreach ($models as $name) {
|
||||
@@ -213,8 +213,8 @@ class ModelsCommand extends Command
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$this->properties = array();
|
||||
$this->methods = array();
|
||||
$this->properties = [];
|
||||
$this->methods = [];
|
||||
if (class_exists($name)) {
|
||||
try {
|
||||
// handle abstract classes, interfaces, ...
|
||||
@@ -248,7 +248,7 @@ class ModelsCommand extends Command
|
||||
$ignore[] = $name;
|
||||
$this->nullableColumns = [];
|
||||
} catch (\Throwable $e) {
|
||||
$this->error("Exception: " . $e->getMessage() .
|
||||
$this->error('Exception: ' . $e->getMessage() .
|
||||
"\nCould not analyze class $name.\n\nTrace:\n" .
|
||||
$e->getTraceAsString());
|
||||
}
|
||||
@@ -268,7 +268,7 @@ class ModelsCommand extends Command
|
||||
|
||||
protected function loadModels()
|
||||
{
|
||||
$models = array();
|
||||
$models = [];
|
||||
foreach ($this->dirs as $dir) {
|
||||
if (is_dir(base_path($dir))) {
|
||||
$dir = base_path($dir);
|
||||
@@ -364,7 +364,7 @@ class ModelsCommand extends Command
|
||||
*/
|
||||
protected function getTypeOverride($type)
|
||||
{
|
||||
$typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', array());
|
||||
$typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', []);
|
||||
|
||||
return $typeOverrides[$type] ?? $type;
|
||||
}
|
||||
@@ -382,7 +382,7 @@ class ModelsCommand extends Command
|
||||
$databasePlatform->registerDoctrineTypeMapping('enum', 'string');
|
||||
|
||||
$platformName = $databasePlatform->getName();
|
||||
$customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", array());
|
||||
$customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []);
|
||||
foreach ($customTypes as $yourTypeName => $doctrineTypeName) {
|
||||
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
|
||||
}
|
||||
@@ -454,11 +454,11 @@ class ModelsCommand extends Command
|
||||
);
|
||||
if ($this->write_model_magic_where) {
|
||||
$this->setMethod(
|
||||
Str::camel("where_" . $name),
|
||||
Str::camel('where_' . $name),
|
||||
$this->getClassNameInDestinationFile($model, \Illuminate\Database\Eloquent\Builder::class)
|
||||
. '|'
|
||||
. $this->getClassNameInDestinationFile($model, get_class($model)),
|
||||
array('$value')
|
||||
['$value']
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -521,7 +521,7 @@ class ModelsCommand extends Command
|
||||
|
||||
$this->setMethod(
|
||||
$method,
|
||||
$builder . "|" . $this->getClassNameInDestinationFile($model, get_class($model))
|
||||
$builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model))
|
||||
);
|
||||
} elseif (
|
||||
!method_exists('Illuminate\Database\Eloquent\Model', $method)
|
||||
@@ -552,7 +552,7 @@ class ModelsCommand extends Command
|
||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||
|
||||
foreach (
|
||||
array(
|
||||
[
|
||||
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
||||
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
||||
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
|
||||
@@ -563,8 +563,8 @@ class ModelsCommand extends Command
|
||||
'morphTo' => '\Illuminate\Database\Eloquent\Relations\MorphTo',
|
||||
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
|
||||
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
||||
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
|
||||
) as $relation => $impl
|
||||
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
||||
] as $relation => $impl
|
||||
) {
|
||||
$search = '$this->' . $relation . '(';
|
||||
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
|
||||
@@ -621,7 +621,7 @@ class ModelsCommand extends Command
|
||||
false
|
||||
);
|
||||
}
|
||||
} elseif ($relation === "morphTo") {
|
||||
} elseif ($relation === 'morphTo') {
|
||||
// Model isn't specified because relation is polymorphic
|
||||
$this->setProperty(
|
||||
$method,
|
||||
@@ -688,7 +688,7 @@ class ModelsCommand extends Command
|
||||
protected function setProperty($name, $type = null, $read = null, $write = null, $comment = '', $nullable = false)
|
||||
{
|
||||
if (!isset($this->properties[$name])) {
|
||||
$this->properties[$name] = array();
|
||||
$this->properties[$name] = [];
|
||||
$this->properties[$name]['type'] = 'mixed';
|
||||
$this->properties[$name]['read'] = false;
|
||||
$this->properties[$name]['write'] = false;
|
||||
@@ -709,12 +709,12 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
protected function setMethod($name, $type = '', $arguments = array())
|
||||
protected function setMethod($name, $type = '', $arguments = [])
|
||||
{
|
||||
$methods = array_change_key_case($this->methods, CASE_LOWER);
|
||||
|
||||
if (!isset($methods[strtolower($name)])) {
|
||||
$this->methods[$name] = array();
|
||||
$this->methods[$name] = [];
|
||||
$this->methods[$name]['type'] = $type;
|
||||
$this->methods[$name]['arguments'] = $arguments;
|
||||
}
|
||||
@@ -752,13 +752,13 @@ class ModelsCommand extends Command
|
||||
$phpdoc->setText($class);
|
||||
}
|
||||
|
||||
$properties = array();
|
||||
$methods = array();
|
||||
$properties = [];
|
||||
$methods = [];
|
||||
foreach ($phpdoc->getTags() as $tag) {
|
||||
$name = $tag->getName();
|
||||
if ($name == "property" || $name == "property-read" || $name == "property-write") {
|
||||
if ($name == 'property' || $name == 'property-read' || $name == 'property-write') {
|
||||
$properties[] = $tag->getVariableName();
|
||||
} elseif ($name == "method") {
|
||||
} elseif ($name == 'method') {
|
||||
$methods[] = $tag->getMethodName();
|
||||
}
|
||||
}
|
||||
@@ -797,22 +797,22 @@ class ModelsCommand extends Command
|
||||
$phpdoc->appendTag($tag);
|
||||
}
|
||||
|
||||
if ($this->write && ! $phpdoc->getTagsByName('mixin')) {
|
||||
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
|
||||
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
|
||||
$phpdoc->appendTag(Tag::createInstance("@mixin " . $eloquentClassNameInModel, $phpdoc));
|
||||
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
|
||||
}
|
||||
if ($this->phpstorm_noinspections) {
|
||||
/**
|
||||
* Facades, Eloquent API
|
||||
* @see https://www.jetbrains.com/help/phpstorm/php-fully-qualified-name-usage.html
|
||||
*/
|
||||
$phpdoc->appendTag(Tag::createInstance("@noinspection PhpFullyQualifiedNameUsageInspection", $phpdoc));
|
||||
$phpdoc->appendTag(Tag::createInstance('@noinspection PhpFullyQualifiedNameUsageInspection', $phpdoc));
|
||||
/**
|
||||
* Relations, other models in the same namespace
|
||||
* @see https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html
|
||||
*/
|
||||
$phpdoc->appendTag(
|
||||
Tag::createInstance("@noinspection PhpUnnecessaryFullyQualifiedNameInspection", $phpdoc)
|
||||
Tag::createInstance('@noinspection PhpUnnecessaryFullyQualifiedNameInspection', $phpdoc)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -857,7 +857,7 @@ class ModelsCommand extends Command
|
||||
public function getParameters($method)
|
||||
{
|
||||
//Loop through the default values for parameters, and make the correct output string
|
||||
$paramsWithDefault = array();
|
||||
$paramsWithDefault = [];
|
||||
/** @var \ReflectionParameter $param */
|
||||
foreach ($method->getParameters() as $param) {
|
||||
$paramClass = $param->getClass();
|
||||
|
||||
Reference in New Issue
Block a user