Skip to content

Commit 0f29431

Browse files
committed
fix: narrow catch clauses in convert methods and add docblock
- catch InvalidLtreeException instead of InvalidArgumentException. - add docblock with reference to PostgreSQL's Ltree documentation
1 parent c28ae4c commit 0f29431

File tree

1 file changed

+11
-2
lines changed
  • src/MartinGeorgiev/Doctrine/DBAL/Types

1 file changed

+11
-2
lines changed

src/MartinGeorgiev/Doctrine/DBAL/Types/Ltree.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77
use Doctrine\DBAL\Platforms\AbstractPlatform;
88
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidLtreeForDatabaseException;
99
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidLtreeForPHPException;
10+
use MartinGeorgiev\Doctrine\DBAL\Types\ValueObject\Exceptions\InvalidLtreeException;
1011
use MartinGeorgiev\Doctrine\DBAL\Types\ValueObject\Ltree as LtreeValueObject;
1112

13+
/**
14+
* Implementation of PostgreSQL LTREE data type.
15+
*
16+
* @see https://www.postgresql.org/docs/13/ltree.html
17+
* @since 3.5
18+
*
19+
* @author Pierre-Yves Landuré
20+
*/
1221
final class Ltree extends BaseType
1322
{
1423
protected const TYPE_NAME = 'ltree';
@@ -23,7 +32,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?LtreeVal
2332
if (\is_string($value)) {
2433
try {
2534
return LtreeValueObject::fromString($value);
26-
} catch (\InvalidArgumentException) {
35+
} catch (InvalidLtreeException) {
2736
throw InvalidLtreeForDatabaseException::forInvalidFormat($value);
2837
}
2938
}
@@ -41,7 +50,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
4150
if (\is_string($value)) {
4251
try {
4352
$value = LtreeValueObject::fromString($value);
44-
} catch (\InvalidArgumentException) {
53+
} catch (InvalidLtreeException) {
4554
throw InvalidLtreeForPHPException::forInvalidFormat($value);
4655
}
4756
}

0 commit comments

Comments
 (0)