diff --git a/src/Foundation/Support/PathHelper.php b/src/Foundation/Support/PathHelper.php index d41f312a..16abe711 100644 --- a/src/Foundation/Support/PathHelper.php +++ b/src/Foundation/Support/PathHelper.php @@ -8,11 +8,6 @@ { private const CONTAINERS_DIRECTORY_NAME = 'Containers'; - public static function getSharedDirectoryPath(): string - { - return app_path(self::getSharedDirectoryName()); - } - public static function getAppDirectoryPath(): string { return app_path(); @@ -23,9 +18,9 @@ public static function getAppDirectoryName(): string return 'app'; } - public static function getSharedDirectoryName(): string + public static function getSectionDirectoryPath(): string { - return 'Ship'; + return app_path(self::getContainersDirectoryName()); } public static function getContainersDirectoryName(): string @@ -33,11 +28,6 @@ public static function getContainersDirectoryName(): string return 'Containers'; } - public static function getSectionDirectoryPath(): string - { - return app_path(self::getContainersDirectoryName()); - } - public static function getShipFolderNames(): array { $names = []; @@ -54,6 +44,16 @@ public static function getShipSubDirectories(): array return File::directories(self::getSharedDirectoryPath()); } + public static function getSharedDirectoryPath(): string + { + return app_path(self::getSharedDirectoryName()); + } + + public static function getSharedDirectoryName(): string + { + return 'Ship'; + } + public static function getSectionContainerNames(string $sectionName): array { $names = []; @@ -69,81 +69,6 @@ private static function getSectionPath(string $sectionName): string return app_path(self::CONTAINERS_DIRECTORY_NAME . DIRECTORY_SEPARATOR . $sectionName); } - /** - * Get the full name (name \ namespace) of a class from its file path - * result example: (string) "I\Am\The\Namespace\Of\This\Class". - */ - public static function getFQCNFromFile(string $filePathName): string - { - return self::getClassNamespaceFromFile($filePathName) . '\\' . self::getClassNameFromFile($filePathName); - } - - // reference: https://stackoverflow.com/questions/7153000/get-class-name-from-file - protected static function getClassNamespaceFromFile(string $filePathName): string|null - { - $src = file_get_contents($filePathName); - - $tokens = token_get_all($src); - $count = count($tokens); - $i = 0; - $namespace = ''; - $isValidNameSpace = false; - while ($i < $count) { - $token = $tokens[$i]; - if (is_array($token) && T_NAMESPACE === $token[0]) { - // Found namespace declaration - while (++$i < $count) { - if (';' === $tokens[$i]) { - $isValidNameSpace = true; - $namespace = trim($namespace); - - break; - } - $namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i]; - } - - break; - } - ++$i; - } - if (!$isValidNameSpace) { - return null; - } - - return $namespace; - } - - protected static function getClassNameFromFile(string $filePathName): mixed - { - $phpCode = file_get_contents($filePathName); - - $classes = []; - $tokens = token_get_all($phpCode); - $count = count($tokens); - for ($i = 2; $i < $count; ++$i) { - if (T_CLASS == $tokens[$i - 2][0] - && T_WHITESPACE == $tokens[$i - 1][0] - && T_STRING == $tokens[$i][0] - ) { - $className = $tokens[$i][1]; - $classes[] = $className; - } - } - - return $classes[0]; - } - - /** - * Get the last part of a camel case string. - * Example input = helloDearWorld | returns = World. - */ - public static function getClassType(string $className): mixed - { - $array = preg_split('/(?=[A-Z])/', $className); - - return end($array); - } - public static function getContainerNames(): array { $names = []; diff --git a/tests/Support/Doubles/Dummies/UselessClass.php b/tests/Support/Doubles/Dummies/UselessClass.php deleted file mode 100644 index 9b128518..00000000 --- a/tests/Support/Doubles/Dummies/UselessClass.php +++ /dev/null @@ -1,7 +0,0 @@ -assertEquals(['container1', 'container2'], $result); } - public function testGetClassFullNameFromFileReturnsCorrectFullName(): void - { - $filePath = realpath(__DIR__ . '/../../../Support/Doubles/Dummies/UselessClass.php'); - File::shouldReceive('get') - ->with($filePath) - ->andReturn(); - - $result = PathHelper::getFQCNFromFile($filePath); - - $this->assertEquals(UselessClass::class, $result); - } - - public function testGetClassTypeReturnsCorrectType(): void - { - $result = PathHelper::getClassType('HelloDearWorld'); - - $this->assertEquals('World', $result); - } - public function testGetAllContainerNamesReturnsCorrectNames(): void { File::shouldReceive('directories')