Compare commits

...
3 Commits
Author SHA1 Message Date
Barry vd. Heuvel 5c304db44f Merge pull request #624 from iPaat/Fix/623
Fixes a bug where a missing DocBlock caused errors
2018-02-08 08:56:07 +01:00
Patrick 1fc4284af6 Fixes for Travis. 2018-02-07 13:24:36 +01:00
Patrick ea113e8c0b Fixes a bug where a missing DocBlock caused errors 2018-02-07 13:17:03 +01:00
+37 -7
View File
@@ -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);
} }