mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 18:13:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39c148ad42 | ||
|
|
2b3c9a2449 | ||
|
|
725711022b | ||
|
|
881f77156c | ||
|
|
0fad511954 | ||
|
|
754bb4d075 | ||
|
|
bcb881b20d | ||
|
|
d00600d769 | ||
|
|
858dd40844 | ||
|
|
4cd11a4d33 | ||
|
|
5439781e7c | ||
|
|
190bf07c05 | ||
|
|
3d7f124089 | ||
|
|
32df0a3bc6 | ||
|
|
2f8283a746 | ||
|
|
2a63b31475 | ||
|
|
494d1593c8 | ||
|
|
e513fb34dc | ||
|
|
5db82752ef | ||
|
|
1f555bc194 | ||
|
|
b0ce5325de | ||
|
|
aeae59d0af | ||
|
|
001719245c | ||
|
|
99226c92b7 | ||
|
|
dda63bf8df | ||
|
|
3d7f45479e | ||
|
|
7905dd3926 | ||
|
|
8d135a1dea | ||
|
|
858e730c00 | ||
|
|
2ab961e734 |
+1
-1
@@ -20,7 +20,7 @@ matrix:
|
|||||||
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
|
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
|
- travis_wait 20 travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/phpcs --standard=psr2 src/
|
- vendor/bin/phpcs --standard=psr2 src/
|
||||||
|
|||||||
+7
-7
@@ -11,15 +11,15 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7",
|
"php": ">=7",
|
||||||
"illuminate/support": "^5.5,<5.8",
|
"illuminate/support": "^5.5,<5.9",
|
||||||
"illuminate/console": "^5.5,<5.8",
|
"illuminate/console": "^5.5,<5.9",
|
||||||
"illuminate/filesystem": "^5.5,<5.8",
|
"illuminate/filesystem": "^5.5,<5.9",
|
||||||
"barryvdh/reflection-docblock": "^2.0.4",
|
"barryvdh/reflection-docblock": "^2.0.6",
|
||||||
"composer/composer": "^1.6"
|
"composer/composer": "^1.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"illuminate/config": "^5.1,<5.8",
|
"illuminate/config": "^5.1,<5.9",
|
||||||
"illuminate/view": "^5.1,<5.8",
|
"illuminate/view": "^5.1,<5.9",
|
||||||
"phpro/grumphp": "^0.14",
|
"phpro/grumphp": "^0.14",
|
||||||
"phpunit/phpunit" : "4.*",
|
"phpunit/phpunit" : "4.*",
|
||||||
"scrutinizer/ocular": "~1.1",
|
"scrutinizer/ocular": "~1.1",
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "2.5-dev"
|
"dev-master": "2.6-dev"
|
||||||
},
|
},
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
|
|||||||
@@ -38,6 +38,21 @@ return array(
|
|||||||
|
|
||||||
'write_model_magic_where' => true,
|
'write_model_magic_where' => true,
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Write Eloquent Model Mixins
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This will add the necessary DocBlock mixins to the model class
|
||||||
|
| contained in the Laravel Framework. This helps the IDE with
|
||||||
|
| auto-completion.
|
||||||
|
|
|
||||||
|
| Please be aware that this setting changes a file within the /vendor directory.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'write_eloquent_model_mixins' => false,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Helper files to include
|
| Helper files to include
|
||||||
@@ -178,4 +193,16 @@ return array(
|
|||||||
'integer' => 'int',
|
'integer' => 'int',
|
||||||
'boolean' => 'bool',
|
'boolean' => 'bool',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Include DocBlocks from classes
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Include DocBlocks from classes to allow additional code inspection for
|
||||||
|
| magic methods and properties.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'include_class_docblocks' => false,
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -97,11 +97,11 @@ The `Illuminate/Support/helpers.php` is already set up, but you can add/remove y
|
|||||||
|
|
||||||
### Automatic phpDocs for models
|
### Automatic phpDocs for models
|
||||||
|
|
||||||
> You need to require `doctrine/dbal: ~2.3` in your own composer.json to get database columns.
|
> You need to add `doctrine/dbal: ~2.3` to require-dev in your own composer.json to get database columns.
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require doctrine/dbal
|
composer require --dev doctrine/dbal
|
||||||
```
|
```
|
||||||
|
|
||||||
If you don't want to write your properties yourself, you can use the command `php artisan ide-helper:models` to generate
|
If you don't want to write your properties yourself, you can use the command `php artisan ide-helper:models` to generate
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
|||||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
|
<?php if($method->isInstanceCall()):?>
|
||||||
|
/** @var <?=$method->getRoot()?> $instance */
|
||||||
|
<?php endif?>
|
||||||
|
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRootMethodCall() ?>;
|
||||||
}
|
}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
}
|
}
|
||||||
@@ -57,8 +60,11 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
|||||||
|
|
||||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRoot() ?>::<?= $method->getRealName() ?>(<?= $method->getParams() ?>);
|
<?php if($method->isInstanceCall()):?>
|
||||||
|
/** @var <?=$method->getRoot()?> $instance */
|
||||||
|
<?php endif?>
|
||||||
|
<?= $method->shouldReturn() ? 'return ': '' ?><?= $method->getRootMethodCall() ?>;
|
||||||
}
|
}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php endif; ?>}
|
<?php endif; ?>}
|
||||||
|
|||||||
+64
-15
@@ -10,10 +10,13 @@
|
|||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper;
|
namespace Barryvdh\LaravelIdeHelper;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use ReflectionClass;
|
||||||
use Barryvdh\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use Barryvdh\Reflection\DocBlock\Context;
|
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\Serializer as DocBlockSerializer;
|
||||||
use ReflectionClass;
|
|
||||||
|
|
||||||
class Alias
|
class Alias
|
||||||
{
|
{
|
||||||
@@ -34,17 +37,22 @@ class Alias
|
|||||||
protected $interfaces = array();
|
protected $interfaces = array();
|
||||||
protected $phpdoc = null;
|
protected $phpdoc = null;
|
||||||
|
|
||||||
|
/** @var ConfigRepository */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $alias
|
* @param ConfigRepository $config
|
||||||
* @param string $facade
|
* @param string $alias
|
||||||
* @param array $magicMethods
|
* @param string $facade
|
||||||
* @param array $interfaces
|
* @param array $magicMethods
|
||||||
|
* @param array $interfaces
|
||||||
*/
|
*/
|
||||||
public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array())
|
public function __construct($config, $alias, $facade, $magicMethods = array(), $interfaces = array())
|
||||||
{
|
{
|
||||||
$this->alias = $alias;
|
$this->alias = $alias;
|
||||||
$this->magicMethods = $magicMethods;
|
$this->magicMethods = $magicMethods;
|
||||||
$this->interfaces = $interfaces;
|
$this->interfaces = $interfaces;
|
||||||
|
$this->config = $config;
|
||||||
|
|
||||||
// Make the class absolute
|
// Make the class absolute
|
||||||
$facade = '\\' . ltrim($facade, '\\');
|
$facade = '\\' . ltrim($facade, '\\');
|
||||||
@@ -175,6 +183,10 @@ class Alias
|
|||||||
*/
|
*/
|
||||||
public function getMethods()
|
public function getMethods()
|
||||||
{
|
{
|
||||||
|
if (count($this->methods) > 0) {
|
||||||
|
return $this->methods;
|
||||||
|
}
|
||||||
|
|
||||||
$this->addMagicMethods();
|
$this->addMagicMethods();
|
||||||
$this->detectMethods();
|
$this->detectMethods();
|
||||||
return $this->methods;
|
return $this->methods;
|
||||||
@@ -356,14 +368,17 @@ class Alias
|
|||||||
$properties = $reflection->getStaticProperties();
|
$properties = $reflection->getStaticProperties();
|
||||||
$macros = isset($properties['macros']) ? $properties['macros'] : [];
|
$macros = isset($properties['macros']) ? $properties['macros'] : [];
|
||||||
foreach ($macros as $macro_name => $macro_func) {
|
foreach ($macros as $macro_name => $macro_func) {
|
||||||
// Add macros
|
if (!in_array($macro_name, $this->usedMethods)) {
|
||||||
$this->methods[] = new Macro(
|
// Add macros
|
||||||
$this->getMacroFunction($macro_func),
|
$this->methods[] = new Macro(
|
||||||
$this->alias,
|
$this->getMacroFunction($macro_func),
|
||||||
$reflection,
|
$this->alias,
|
||||||
$macro_name,
|
$reflection,
|
||||||
$this->interfaces
|
$macro_name,
|
||||||
);
|
$this->interfaces
|
||||||
|
);
|
||||||
|
$this->usedMethods[] = $macro_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,6 +396,10 @@ class Alias
|
|||||||
return new \ReflectionMethod($macro_func[0], $macro_func[1]);
|
return new \ReflectionMethod($macro_func[0], $macro_func[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_object($macro_func) && is_callable($macro_func) && !$macro_func instanceof Closure) {
|
||||||
|
return new \ReflectionMethod($macro_func, '__invoke');
|
||||||
|
}
|
||||||
|
|
||||||
return new \ReflectionFunction($macro_func);
|
return new \ReflectionFunction($macro_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,12 +414,42 @@ class Alias
|
|||||||
$serializer = new DocBlockSerializer(1, $prefix);
|
$serializer = new DocBlockSerializer(1, $prefix);
|
||||||
|
|
||||||
if ($this->phpdoc) {
|
if ($this->phpdoc) {
|
||||||
|
if ($this->config->get('ide-helper.include_class_docblocks')) {
|
||||||
|
// if a class doesn't expose any DocBlock tags
|
||||||
|
// we can perform reflection on the class and
|
||||||
|
// add in the original class DocBlock
|
||||||
|
if (count($this->phpdoc->getTags()) === 0) {
|
||||||
|
$class = new ReflectionClass($this->root);
|
||||||
|
$this->phpdoc = new DocBlock($class->getDocComment());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->removeDuplicateMethodsFromPhpDoc();
|
||||||
return $serializer->getDocComment($this->phpdoc);
|
return $serializer->getDocComment($this->phpdoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes method tags from the doc comment that already appear as functions inside the class.
|
||||||
|
* This prevents duplicate function errors in the IDE.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function removeDuplicateMethodsFromPhpDoc()
|
||||||
|
{
|
||||||
|
$methodNames = array_map(function (Method $method) {
|
||||||
|
return $method->getName();
|
||||||
|
}, $this->getMethods());
|
||||||
|
|
||||||
|
foreach ($this->phpdoc->getTags() as $tag) {
|
||||||
|
if ($tag instanceof MethodTag && in_array($tag->getMethodName(), $methodNames)) {
|
||||||
|
$this->phpdoc->deleteTag($tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output an error.
|
* Output an error.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ class GeneratorCommand extends Command
|
|||||||
|
|
||||||
if ($written !== false) {
|
if ($written !== false) {
|
||||||
$this->info("A new helper file was written to $filename");
|
$this->info("A new helper file was written to $filename");
|
||||||
|
|
||||||
|
if ($this->option('write_mixins')) {
|
||||||
|
Eloquent::writeEloquentModelHelper($this, $this->files);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->error("The helper file could not be created at $filename");
|
$this->error("The helper file could not be created at $filename");
|
||||||
}
|
}
|
||||||
@@ -158,9 +162,11 @@ class GeneratorCommand extends Command
|
|||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$format = $this->config->get('ide-helper.format');
|
$format = $this->config->get('ide-helper.format');
|
||||||
|
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array('format', "F", InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format),
|
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('helpers', "H", InputOption::VALUE_NONE, 'Include the helper files'),
|
||||||
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
|
array('memory', "M", InputOption::VALUE_NONE, 'Use sqlite memory driver'),
|
||||||
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
|
array('sublime', "S", InputOption::VALUE_NONE, 'DEPRECATED: Use different style for SublimeText CodeIntel'),
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class MetaCommand extends Command
|
|||||||
protected function registerClassAutoloadExceptions()
|
protected function registerClassAutoloadExceptions()
|
||||||
{
|
{
|
||||||
spl_autoload_register(function ($class) {
|
spl_autoload_register(function ($class) {
|
||||||
throw new \Exception("Class '$class' not found.");
|
throw new \ReflectionException("Class '$class' not found.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -446,12 +446,17 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
|
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
|
||||||
$reflection = new \ReflectionClass($model);
|
$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)
|
} 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
|
||||||
$reflection = new \ReflectionMethod($model, $method);
|
$reflection = new \ReflectionMethod($model, $method);
|
||||||
|
// php 7.x type or fallback to docblock
|
||||||
|
$type = (string) $reflection->getReturnType() ?: (string)$this->getReturnTypeFromDocBlock($reflection);
|
||||||
|
|
||||||
$file = new \SplFileObject($reflection->getFileName());
|
$file = new \SplFileObject($reflection->getFileName());
|
||||||
$file->seek($reflection->getStartLine() - 1);
|
$file->seek($reflection->getStartLine() - 1);
|
||||||
@@ -466,23 +471,23 @@ class ModelsCommand extends Command
|
|||||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||||
|
|
||||||
foreach (array(
|
foreach (array(
|
||||||
'hasMany',
|
'hasMany' => '\Illuminate\Database\Eloquent\Relations\HasMany',
|
||||||
'hasManyThrough',
|
'hasManyThrough' => '\Illuminate\Database\Eloquent\Relations\HasManyThrough',
|
||||||
'belongsToMany',
|
'belongsToMany' => '\Illuminate\Database\Eloquent\Relations\BelongsToMany',
|
||||||
'hasOne',
|
'hasOne' => '\Illuminate\Database\Eloquent\Relations\HasOne',
|
||||||
'belongsTo',
|
'belongsTo' => '\Illuminate\Database\Eloquent\Relations\BelongsTo',
|
||||||
'morphOne',
|
'morphOne' => '\Illuminate\Database\Eloquent\Relations\MorphOne',
|
||||||
'morphTo',
|
'morphTo' => '\Illuminate\Database\Eloquent\Relations\MorphTo',
|
||||||
'morphMany',
|
'morphMany' => '\Illuminate\Database\Eloquent\Relations\MorphMany',
|
||||||
'morphToMany',
|
'morphToMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany',
|
||||||
'morphedByMany'
|
'morphedByMany' => '\Illuminate\Database\Eloquent\Relations\MorphToMany'
|
||||||
) as $relation) {
|
) as $relation => $impl) {
|
||||||
$search = '$this->' . $relation . '(';
|
$search = '$this->' . $relation . '(';
|
||||||
if ($pos = stripos($code, $search)) {
|
if (stripos($code, $search) || stripos($impl, (string)$type) !== false) {
|
||||||
//Resolve the relation's model to a Relation object.
|
//Resolve the relation's model to a Relation object.
|
||||||
$methodReflection = new \ReflectionMethod($model, $method);
|
$methodReflection = new \ReflectionMethod($model, $method);
|
||||||
if ($methodReflection->getNumberOfParameters()) {
|
if ($methodReflection->getNumberOfParameters()) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relationObj = $model->$method();
|
$relationObj = $model->$method();
|
||||||
|
|||||||
+37
-7
@@ -32,27 +32,57 @@ class Eloquent
|
|||||||
$reflection = new \ReflectionClass($class);
|
$reflection = new \ReflectionClass($class);
|
||||||
$namespace = $reflection->getNamespaceName();
|
$namespace = $reflection->getNamespaceName();
|
||||||
$originalDoc = $reflection->getDocComment();
|
$originalDoc = $reflection->getDocComment();
|
||||||
|
|
||||||
if (!$originalDoc) {
|
if (!$originalDoc) {
|
||||||
$command->info('Unexpected no document on ' . $class);
|
$command->info('Unexpected no document on ' . $class);
|
||||||
}
|
}
|
||||||
$phpdoc = new DocBlock($reflection, new Context($namespace));
|
$phpdoc = new DocBlock($reflection, new Context($namespace));
|
||||||
|
|
||||||
$mixins = $phpdoc->getTagsByName('mixin');
|
$mixins = $phpdoc->getTagsByName('mixin');
|
||||||
foreach ($mixins as $m) {
|
$expectedMixins = [
|
||||||
if ($m->getContent() === '\Eloquent') {
|
'\Eloquent' => false,
|
||||||
$command->info('Tag Exists: @mixin \Eloquent in ' . $class);
|
'\Illuminate\Database\Eloquent\Builder' => false,
|
||||||
|
'\Illuminate\Database\Query\Builder' => false,
|
||||||
|
];
|
||||||
|
|
||||||
return;
|
foreach ($mixins as $m) {
|
||||||
|
$mixin = $m->getContent();
|
||||||
|
|
||||||
|
if (isset($expectedMixins[$mixin])) {
|
||||||
|
$command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class);
|
||||||
|
|
||||||
|
$expectedMixins[$mixin] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the Eloquent mixin
|
$changed = false;
|
||||||
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
|
foreach ($expectedMixins as $expectedMixin => $present) {
|
||||||
|
if ($present === false) {
|
||||||
|
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $expectedMixin, $phpdoc));
|
||||||
|
|
||||||
|
$changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing's changed, stop here.
|
||||||
|
if (!$changed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$serializer = new DocBlockSerializer();
|
$serializer = new DocBlockSerializer();
|
||||||
$serializer->getDocComment($phpdoc);
|
$serializer->getDocComment($phpdoc);
|
||||||
$docComment = $serializer->getDocComment($phpdoc);
|
$docComment = $serializer->getDocComment($phpdoc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
The new DocBlock is appended to the beginning of the class declaration.
|
||||||
|
Since there is no DocBlock, the declaration is used as a guide.
|
||||||
|
*/
|
||||||
|
if (!$originalDoc) {
|
||||||
|
$originalDoc = 'abstract class Model implements';
|
||||||
|
|
||||||
|
$docComment .= "\nabstract class Model implements";
|
||||||
|
}
|
||||||
|
|
||||||
$filename = $reflection->getFileName();
|
$filename = $reflection->getFileName();
|
||||||
if ($filename) {
|
if ($filename) {
|
||||||
$contents = $files->get($filename);
|
$contents = $files->get($filename);
|
||||||
@@ -61,7 +91,7 @@ class Eloquent
|
|||||||
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
||||||
if ($count > 0) {
|
if ($count > 0) {
|
||||||
if ($files->put($filename, $contents)) {
|
if ($files->put($filename, $contents)) {
|
||||||
$command->info('Wrote @mixin \Eloquent to ' . $filename);
|
$command->info('Wrote expected docblock to ' . $filename);
|
||||||
} else {
|
} else {
|
||||||
$command->error('File write failed to ' . $filename);
|
$command->error('File write failed to ' . $filename);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -198,12 +198,12 @@ class Generator
|
|||||||
// Get all aliases
|
// Get all aliases
|
||||||
foreach ($this->getAliases() as $name => $facade) {
|
foreach ($this->getAliases() as $name => $facade) {
|
||||||
// Skip the Redis facade, if not available (otherwise Fatal PHP Error)
|
// Skip the Redis facade, if not available (otherwise Fatal PHP Error)
|
||||||
if ($facade == 'Illuminate\Support\Facades\Redis' && !class_exists('Predis\Client')) {
|
if ($facade == 'Illuminate\Support\Facades\Redis' && $name == 'Redis' && !class_exists('Predis\Client')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
|
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array();
|
||||||
$alias = new Alias($name, $facade, $magicMethods, $this->interfaces);
|
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
|
||||||
if ($alias->isValid()) {
|
if ($alias->isValid()) {
|
||||||
//Add extra methods, from other classes (magic static calls)
|
//Add extra methods, from other classes (magic static calls)
|
||||||
if (array_key_exists($name, $this->extra)) {
|
if (array_key_exists($name, $this->extra)) {
|
||||||
|
|||||||
@@ -37,8 +37,10 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$viewPath = __DIR__.'/../resources/views';
|
if ($this->app->has('view')) {
|
||||||
$this->loadViewsFrom($viewPath, 'ide-helper');
|
$viewPath = __DIR__ . '/../resources/views';
|
||||||
|
$this->loadViewsFrom($viewPath, 'ide-helper');
|
||||||
|
}
|
||||||
|
|
||||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||||
if (function_exists('config_path')) {
|
if (function_exists('config_path')) {
|
||||||
|
|||||||
+29
-4
@@ -34,6 +34,7 @@ class Method
|
|||||||
protected $interfaces = array();
|
protected $interfaces = array();
|
||||||
protected $real_name;
|
protected $real_name;
|
||||||
protected $return = null;
|
protected $return = null;
|
||||||
|
protected $root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \ReflectionMethod|\ReflectionFunctionAbstract $method
|
* @param \ReflectionMethod|\ReflectionFunctionAbstract $method
|
||||||
@@ -47,9 +48,12 @@ class Method
|
|||||||
$this->method = $method;
|
$this->method = $method;
|
||||||
$this->interfaces = $interfaces;
|
$this->interfaces = $interfaces;
|
||||||
$this->name = $methodName ?: $method->name;
|
$this->name = $methodName ?: $method->name;
|
||||||
$this->real_name = $method->name;
|
$this->real_name = $method->isClosure() ? $this->name : $method->name;
|
||||||
$this->initClassDefinedProperties($method, $class);
|
$this->initClassDefinedProperties($method, $class);
|
||||||
|
|
||||||
|
//Reference the 'real' function in the declaring class
|
||||||
|
$this->root = '\\' . ltrim($class->getName(), '\\');
|
||||||
|
|
||||||
//Create a DocBlock and serializer instance
|
//Create a DocBlock and serializer instance
|
||||||
$this->initPhpDoc($method);
|
$this->initPhpDoc($method);
|
||||||
|
|
||||||
@@ -66,9 +70,6 @@ class Method
|
|||||||
|
|
||||||
//Make the method static
|
//Make the method static
|
||||||
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
|
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
|
||||||
|
|
||||||
//Reference the 'real' function in the declaring class
|
|
||||||
$this->root = '\\' . ltrim($class->getName(), '\\');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,6 +111,26 @@ class Method
|
|||||||
return $this->root;
|
return $this->root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isInstanceCall()
|
||||||
|
{
|
||||||
|
return ! ($this->method->isClosure() || $this->method->isStatic());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRootMethodCall()
|
||||||
|
{
|
||||||
|
if ($this->isInstanceCall()) {
|
||||||
|
return "\$instance->{$this->getRealName()}({$this->getParams()})";
|
||||||
|
} else {
|
||||||
|
return "{$this->getRoot()}::{$this->getRealName()}({$this->getParams()})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the docblock for this method
|
* Get the docblock for this method
|
||||||
*
|
*
|
||||||
@@ -243,6 +264,10 @@ class Method
|
|||||||
// Set the changed content
|
// Set the changed content
|
||||||
$tag->setContent($returnValue . ' ' . $tag->getDescription());
|
$tag->setContent($returnValue . ' ' . $tag->getDescription());
|
||||||
$this->return = $returnValue;
|
$this->return = $returnValue;
|
||||||
|
|
||||||
|
if ($tag->getType() === '$this') {
|
||||||
|
$tag->setType($this->root);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->return = null;
|
$this->return = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user