Skip to content

Commit a9f66c3

Browse files
committed
refactor: throw directly ResourceAlreadyExistsException instead of ClassAlreadyExistsException
1 parent bb6fa6b commit a9f66c3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Exceptions/ResourceAlreadyExistsException.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,24 @@ class ResourceAlreadyExistsException extends Exception
1010
public function __construct(
1111
protected string $filePath,
1212
) {
13+
$entity = $this->getEntity();
14+
15+
$filePath = $this->getFilePath();
16+
17+
parent::__construct("Cannot create {$entity} cause it already exists. Remove {$filePath} and run command again.");
18+
}
19+
20+
protected function getEntity(): string
21+
{
1322
$entity = Str::afterLast($this->filePath, '/');
14-
$entity = Str::before($entity, '.php');
1523

16-
parent::__construct("Cannot create {$entity} cause it already exists. Remove {$this->filePath} and run command again.");
24+
return Str::before($entity, '.php');
25+
}
26+
27+
protected function getFilePath(): string
28+
{
29+
$filePath = realpath($this->filePath);
30+
31+
return empty($filePath) ? $this->filePath : "{$filePath}:1";
1732
}
1833
}

tests/TestGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RonasIT\Support\Events\WarningEvent;
88
use RonasIT\Support\Exceptions\CircularRelationsFoundedException;
99
use RonasIT\Support\Exceptions\ClassNotExistsException;
10+
use RonasIT\Support\Exceptions\ResourceAlreadyExistsException;
1011
use RonasIT\Support\Generators\TestsGenerator;
1112
use RonasIT\Support\Tests\Support\Test\TestMockTrait;
1213

0 commit comments

Comments
 (0)