From ea113e8c0bd915aad961dc9999fdce7f58e486bf Mon Sep 17 00:00:00 2001 From: Patrick <943484+iPaat@users.noreply.github.com> Date: Wed, 7 Feb 2018 13:17:03 +0100 Subject: [PATCH 1/2] Fixes a bug where a missing DocBlock caused errors --- src/Eloquent.php | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Eloquent.php b/src/Eloquent.php index c27b1c1..9e5e2bc 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -32,27 +32,57 @@ 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'); - foreach ($mixins as $m) { - if ($m->getContent() === '\Eloquent') { - $command->info('Tag Exists: @mixin \Eloquent in ' . $class); + $expectedMixins = [ + '\Eloquent' => false, + '\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 - $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc)); + $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; + } $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); @@ -61,7 +91,7 @@ class Eloquent $contents = str_replace($originalDoc, $docComment, $contents, $count); if ($count > 0) { if ($files->put($filename, $contents)) { - $command->info('Wrote @mixin \Eloquent to ' . $filename); + $command->info('Wrote expected docblock to ' . $filename); } else { $command->error('File write failed to ' . $filename); } From 1fc4284af6dec64e978e61c3117036d008836c23 Mon Sep 17 00:00:00 2001 From: Patrick <943484+iPaat@users.noreply.github.com> Date: Wed, 7 Feb 2018 13:24:36 +0100 Subject: [PATCH 2/2] Fixes for Travis. --- src/Eloquent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Eloquent.php b/src/Eloquent.php index 9e5e2bc..d84435d 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -48,7 +48,7 @@ class Eloquent foreach ($mixins as $m) { $mixin = $m->getContent(); - if(isset($expectedMixins[$mixin])) { + if (isset($expectedMixins[$mixin])) { $command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class); $expectedMixins[$mixin] = true; @@ -56,8 +56,8 @@ class Eloquent } $changed = false; - foreach($expectedMixins as $expectedMixin => $present) { - if($present === false) { + foreach ($expectedMixins as $expectedMixin => $present) { + if ($present === false) { $phpdoc->appendTag(Tag::createInstance('@mixin ' . $expectedMixin, $phpdoc)); $changed = true; @@ -65,7 +65,7 @@ class Eloquent } // If nothing's changed, stop here. - if(!$changed) { + if (!$changed) { return; }