diff --git a/src/ClassFileLocator.php b/src/ClassFileLocator.php index 666b4bf..b4d93fe 100644 --- a/src/ClassFileLocator.php +++ b/src/ClassFileLocator.php @@ -139,6 +139,9 @@ public function accept() } $class = (null === $namespace) ? $content : $namespace . '\\' . $content; $file->addClass($class); + if ($namespace) { + $file->addNamespace($namespace); + } $namespace = null; break; } diff --git a/src/PhpClassFile.php b/src/PhpClassFile.php index 5a95967..309d63e 100644 --- a/src/PhpClassFile.php +++ b/src/PhpClassFile.php @@ -19,7 +19,12 @@ class PhpClassFile extends SplFileInfo /** * @var array */ - protected $classes; + protected $classes = array(); + + /** + * @var array + */ + protected $namespaces = array(); /** * Get classes @@ -31,15 +36,40 @@ public function getClasses() return $this->classes; } + /** + * Get namespaces + * + * @return array + */ + public function getNamespaces() + { + return $this->namespaces; + } + /** * Add class * * @param string $class - * @return PhpClassFile + * @return self */ public function addClass($class) { $this->classes[] = $class; return $this; } + + /** + * Add namespace + * + * @param string $namespace + * @return self + */ + public function addNamespace($namespace) + { + if (in_array($namespace, $this->namespaces)) { + return $this; + } + $this->namespaces[] = $namespace; + return $this; + } } diff --git a/test/ClassFileLocatorTest.php b/test/ClassFileLocatorTest.php index d895ccd..02ef33f 100644 --- a/test/ClassFileLocatorTest.php +++ b/test/ClassFileLocatorTest.php @@ -83,6 +83,15 @@ public function testIterationShouldInjectNamespaceInFoundItems() $this->assertTrue($found); } + public function testIterationShouldInjectNamespacesInFileInfo() + { + $locator = new ClassFileLocator(__DIR__); + foreach ($locator as $file) { + $namespaces = $file->getNamespaces(); + $this->assertTrue(count($namespaces) > 0); + } + } + public function testIterationShouldInjectClassInFoundItems() { $locator = new ClassFileLocator(__DIR__);