diff --git a/application/symfony/src/Domain/SourceManagement/SourceClassInformationService.php b/application/symfony/src/Domain/SourceManagement/SourceClassInformationService.php new file mode 100644 index 0000000..3b38f44 --- /dev/null +++ b/application/symfony/src/Domain/SourceManagement/SourceClassInformationService.php @@ -0,0 +1,132 @@ +allClasses[] = $this->transformPathToClass($path); + } + + private function loadClasses() + { + $recursiveDirectoryIterator = new \RecursiveDirectoryIterator(self::FOLDER); + $files = new \RecursiveIteratorIterator($recursiveDirectoryIterator, \RecursiveIteratorIterator::SELF_FIRST); + foreach ($files as $file) { + $path = $file->getPathname(); + if ($this->isPHP($path) && !$this->isInterface($path)) { + $this->addToClasses($path); + } + } + } + + public function __construct() + { + $this->loadClasses(); + } + + /** + * @param string $subPath + * @param string $rootPath + * + * @return bool + */ + private function isSubSourceClass(string $subPath, string $rootPath): bool + { + return substr($rootPath, 0, strlen($subPath)) === $subPath; + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\SourceManagement\SourceClassInformationServiceInterface::getAllSourceClasses() + */ + public function getAllSourceClasses(): array + { + return $this->allClasses; + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\SourceManagement\SourceClassInformationServiceInterface::getAllSubSourceClasses() + */ + public function getAllSubSourceClasses(string $subNamespace): array + { + $subSourceClasses = []; + foreach ($this->allClasses as $class) { + if ($this->isSubSourceClass($subNamespace, $class)) { + $subSourceClasses[] = $class; + } + } + + return $subSourceClasses; + } +} diff --git a/application/symfony/src/Domain/SourceManagement/SourceClassInformationServiceInterface.php b/application/symfony/src/Domain/SourceManagement/SourceClassInformationServiceInterface.php new file mode 100644 index 0000000..33eae96 --- /dev/null +++ b/application/symfony/src/Domain/SourceManagement/SourceClassInformationServiceInterface.php @@ -0,0 +1,23 @@ +sourceClassInformationService = new SourceClassInformationService(); + } + + public function testPureSource(): void + { + $allClasses = $this->sourceClassInformationService->getAllSourceClasses(); + $this->assertTrue(in_array(PureSource::class, $allClasses)); + } + + public function testNotSource(): void + { + $allClasses = $this->sourceClassInformationService->getAllSourceClasses(); + $this->assertFalse(in_array('ALLALALABBBB', $allClasses)); + } + + public function testSubSource(): void + { + $allClasses = $this->sourceClassInformationService->getAllSubSourceClasses('App\\Entity\\Source\\Complex'); + $this->assertFalse(in_array(PureSource::class, $allClasses)); + $this->assertTrue(in_array(AbstractComplexSource::class, $allClasses)); + } +}