Merge pull request #626 from barryvdh/revert-624-Fix/623

Revert "Fixes a bug where a missing DocBlock caused errors"
This commit is contained in:
Barry vd. Heuvel
2018-02-08 17:01:01 +01:00
committed by GitHub
+7 -37
View File
@@ -32,57 +32,27 @@ 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');
$expectedMixins = [
'\Eloquent' => false,
'\Illuminate\Database\Eloquent\Builder' => false,
'\Illuminate\Database\Query\Builder' => false,
];
foreach ($mixins as $m) { foreach ($mixins as $m) {
$mixin = $m->getContent(); if ($m->getContent() === '\Eloquent') {
$command->info('Tag Exists: @mixin \Eloquent in ' . $class);
if (isset($expectedMixins[$mixin])) {
$command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class);
$expectedMixins[$mixin] = true;
}
}
$changed = false;
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; return;
} }
}
// add the Eloquent mixin
$phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc));
$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);
@@ -91,7 +61,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 expected docblock to ' . $filename); $command->info('Wrote @mixin \Eloquent to ' . $filename);
} else { } else {
$command->error('File write failed to ' . $filename); $command->error('File write failed to ' . $filename);
} }