mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Merge pull request #624 from iPaat/Fix/623
Fixes a bug where a missing DocBlock caused errors
This commit is contained in:
+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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user