From 2d56afce8e6dc9b495f092fa3029f8d75f8f05d6 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 8 Feb 2018 17:00:48 +0100 Subject: [PATCH] Revert "Fixes a bug where a missing DocBlock caused errors" --- src/Eloquent.php | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/Eloquent.php b/src/Eloquent.php index d84435d..c27b1c1 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -32,57 +32,27 @@ class Eloquent $reflection = new \ReflectionClass($class); $namespace = $reflection->getNamespaceName(); $originalDoc = $reflection->getDocComment(); - if (!$originalDoc) { $command->info('Unexpected no document on ' . $class); } $phpdoc = new DocBlock($reflection, new Context($namespace)); $mixins = $phpdoc->getTagsByName('mixin'); - $expectedMixins = [ - '\Eloquent' => false, - '\Illuminate\Database\Eloquent\Builder' => false, - '\Illuminate\Database\Query\Builder' => false, - ]; - 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; + return; } } - $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; - } + // add the Eloquent mixin + $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc)); $serializer = new DocBlockSerializer(); $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(); if ($filename) { $contents = $files->get($filename); @@ -91,7 +61,7 @@ class Eloquent $contents = str_replace($originalDoc, $docComment, $contents, $count); if ($count > 0) { if ($files->put($filename, $contents)) { - $command->info('Wrote expected docblock to ' . $filename); + $command->info('Wrote @mixin \Eloquent to ' . $filename); } else { $command->error('File write failed to ' . $filename); }