Skip to content

Commit 373bc7e

Browse files
committed
Collapse NamespaceDirectory::createFromClass() into ::fromClass().
1 parent cc027e1 commit 373bc7e

4 files changed

Lines changed: 5 additions & 40 deletions

File tree

src/ClassFilesIA/ClassFilesIA.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function psr4Up(string $directory, string $namespace, int $nLevels
4242
* @return \Ock\ClassFilesIterator\NamespaceDirectory
4343
*/
4444
public static function psr4FromClass(string $class, int $nLevelsUp = 0): NamespaceDirectory {
45-
$result = NamespaceDirectory::createFromClass($class);
45+
$result = NamespaceDirectory::fromClass($class);
4646
if ($nLevelsUp !== 0) {
4747
$result = $result->requireParentN($nLevelsUp);
4848
}

src/ClassFilesIA/ClassFilesIA_Psr4.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function create(string $directory, string $namespace): self {
3636
* @return \Ock\ClassFilesIterator\ClassFilesIA\ClassFilesIAInterface
3737
*/
3838
public static function createFromClass(string $class, int $nLevelsUp = 0): ClassFilesIAInterface {
39-
$nsDir = NamespaceDirectory::createFromClass($class)
39+
$nsDir = NamespaceDirectory::fromClass($class)
4040
->requireParentN($nLevelsUp);
4141
return self::createFromNsdirObject($nsDir);
4242
}

src/NamespaceDirectory.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,12 @@ public static function create(string $directory, string $namespace): self {
4242
* Creates a namespace directory based on a known class name.
4343
*
4444
* @param class-string $class
45-
*
46-
* @return self
47-
*/
48-
public static function fromClass(string $class): self {
49-
try {
50-
return self::createFromClass($class);
51-
}
52-
catch (\ReflectionException $e) {
53-
throw new \RuntimeException($e->getMessage(), 0, $e);
54-
}
55-
}
56-
57-
/**
58-
* Creates a namespace directory based on a class name.
59-
*
60-
* @param class-string $class
6145
* A class in the namespace directory.
6246
*
6347
* @return self
64-
* Namespace directory of this very class file.
48+
* Namespace directory which contains the given class.
6549
*/
66-
public static function createFromClass(string $class): self {
50+
public static function fromClass(string $class): self {
6751
try {
6852
$reflClass = new \ReflectionClass($class);
6953
}

tests/src/NamespaceDirectoryTest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,7 @@ public function testFromClass(): void {
5050
// Does not work with built-in class.
5151
$this->callAndAssertException(
5252
\InvalidArgumentException::class,
53-
fn() => NamespaceDirectory::fromClass(\stdClass::class),
54-
);
55-
}
56-
57-
public function testCreateFromClass(): void {
58-
$this->assertNamespaceDir(
59-
__DIR__,
60-
__NAMESPACE__,
61-
NamespaceDirectory::createFromClass(self::class),
62-
);
63-
// Does not work with non-existing class.
64-
$this->callAndAssertException(
65-
\RuntimeException::class,
66-
// @phpstan-ignore argument.type
67-
fn () => NamespaceDirectory::createFromClass(__NAMESPACE__ . '\\NonExistingClass'),
68-
);
69-
// Does not work with built-in class.
70-
$this->callAndAssertException(
71-
\InvalidArgumentException::class,
72-
fn () => NamespaceDirectory::createFromClass(\stdClass::class),
53+
fn () => NamespaceDirectory::fromClass(\stdClass::class),
7354
);
7455
}
7556

0 commit comments

Comments
 (0)