[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:
Markus Podar
2020-09-01 11:32:31 +02:00
committed by GitHub
co-authored by Barry vd. Heuvel
parent a96add6981
commit 764bc02b84
55 changed files with 310 additions and 217 deletions
+1 -6
View File
@@ -23,16 +23,11 @@ jobs:
tools: composer:v2
- name: Install dependencies
run: |
composer remove phpro/grumphp vimeo/psalm --no-update --dev
composer update --prefer-dist --no-progress
run: composer update --prefer-dist --no-progress
- run: composer fix-style
continue-on-error: true
# Revert manual modifications so they don't get commited 💥
- run: git checkout -- composer.json
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: composer fix-style
+3
View File
@@ -1,5 +1,8 @@
.phpunit.result.cache
/.idea
/.php_cs
/.php_cs.cache
/.php_cs.tests.cache
/composer.lock
/vendor
+65
View File
@@ -0,0 +1,65 @@
<?php
// Share common rules between non-test and test files
return [
// PSR12 from https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4943
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'braces' => [
// Not-yet-implemented
// 'allow_single_line_anonymous_class_with_empty_body' => true,
],
'compact_nullable_typehint' => true,
'declare_equal_normalize' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'new_with_braces' => true,
'no_blank_lines_after_class_opening' => true,
'no_leading_import_slash' => true,
'no_whitespace_in_blank_line' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
],
],
'ordered_imports' => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'alpha',
],
'return_type_declaration' => true,
'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_trait_insert_per_statement' => true,
'ternary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
'const',
'method',
'property',
],
],
// Further quality-of-life improvements
'array_syntax' => [
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one',
],
'fully_qualified_strict_types' => true,
'native_function_invocation' => [
'include' => [],
'strict' => true,
],
'no_unused_imports' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
];
+14
View File
@@ -0,0 +1,14 @@
<?php
require __DIR__ . '/vendor/autoload.php';
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('tests');
$config = require __DIR__ . '/.php_cs.common.php';
return PhpCsFixer\Config::create()
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php_cs.cache');
+22
View File
@@ -0,0 +1,22 @@
<?php
require __DIR__ . '/vendor/autoload.php';
$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/tests')
->exclude('__snapshots__');
$config = require __DIR__ . '/.php_cs.common.php';
// Additional rules for tests
$config = array_merge(
$config,
[
'declare_strict_types' => true,
]
);
return PhpCsFixer\Config::create()
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php_cs.tests.cache');
+9 -3
View File
@@ -31,13 +31,13 @@
"phpdocumentor/type-resolver": "^1.1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2",
"illuminate/config": "^6 || ^7 || ^8",
"illuminate/view": "^6 || ^7 || ^8",
"mockery/mockery": "^1.3",
"orchestra/testbench": "^4 || ^5 || ^6",
"phpro/grumphp": "^0.19.0",
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^3.12"
},
"config": {
@@ -67,8 +67,14 @@
"prefer-stable": true,
"scripts": {
"analyze": "psalm",
"check-style": "phpcs -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'",
"fix-style": "phpcbf -p --standard=PSR12 config/ resources/ src/ tests/ '--ignore=*__snapshots_*'",
"check-style": [
"php-cs-fixer fix --diff --diff-format=udiff --dry-run",
"php-cs-fixer fix --diff --diff-format=udiff --dry-run --config=.php_cs.tests.php"
],
"fix-style": [
"php-cs-fixer fix",
"php-cs-fixer fix --config=.php_cs.tests.php"
],
"test": "phpunit",
"test-regenerate": "phpunit -d --update-snapshots"
}
+19 -20
View File
@@ -1,6 +1,6 @@
<?php
return array(
return [
/*
|--------------------------------------------------------------------------
@@ -98,9 +98,9 @@ return array(
'include_helpers' => false,
'helper_files' => array(
'helper_files' => [
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
),
],
/*
|--------------------------------------------------------------------------
@@ -115,9 +115,9 @@ return array(
|
*/
'model_locations' => array(
'model_locations' => [
'app',
),
],
/*
|--------------------------------------------------------------------------
@@ -128,9 +128,9 @@ return array(
|
*/
'ignored_models' => array(
'ignored_models' => [
),
],
/*
|--------------------------------------------------------------------------
@@ -141,12 +141,12 @@ return array(
|
*/
'extra' => array(
'Eloquent' => array('Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'),
'Session' => array('Illuminate\Session\Store'),
),
'extra' => [
'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'],
'Session' => ['Illuminate\Session\Store'],
],
'magic' => array(),
'magic' => [],
/*
|--------------------------------------------------------------------------
@@ -158,9 +158,9 @@ return array(
|
*/
'interfaces' => array(
'interfaces' => [
),
],
/*
|--------------------------------------------------------------------------
@@ -188,9 +188,9 @@ return array(
| ),
|
*/
'custom_db_types' => array(
'custom_db_types' => [
),
],
/*
|--------------------------------------------------------------------------
@@ -226,10 +226,10 @@ return array(
| Cast the given "real type" to the given "type".
|
*/
'type_overrides' => array(
'type_overrides' => [
'integer' => 'int',
'boolean' => 'bool',
),
],
/*
|--------------------------------------------------------------------------
@@ -253,5 +253,4 @@ return array(
|
*/
'force_fqn' => false,
);
];
+1 -1
View File
@@ -5,7 +5,7 @@ grumphp:
triggered_by: [php]
metadata:
task: composer_script
phpcs:
phpcsfixer:
script: check-style
triggered_by: [php]
metadata:
+13 -13
View File
@@ -11,13 +11,13 @@
namespace Barryvdh\LaravelIdeHelper;
use Closure;
use ReflectionClass;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
use Illuminate\Config\Repository as ConfigRepository;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
use Closure;
use Illuminate\Config\Repository as ConfigRepository;
use ReflectionClass;
class Alias
{
@@ -31,12 +31,12 @@ class Alias
protected $short;
protected $namespace = '__root';
protected $root = null;
protected $classes = array();
protected $methods = array();
protected $usedMethods = array();
protected $classes = [];
protected $methods = [];
protected $usedMethods = [];
protected $valid = false;
protected $magicMethods = array();
protected $interfaces = array();
protected $magicMethods = [];
protected $interfaces = [];
protected $phpdoc = null;
/** @var ConfigRepository */
@@ -50,7 +50,7 @@ class Alias
* @param array $magicMethods
* @param array $interfaces
*/
public function __construct($config, $alias, $facade, $magicMethods = array(), $interfaces = array())
public function __construct($config, $alias, $facade, $magicMethods = [], $interfaces = [])
{
$this->alias = $alias;
$this->magicMethods = $magicMethods;
@@ -82,7 +82,7 @@ class Alias
if ($facade === '\Illuminate\Database\Eloquent\Model') {
$this->usedMethods = array('decrement', 'increment');
$this->usedMethods = ['decrement', 'increment'];
}
}
@@ -289,12 +289,12 @@ class Alias
//When the database connection is not set, some classes will be skipped
} catch (\PDOException $e) {
$this->error(
"PDOException: " . $e->getMessage() .
'PDOException: ' . $e->getMessage() .
"\nPlease configure your database connection correctly, or use the sqlite memory driver (-M)." .
" Skipping $facade."
);
} catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nSkipping $facade.");
$this->error('Exception: ' . $e->getMessage() . "\nSkipping $facade.");
}
}
+18 -18
View File
@@ -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'],
];
}
}
+4 -5
View File
@@ -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],
];
}
/**
+46 -46
View File
@@ -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();
+2 -2
View File
@@ -8,12 +8,12 @@
namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class Eloquent
{
-1
View File
@@ -8,7 +8,6 @@ use ReflectionClass;
class Factories
{
public static function all()
{
$factories = [];
+22 -22
View File
@@ -11,10 +11,8 @@
namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Collection;
use ReflectionClass;
use Symfony\Component\Console\Output\OutputInterface;
class Generator
@@ -28,9 +26,9 @@ class Generator
/** @var \Symfony\Component\Console\Output\OutputInterface */
protected $output;
protected $extra = array();
protected $magic = array();
protected $interfaces = array();
protected $extra = [];
protected $magic = [];
protected $interfaces = [];
protected $helpers;
/**
@@ -40,8 +38,10 @@ class Generator
* @param string $helpers
*/
public function __construct(
/*ConfigRepository */ $config,
/* Illuminate\View\Factory */ $view,
/*ConfigRepository */
$config,
/* Illuminate\View\Factory */
$view,
OutputInterface $output = null,
$helpers = ''
) {
@@ -93,16 +93,16 @@ class Generator
public function generateJsonHelper()
{
$classes = array();
$classes = [];
foreach ($this->getValidAliases() as $aliases) {
foreach ($aliases as $alias) {
$functions = array();
$functions = [];
foreach ($alias->getMethods() as $method) {
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
}
$classes[$alias->getAlias()] = array(
$classes[$alias->getAlias()] = [
'functions' => $functions,
);
];
}
}
@@ -111,11 +111,11 @@ class Generator
$flags |= JSON_PRETTY_PRINT;
}
return json_encode(array(
'php' => array(
return json_encode([
'php' => [
'classes' => $classes,
),
), $flags);
],
], $flags);
}
protected function detectDrivers()
@@ -129,7 +129,7 @@ class Generator
&& app()->bound('auth')
) {
$class = get_class(\Auth::guard());
$this->extra['Auth'] = array($class);
$this->extra['Auth'] = [$class];
$this->interfaces['\Illuminate\Auth\UserProviderInterface'] = $class;
}
} catch (\Exception $e) {
@@ -138,7 +138,7 @@ class Generator
try {
if (class_exists('DB') && is_a('DB', '\Illuminate\Support\Facades\DB', true)) {
$class = get_class(\DB::connection());
$this->extra['DB'] = array($class);
$this->extra['DB'] = [$class];
$this->interfaces['\Illuminate\Database\ConnectionInterface'] = $class;
}
} catch (\Exception $e) {
@@ -148,7 +148,7 @@ class Generator
if (class_exists('Cache') && is_a('Cache', '\Illuminate\Support\Facades\Cache', true)) {
$driver = get_class(\Cache::driver());
$store = get_class(\Cache::getStore());
$this->extra['Cache'] = array($driver, $store);
$this->extra['Cache'] = [$driver, $store];
$this->interfaces['\Illuminate\Cache\StoreInterface'] = $store;
}
} catch (\Exception $e) {
@@ -157,7 +157,7 @@ class Generator
try {
if (class_exists('Queue') && is_a('Queue', '\Illuminate\Support\Facades\Queue', true)) {
$class = get_class(\Queue::connection());
$this->extra['Queue'] = array($class);
$this->extra['Queue'] = [$class];
$this->interfaces['\Illuminate\Queue\QueueInterface'] = $class;
}
} catch (\Exception $e) {
@@ -166,7 +166,7 @@ class Generator
try {
if (class_exists('SSH') && is_a('SSH', '\Illuminate\Support\Facades\SSH', true)) {
$class = get_class(\SSH::connection());
$this->extra['SSH'] = array($class);
$this->extra['SSH'] = [$class];
$this->interfaces['\Illuminate\Remote\ConnectionInterface'] = $class;
}
} catch (\Exception $e) {
@@ -175,7 +175,7 @@ class Generator
try {
if (class_exists('Storage') && is_a('Storage', '\Illuminate\Support\Facades\Storage', true)) {
$class = get_class(\Storage::disk());
$this->extra['Storage'] = array($class);
$this->extra['Storage'] = [$class];
$this->interfaces['\Illuminate\Contracts\Filesystem\Filesystem'] = $class;
}
} catch (\Exception $e) {
@@ -198,7 +198,7 @@ class Generator
continue;
}
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : [];
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
if ($alias->isValid()) {
//Add extra methods, from other classes (magic static calls)
+1 -2
View File
@@ -24,7 +24,6 @@ use Illuminate\View\FileViewFinder;
class IdeHelperServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
@@ -107,7 +106,7 @@ class IdeHelperServiceProvider extends ServiceProvider
*/
public function provides()
{
return array('command.ide-helper.generate', 'command.ide-helper.models');
return ['command.ide-helper.generate', 'command.ide-helper.models'];
}
/**
+1 -1
View File
@@ -20,7 +20,7 @@ class Macro extends Method
$alias,
$class,
$methodName = null,
$interfaces = array()
$interfaces = []
) {
parent::__construct($method, $alias, $class, $methodName, $interfaces);
}
+11 -11
View File
@@ -13,10 +13,10 @@ namespace Barryvdh\LaravelIdeHelper;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
use Barryvdh\Reflection\DocBlock\Tag\ParamTag;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\ParamTag;
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
@@ -32,9 +32,9 @@ class Method
protected $declaringClassName;
protected $name;
protected $namespace;
protected $params = array();
protected $params_with_default = array();
protected $interfaces = array();
protected $params = [];
protected $params_with_default = [];
protected $interfaces = [];
protected $real_name;
protected $return = null;
protected $root;
@@ -46,7 +46,7 @@ class Method
* @param string|null $methodName
* @param array $interfaces
*/
public function __construct($method, $alias, $class, $methodName = null, $interfaces = array())
public function __construct($method, $alias, $class, $methodName = null, $interfaces = [])
{
$this->method = $method;
$this->interfaces = $interfaces;
@@ -119,7 +119,7 @@ class Method
*/
public function isInstanceCall()
{
return ! ($this->method->isClosure() || $this->method->isStatic());
return !($this->method->isClosure() || $this->method->isStatic());
}
/**
@@ -302,7 +302,7 @@ class Method
*/
public function shouldReturn()
{
if ($this->return !== "void" && $this->method->name !== "__construct") {
if ($this->return !== 'void' && $this->method->name !== '__construct') {
return true;
}
@@ -318,8 +318,8 @@ class Method
public function getParameters($method)
{
//Loop through the default values for parameters, and make the correct output string
$params = array();
$paramsWithDefault = array();
$params = [];
$paramsWithDefault = [];
foreach ($method->getParameters() as $param) {
$paramStr = $param->isVariadic() ? '...$' . $param->getName() : '$' . $param->getName();
$params[] = $paramStr;
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console;
use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
@@ -1,10 +1,11 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections;
use Illuminate\Database\Eloquent\Collection;
class SimpleCollection extends Collection
{
}
@@ -6,9 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Collections\SimpleCollection;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -7,10 +7,8 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Carbon\CarbonImmutable;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -8,5 +8,4 @@ use Illuminate\Database\Eloquent\Model;
class Account extends Model
{
}
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhp
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,5 +6,4 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
final class CastType
{
}
@@ -6,13 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
use Eloquent;
use Illuminate\Database\Eloquent\{
Builder as EloquentBuilder,
Collection,
SoftDeletes
};
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Carbon;
@@ -20,6 +18,18 @@ class Post extends Model
{
use SoftDeletes;
/**
* Special hack to avoid code style fixer removing unused imports
* which play a role when generating the snapshot
*/
private $hack = [
Carbon::class,
Collection::class,
Eloquent::class,
EloquentBuilder::class,
QueryBuilder::class,
];
protected $casts = [
'char_not_nullable' => CastType::class,
];
@@ -6,12 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,13 +6,11 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Casts\CastType;
use Eloquent;
use Illuminate\Database\Eloquent\{
Builder as EloquentBuilder,
Collection,
SoftDeletes
};
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Support\Carbon;
@@ -180,6 +178,18 @@ class Post extends Model
{
use SoftDeletes;
/**
* Special hack to avoid code style fixer removing unused imports
* which play a role when generating the snapshot
*/
private $hack = [
Carbon::class,
Collection::class,
Eloquent::class,
EloquentBuilder::class,
QueryBuilder::class,
];
protected $casts = [
'char_not_nullable' => CastType::class,
];
@@ -8,5 +8,4 @@ use Illuminate\Database\Eloquent\Builder;
class EMaterialQueryBuilder extends Builder
{
}
@@ -6,12 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Getter;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models;
use DateTime;
use Illuminate\Database\Eloquent\Model;
class Ignored extends Model
+1 -3
View File
@@ -7,8 +7,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Ignored\Models\Ignored;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -17,7 +15,7 @@ class Test extends AbstractModelsCommand
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper.ignored_models', [
Ignored::class
Ignored::class,
]);
}
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Interfaces;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
final class Test extends AbstractModelsCommand
{
@@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
class CastedProperty
{
}
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
@@ -6,13 +6,10 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCas
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Application;
use Mockery;
class Test extends AbstractModelsCommand
{
protected function setUp(): void
{
parent::setUp();
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\MagicWhere;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,10 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspec
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
use function file_get_contents;
class Test extends AbstractModelsCommand
{
@@ -6,10 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\RelationCountPro
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartRes
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
@@ -6,8 +6,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Illuminate\Filesystem\Filesystem;
use Mockery;
class Test extends AbstractModelsCommand
{
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use Barryvdh\LaravelIdeHelper\Method;
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use PHPUnit\Framework\Assert;
+2
View File
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests;
use PHPUnit\Framework\Assert;