Skip to content

Commit

Permalink
Merge pull request #28 from ThibaudDauce/fix-class-without-namespace
Browse files Browse the repository at this point in the history
Classes without namespace break the ModelFinder
  • Loading branch information
mpociot authored Jul 21, 2018
2 parents 33b734a + 4d47c6e commit dea29dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ModelFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ protected function getFullyQualifiedClassNameFromFile(string $path): string
return $statement instanceof Namespace_;
})->first();

if (! $root_statement) {
return '';
}

return collect($root_statement->stmts)
->filter(function ($statement) {
return $statement instanceof Class_;
Expand All @@ -66,5 +70,4 @@ protected function getFullyQualifiedClassNameFromFile(string $path): string
})
->first() ?? '';
}

}
6 changes: 6 additions & 0 deletions tests/Models/SomeClassWithoutNamespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

class SomeClassWithoutNamespace
{

}

0 comments on commit dea29dd

Please sign in to comment.