mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
chore: psr12 (#964)
This commit is contained in:
+2
-2
@@ -60,8 +60,8 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"analyze": "psalm",
|
"analyze": "psalm",
|
||||||
"check-style": "phpcs -p --standard=PSR2 src/",
|
"check-style": "phpcs -p --standard=PSR12 src/",
|
||||||
"fix-style": "phpcbf -p --standard=PSR2 src/",
|
"fix-style": "phpcbf -p --standard=PSR12 src/",
|
||||||
"test": "phpunit"
|
"test": "phpunit"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ grumphp:
|
|||||||
group: []
|
group: []
|
||||||
always_execute: false
|
always_execute: false
|
||||||
phpcs:
|
phpcs:
|
||||||
standard: PSR2
|
standard: PSR12
|
||||||
warning_severity: ~
|
warning_severity: ~
|
||||||
ignore_patterns:
|
ignore_patterns:
|
||||||
- tests/
|
- tests/
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator - Eloquent Model Mixin
|
* Laravel IDE Helper Generator - Eloquent Model Mixin
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
@@ -76,9 +77,11 @@ class GeneratorCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if (file_exists(base_path() . '/vendor/compiled.php') ||
|
if (
|
||||||
|
file_exists(base_path() . '/vendor/compiled.php') ||
|
||||||
file_exists(base_path() . '/bootstrap/cache/compiled.php') ||
|
file_exists(base_path() . '/bootstrap/cache/compiled.php') ||
|
||||||
file_exists(base_path() . '/storage/framework/compiled.php')) {
|
file_exists(base_path() . '/storage/framework/compiled.php')
|
||||||
|
) {
|
||||||
$this->error(
|
$this->error(
|
||||||
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
|
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
@@ -98,7 +99,7 @@ class MetaCommand extends Command
|
|||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
||||||
$this->comment("Cannot make '$abstract': ".$e->getMessage());
|
$this->comment("Cannot make '$abstract': " . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
@@ -109,9 +110,10 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
//If filename is default and Write is not specified, ask what to do
|
//If filename is default and Write is not specified, ask what to do
|
||||||
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
if (!$this->write && $filename === $this->filename && !$this->option('nowrite')) {
|
||||||
if ($this->confirm(
|
if (
|
||||||
"Do you want to overwrite the existing model files? Choose no to write to $filename instead"
|
$this->confirm(
|
||||||
)
|
"Do you want to overwrite the existing model files? Choose no to write to $filename instead"
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
$this->write = true;
|
$this->write = true;
|
||||||
}
|
}
|
||||||
@@ -254,7 +256,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
if (!$hasDoctrine) {
|
if (!$hasDoctrine) {
|
||||||
$this->error(
|
$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`.'
|
'Please require that in your composer.json and run `composer update`.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -455,10 +457,11 @@ class ModelsCommand extends Command
|
|||||||
if ($methods) {
|
if ($methods) {
|
||||||
sort($methods);
|
sort($methods);
|
||||||
foreach ($methods as $method) {
|
foreach ($methods as $method) {
|
||||||
if (Str::startsWith($method, 'get') && Str::endsWith(
|
if (
|
||||||
$method,
|
Str::startsWith($method, 'get') && Str::endsWith(
|
||||||
'Attribute'
|
$method,
|
||||||
) && $method !== 'getAttribute'
|
'Attribute'
|
||||||
|
) && $method !== 'getAttribute'
|
||||||
) {
|
) {
|
||||||
//Magic get<name>Attribute
|
//Magic get<name>Attribute
|
||||||
$name = Str::snake(substr($method, 3, -9));
|
$name = Str::snake(substr($method, 3, -9));
|
||||||
@@ -468,10 +471,11 @@ class ModelsCommand extends Command
|
|||||||
$type = $this->getTypeInModel($model, $type);
|
$type = $this->getTypeInModel($model, $type);
|
||||||
$this->setProperty($name, $type, true, null);
|
$this->setProperty($name, $type, true, null);
|
||||||
}
|
}
|
||||||
} elseif (Str::startsWith($method, 'set') && Str::endsWith(
|
} elseif (
|
||||||
$method,
|
Str::startsWith($method, 'set') && Str::endsWith(
|
||||||
'Attribute'
|
$method,
|
||||||
) && $method !== 'setAttribute'
|
'Attribute'
|
||||||
|
) && $method !== 'setAttribute'
|
||||||
) {
|
) {
|
||||||
//Magic set<name>Attribute
|
//Magic set<name>Attribute
|
||||||
$name = Str::snake(substr($method, 3, -9));
|
$name = Str::snake(substr($method, 3, -9));
|
||||||
@@ -500,7 +504,8 @@ class ModelsCommand extends Command
|
|||||||
$builder = $this->getClassNameInModel($model, get_class($model->newModelQuery()));
|
$builder = $this->getClassNameInModel($model, get_class($model->newModelQuery()));
|
||||||
|
|
||||||
$this->setMethod($method, $builder . "|" . $this->getClassNameInModel($model, get_class($model)));
|
$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')
|
&& !Str::startsWith($method, 'get')
|
||||||
) {
|
) {
|
||||||
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
||||||
@@ -527,7 +532,8 @@ class ModelsCommand extends Command
|
|||||||
$begin = strpos($code, 'function(');
|
$begin = strpos($code, 'function(');
|
||||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||||
|
|
||||||
foreach (array(
|
foreach (
|
||||||
|
array(
|
||||||
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
||||||
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
||||||
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
|
'hasOneThrough' => '\Illuminate\Database\Eloquent\Relations\HasOneThrough',
|
||||||
@@ -539,7 +545,8 @@ class ModelsCommand extends Command
|
|||||||
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
|
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
|
||||||
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
||||||
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
|
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
|
||||||
) as $relation => $impl) {
|
) as $relation => $impl
|
||||||
|
) {
|
||||||
$search = '$this->' . $relation . '(';
|
$search = '$this->' . $relation . '(';
|
||||||
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
|
if (stripos($code, $search) || ltrim($impl, '\\') === ltrim((string)$type, '\\')) {
|
||||||
//Resolve the relation's model to a Relation object.
|
//Resolve the relation's model to a Relation object.
|
||||||
@@ -662,7 +669,7 @@ class ModelsCommand extends Command
|
|||||||
if ($type !== null) {
|
if ($type !== null) {
|
||||||
$newType = $this->getTypeOverride($type);
|
$newType = $this->getTypeOverride($type);
|
||||||
if ($nullable) {
|
if ($nullable) {
|
||||||
$newType .='|null';
|
$newType .= '|null';
|
||||||
}
|
}
|
||||||
$this->properties[$name]['type'] = $newType;
|
$this->properties[$name]['type'] = $newType;
|
||||||
}
|
}
|
||||||
@@ -865,7 +872,7 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Model $model */
|
/** @var \Illuminate\Database\Eloquent\Model $model */
|
||||||
$model = new $className;
|
$model = new $className();
|
||||||
return '\\' . get_class($model->newCollection());
|
return '\\' . get_class($model->newCollection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*
|
*
|
||||||
* @author Charles A. Peterson <[email protected]>
|
* @author Charles A. Peterson <[email protected]>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|||||||
+7
-4
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
@@ -69,7 +70,7 @@ class Generator
|
|||||||
public function generate($format = 'php')
|
public function generate($format = 'php')
|
||||||
{
|
{
|
||||||
// Check if the generator for this format exists
|
// Check if the generator for this format exists
|
||||||
$method = 'generate'.ucfirst($format).'Helper';
|
$method = 'generate' . ucfirst($format) . 'Helper';
|
||||||
if (method_exists($this, $method)) {
|
if (method_exists($this, $method)) {
|
||||||
return $this->$method();
|
return $this->$method();
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,7 @@ class Generator
|
|||||||
foreach ($aliases as $alias) {
|
foreach ($aliases as $alias) {
|
||||||
$functions = array();
|
$functions = array();
|
||||||
foreach ($alias->getMethods() as $method) {
|
foreach ($alias->getMethods() as $method) {
|
||||||
$functions[$method->getName()] = '('. $method->getParamsWithDefault().')';
|
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
|
||||||
}
|
}
|
||||||
$classes[$alias->getAlias()] = array(
|
$classes[$alias->getAlias()] = array(
|
||||||
'functions' => $functions,
|
'functions' => $functions,
|
||||||
@@ -123,8 +124,10 @@ class Generator
|
|||||||
$this->interfaces['\Illuminate\Contracts\Auth\Authenticatable'] = $defaultUserModel;
|
$this->interfaces['\Illuminate\Contracts\Auth\Authenticatable'] = $defaultUserModel;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)
|
if (
|
||||||
&& app()->bound('auth')) {
|
class_exists('Auth') && is_a('Auth', '\Illuminate\Support\Facades\Auth', true)
|
||||||
|
&& app()->bound('auth')
|
||||||
|
) {
|
||||||
if (class_exists('\Illuminate\Foundation\Application')) {
|
if (class_exists('\Illuminate\Foundation\Application')) {
|
||||||
$authMethod = version_compare(Application::VERSION, '5.2', '>=') ? 'guard' : 'driver';
|
$authMethod = version_compare(Application::VERSION, '5.2', '>=') ? 'guard' : 'driver';
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laravel IDE Helper Generator
|
* Laravel IDE Helper Generator
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user