diff --git a/composer.json b/composer.json index 55b527f..d3cd8de 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "minimum-stability": "stable", "require": { - "php": "^8.1" + "php": "^7.4 || ^8.0.0" }, "autoload": { "psr-4": { diff --git a/src/Reflection/ReflectionNamespace.php b/src/Reflection/ReflectionNamespace.php index cd4f272..2682794 100644 --- a/src/Reflection/ReflectionNamespace.php +++ b/src/Reflection/ReflectionNamespace.php @@ -5,7 +5,6 @@ namespace jrosset\Reflection; use FilesystemIterator; use ReflectionClass; -use ReflectionEnum; use ReflectionException; /** @@ -42,7 +41,7 @@ class ReflectionNamespace { * @param string $name The namespace name * @param string[]|string $directories The list of directories that maps the namespace */ - public function __construct (string $name, array|string $directories) { + public function __construct (string $name, $directories) { $this->name = self::normalizeNamespaceName($name); if (!is_array($directories)) { @@ -61,7 +60,7 @@ class ReflectionNamespace { * * @throws ReflectionException If the namespace can not be found with the mapping */ - public static function createFromMapping (string $name, array $mapping): static { + public static function createFromMapping (string $name, array $mapping): self { $nsReflection = new static ($name, []); //region Normalize the mapping @@ -119,7 +118,7 @@ class ReflectionNamespace { * * @throws ReflectionException If the namespace can not be found */ - public static function createFromComposerMapping (string $name, string $vendorDirectoryPath): static { + public static function createFromComposerMapping (string $name, string $vendorDirectoryPath): self { $composerDirectory = static::normalizeDirectoryPath($vendorDirectoryPath) . DIRECTORY_SEPARATOR . 'composer'; if (!file_exists($composerDirectory) || !is_dir($vendorDirectoryPath) || !is_readable($vendorDirectoryPath)) { throw new ReflectionException('Unable to find composer directory: ' . $composerDirectory); @@ -188,7 +187,7 @@ class ReflectionNamespace { * * @return static|null The parent namespace or Null if there is no parent */ - public function getParent (): ?static { + public function getParent (): ?self { if (($parentNamespaceName = $this->getParentName()) === null) { return null; } @@ -216,7 +215,7 @@ class ReflectionNamespace { * * @throws ReflectionException If the sub namespace doesn't exist */ - public function getSubNamespace (string $subNamespaceName): static { + public function getSubNamespace (string $subNamespaceName): self { $this->checkValidDirectories(); $subNamespaceDirectories = []; @@ -336,12 +335,12 @@ class ReflectionNamespace { try { $classReflection = new ReflectionClass($this->getName() . '\\' . $element); } - catch (ReflectionException) { + catch (ReflectionException $exception) { continue; } //endregion //region Check it is a class (ignore interfaces and traits) - if ($classReflection->isInterface() || $classReflection->isTrait() || $classReflection->isEnum()) { + if ($classReflection->isInterface() || $classReflection->isTrait()) { continue; } //endregion @@ -395,7 +394,7 @@ class ReflectionNamespace { try { $interfaceReflection = new ReflectionClass($this->getName() . '\\' . $element); } - catch (ReflectionException) { + catch (ReflectionException $exception) { continue; } //endregion @@ -446,7 +445,7 @@ class ReflectionNamespace { try { $traitReflection = new ReflectionClass($this->getName() . '\\' . $element); } - catch (ReflectionException) { + catch (ReflectionException $exception) { continue; } //endregion @@ -463,48 +462,6 @@ class ReflectionNamespace { return $traits; } - /** - * Get an enum of the namespace - * - * @param string $enumName The enum name - * - * @return ReflectionEnum The reflection enum - * - * @throws ReflectionException If the enum doesn't exist - */ - public function getEnum (string $enumName): ReflectionEnum { - return new ReflectionEnum($this->getName() . '\\' . $enumName); - } - /** - * Get the enums of the namespace - * - * @param bool $recursive Search also in sub namespaces - * - * @return ReflectionEnum[] The list of enums - * - * @throws ReflectionException If the namespace has no configured directories - */ - public function getEnums (bool $recursive = false): array { - $traits = []; - - //region For each valid element of the namespace - foreach ($this->getValidElements($recursive) as $element) { - //region Try to get the reflection class - try { - $enumReflection = new ReflectionEnum($this->getName() . '\\' . $element); - } - catch (ReflectionException) { - continue; - } - //endregion - - $traits[] = $enumReflection; - } - //endregion - - return $traits; - } - /** * The list of directories that maps the namespace * @@ -518,7 +475,7 @@ class ReflectionNamespace { * * @param string[] $directories The list of directories that maps the namespace */ - public function setDirectories (array $directories): static { + public function setDirectories (array $directories): self { $this->directories = array_unique(static::normalizeDirectoriesPath($directories)); return $this; } diff --git a/tests/SubTests1/Enum1.php b/tests/SubTests1/Enum1.php deleted file mode 100644 index c2dfde4..0000000 --- a/tests/SubTests1/Enum1.php +++ /dev/null @@ -1,8 +0,0 @@ -getTraits(true) as $trait) { echo "\t - " . $trait->getName() . PHP_EOL; } - -echo '===== ENUMS =====' . PHP_EOL; -foreach ($tests->getEnums(true) as $enum) { - echo "\t - " . $enum->getName() . ($enum->isBacked() ? ' (backed)' : '') . PHP_EOL; -} \ No newline at end of file