mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16eb4f65ee | ||
|
|
0edf8f750e | ||
|
|
1b15d2930b | ||
|
|
3668e3821a | ||
|
|
7b4cef1ea4 | ||
|
|
cd2a71d43c | ||
|
|
c9132b28a6 | ||
|
|
8ab6e0536b | ||
|
|
87ebe458e9 | ||
|
|
9ef14f83be | ||
|
|
39c148ad42 | ||
|
|
2b3c9a2449 | ||
|
|
725711022b | ||
|
|
881f77156c | ||
|
|
0fad511954 |
+5
-5
@@ -11,15 +11,15 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7",
|
||||
"illuminate/support": "^5.5,<5.9",
|
||||
"illuminate/console": "^5.5,<5.9",
|
||||
"illuminate/filesystem": "^5.5,<5.9",
|
||||
"illuminate/support": "^5.5|^6",
|
||||
"illuminate/console": "^5.5|^6",
|
||||
"illuminate/filesystem": "^5.5|^6",
|
||||
"barryvdh/reflection-docblock": "^2.0.6",
|
||||
"composer/composer": "^1.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"illuminate/config": "^5.1,<5.9",
|
||||
"illuminate/view": "^5.1,<5.9",
|
||||
"illuminate/config": "^5.5|^6",
|
||||
"illuminate/view": "^5.5|^6",
|
||||
"phpro/grumphp": "^0.14",
|
||||
"phpunit/phpunit" : "4.*",
|
||||
"scrutinizer/ocular": "~1.1",
|
||||
|
||||
+3
-14
@@ -98,18 +98,7 @@ return array(
|
||||
'Session' => array('Illuminate\Session\Store'),
|
||||
),
|
||||
|
||||
'magic' => array(
|
||||
'Log' => array(
|
||||
'debug' => 'Monolog\Logger::addDebug',
|
||||
'info' => 'Monolog\Logger::addInfo',
|
||||
'notice' => 'Monolog\Logger::addNotice',
|
||||
'warning' => 'Monolog\Logger::addWarning',
|
||||
'error' => 'Monolog\Logger::addError',
|
||||
'critical' => 'Monolog\Logger::addCritical',
|
||||
'alert' => 'Monolog\Logger::addAlert',
|
||||
'emergency' => 'Monolog\Logger::addEmergency',
|
||||
)
|
||||
),
|
||||
'magic' => array(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -189,10 +178,10 @@ return array(
|
||||
| Cast the given "real type" to the given "type".
|
||||
|
|
||||
*/
|
||||
'type_overrides' => array(
|
||||
'type_overrides' => array(
|
||||
'integer' => 'int',
|
||||
'boolean' => 'bool',
|
||||
),
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
## Laravel 5 IDE Helper Generator
|
||||
## Laravel IDE Helper Generator
|
||||
|
||||
[![Latest Version on Packagist][ico-version]][link-packagist]
|
||||
[![Software License][ico-license]](LICENSE.md)
|
||||
@@ -29,7 +29,7 @@ Note: You do need CodeComplice for Sublime Text: https://github.com/spectacles/C
|
||||
Require this package with composer using the following command:
|
||||
|
||||
```bash
|
||||
composer require barryvdh/laravel-ide-helper
|
||||
composer require --dev barryvdh/laravel-ide-helper
|
||||
```
|
||||
|
||||
After updating composer, add the service provider to the `providers` array in `config/app.php`
|
||||
@@ -39,12 +39,6 @@ Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
|
||||
```
|
||||
**Laravel 5.5** uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
|
||||
|
||||
To install this package on only development systems, add the `--dev` flag to your composer command:
|
||||
|
||||
```bash
|
||||
composer require --dev barryvdh/laravel-ide-helper
|
||||
```
|
||||
|
||||
In Laravel, instead of adding the service provider in the `config/app.php` file, you can add the following code to your `app/Providers/AppServiceProvider.php` file, within the `register()` method:
|
||||
|
||||
```php
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
use Closure;
|
||||
use ReflectionClass;
|
||||
use Barryvdh\Reflection\DocBlock;
|
||||
use Barryvdh\Reflection\DocBlock\Context;
|
||||
@@ -395,7 +396,7 @@ class Alias
|
||||
return new \ReflectionMethod($macro_func[0], $macro_func[1]);
|
||||
}
|
||||
|
||||
if (is_object($macro_func) && is_callable($macro_func)) {
|
||||
if (is_object($macro_func) && is_callable($macro_func) && !$macro_func instanceof Closure) {
|
||||
return new \ReflectionMethod($macro_func, '__invoke');
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ class MetaCommand extends Command
|
||||
|
||||
protected $methods = [
|
||||
'new \Illuminate\Contracts\Container\Container',
|
||||
'\Illuminate\Container\Container::makeWith(0)',
|
||||
'\Illuminate\Contracts\Container\Container::make(0)',
|
||||
'\Illuminate\Contracts\Container\Container::makeWith(0)',
|
||||
'\App::make(0)',
|
||||
@@ -90,7 +91,7 @@ class MetaCommand extends Command
|
||||
if (is_object($concrete)) {
|
||||
$bindings[$abstract] = get_class($concrete);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
||||
$this->comment("Cannot make '$abstract': ".$e->getMessage());
|
||||
}
|
||||
@@ -135,7 +136,7 @@ class MetaCommand extends Command
|
||||
protected function registerClassAutoloadExceptions()
|
||||
{
|
||||
spl_autoload_register(function ($class) {
|
||||
throw new \Exception("Class '$class' not found.");
|
||||
throw new \ReflectionException("Class '$class' not found.");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class ModelsCommand extends Command
|
||||
//If filename is default and Write is not specified, ask what to do
|
||||
if (!$this->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?"
|
||||
"Do you want to overwrite the existing model files? Choose no to write to $filename instead"
|
||||
)
|
||||
) {
|
||||
$this->write = true;
|
||||
@@ -217,7 +217,7 @@ class ModelsCommand extends Command
|
||||
$output .= $this->createPhpDocs($name);
|
||||
$ignore[] = $name;
|
||||
$this->nullableColumns = [];
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ class ModelsCommand extends Command
|
||||
$realType = '\Illuminate\Support\Collection';
|
||||
break;
|
||||
default:
|
||||
$realType = 'mixed';
|
||||
$realType = class_exists($type) ? ('\\' . $type) : 'mixed';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -446,14 +446,17 @@ class ModelsCommand extends Command
|
||||
}
|
||||
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
|
||||
$reflection = new \ReflectionClass($model);
|
||||
$this->setMethod($method, '\Illuminate\Database\Eloquent\Builder|\\' . $reflection->getName());
|
||||
|
||||
$builder = get_class($model->newModelQuery());
|
||||
|
||||
$this->setMethod($method, "\\{$builder}|\\" . $reflection->getName());
|
||||
} elseif (!method_exists('Illuminate\Database\Eloquent\Model', $method)
|
||||
&& !Str::startsWith($method, 'get')
|
||||
) {
|
||||
//Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
|
||||
$reflection = new \ReflectionMethod($model, $method);
|
||||
// php 7.x type or fallback to docblock
|
||||
$type = (string) $reflection->getReturnType() ?: $this->getReturnTypeFromDocBlock($reflection);
|
||||
$type = (string)($reflection->getReturnType() ?: $this->getReturnTypeFromDocBlock($reflection));
|
||||
|
||||
$file = new \SplFileObject($reflection->getFileName());
|
||||
$file->seek($reflection->getStartLine() - 1);
|
||||
@@ -480,7 +483,7 @@ class ModelsCommand extends Command
|
||||
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
|
||||
) as $relation => $impl) {
|
||||
$search = '$this->' . $relation . '(';
|
||||
if (stripos($code, $search) || stripos($impl, $type) !== false) {
|
||||
if (stripos($code, $search) || stripos($impl, (string)$type) !== false) {
|
||||
//Resolve the relation's model to a Relation object.
|
||||
$methodReflection = new \ReflectionMethod($model, $method);
|
||||
if ($methodReflection->getNumberOfParameters()) {
|
||||
@@ -500,7 +503,7 @@ class ModelsCommand extends Command
|
||||
'morphToMany',
|
||||
'morphedByMany',
|
||||
];
|
||||
if (in_array($relation, $relations)) {
|
||||
if (strpos(get_class($relationObj), 'Many') !== false) {
|
||||
//Collection or array of models (because Collection is Arrayable)
|
||||
$this->setProperty(
|
||||
$method,
|
||||
@@ -508,6 +511,12 @@ class ModelsCommand extends Command
|
||||
true,
|
||||
null
|
||||
);
|
||||
$this->setProperty(
|
||||
Str::snake($method) . '_count',
|
||||
'int|null',
|
||||
true,
|
||||
false
|
||||
);
|
||||
} elseif ($relation === "morphTo") {
|
||||
// Model isn't specified because relation is polymorphic
|
||||
$this->setProperty(
|
||||
|
||||
Reference in New Issue
Block a user