Skip to content

Commit a56885e

Browse files
committed
Improve codes
1 parent 045c8ac commit a56885e

6 files changed

+35
-33
lines changed

src/Exception/InvalidTagNameException.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
*/
1010
class InvalidTagNameException extends InvalidTagException implements DocBlockExceptionInterface
1111
{
12-
final public const CODE_EMPTY = 0x01 + parent::CODE_LAST;
12+
final public const ERROR_CODE_EMPTY = 0x01 + parent::CODE_LAST;
1313

14-
final public const CODE_EMPTY_NAME = 0x02 + parent::CODE_LAST;
14+
final public const ERROR_CODE_EMPTY_NAME = 0x02 + parent::CODE_LAST;
1515

16-
final public const CODE_INVALID_PREFIX = 0x03 + parent::CODE_LAST;
16+
final public const ERROR_CODE_INVALID_PREFIX = 0x03 + parent::CODE_LAST;
1717

18-
protected const CODE_LAST = self::CODE_INVALID_PREFIX;
18+
protected const CODE_LAST = self::ERROR_CODE_INVALID_PREFIX;
1919

2020
/**
2121
* Occurs when a tag name is empty.
@@ -24,7 +24,7 @@ public static function fromEmptyTag(): self
2424
{
2525
$message = 'Can not read tag name from empty value';
2626

27-
return new self($message, self::CODE_EMPTY);
27+
return new self($message, self::ERROR_CODE_EMPTY);
2828
}
2929

3030
/**
@@ -34,7 +34,7 @@ public static function fromEmptyTagName(): self
3434
{
3535
$message = 'Tag name cannot be empty';
3636

37-
return new self($message, self::CODE_EMPTY_NAME);
37+
return new self($message, self::ERROR_CODE_EMPTY_NAME);
3838
}
3939

4040
/**
@@ -44,6 +44,6 @@ public static function fromInvalidTagPrefix(): self
4444
{
4545
$message = 'The tag name must starts with the "@" character';
4646

47-
return new self($message, self::CODE_INVALID_PREFIX);
47+
return new self($message, self::ERROR_CODE_INVALID_PREFIX);
4848
}
4949
}

src/Exception/InvalidTypeException.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
/**
88
* @psalm-consistent-constructor
9+
* @phpstan-consistent-constructor
910
*/
1011
class InvalidTypeException extends InvalidTagException implements DocBlockExceptionInterface
1112
{
12-
final public const CODE_WITHOUT_TYPE = 0x01 + parent::CODE_LAST;
13+
final public const ERROR_CODE_WITHOUT_TYPE = 0x01 + parent::CODE_LAST;
1314

14-
protected const CODE_LAST = self::CODE_WITHOUT_TYPE;
15+
protected const CODE_LAST = self::ERROR_CODE_WITHOUT_TYPE;
1516

1617
public function __construct(string $message, int $code = 0, ?\Throwable $previous = null)
1718
{
@@ -22,6 +23,6 @@ public static function fromInvalidType(\Throwable $e = null): self
2223
{
2324
$message = 'Could not parse tag type';
2425

25-
return new static($message, self::CODE_WITHOUT_TYPE, $e);
26+
return new static($message, self::ERROR_CODE_WITHOUT_TYPE, $e);
2627
}
2728
}

src/Exception/InvalidVariableNameException.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88

99
/**
1010
* @psalm-consistent-constructor
11+
* @phpstan-consistent-constructor
1112
*/
1213
class InvalidVariableNameException extends InvalidTagException implements InvalidTypedTagExceptionInterface
1314
{
14-
final public const CODE_WITH_TYPE = 0x01 + parent::CODE_LAST;
15+
final public const ERROR_CODE_WITH_TYPE = 0x01 + parent::CODE_LAST;
1516

16-
final public const CODE_WITHOUT_TYPE = 0x02 + parent::CODE_LAST;
17+
final public const ERROR_CODE_WITHOUT_TYPE = 0x02 + parent::CODE_LAST;
1718

18-
final public const CODE_EMPTY = 0x03 + parent::CODE_LAST;
19+
final public const ERROR_CODE_EMPTY = 0x03 + parent::CODE_LAST;
1920

20-
final public const CODE_EMPTY_NAME = 0x04 + parent::CODE_LAST;
21+
final public const ERROR_CODE_EMPTY_NAME = 0x04 + parent::CODE_LAST;
2122

22-
final public const CODE_INVALID_PREFIX = 0x05 + parent::CODE_LAST;
23+
final public const ERROR_CODE_INVALID_PREFIX = 0x05 + parent::CODE_LAST;
2324

24-
protected const CODE_LAST = self::CODE_INVALID_PREFIX;
25+
protected const CODE_LAST = self::ERROR_CODE_INVALID_PREFIX;
2526

2627
/**
2728
* @param int<0, max> $offset
@@ -53,7 +54,7 @@ public static function fromNonTyped(\Throwable $e = null): self
5354
{
5455
$message = 'Could not parse tag variable name, expected "<@tag> <$name> [<description>]"';
5556

56-
return new static($message, self::CODE_WITHOUT_TYPE, $e);
57+
return new static($message, self::ERROR_CODE_WITHOUT_TYPE, $e);
5758
}
5859

5960
/**
@@ -63,7 +64,7 @@ public static function fromTyped(TypeStatement $type, int $offset, \Throwable $e
6364
{
6465
$message = 'Could not parse typed tag variable name, expected "<@tag> <type> <$name> [<description>]"';
6566

66-
return new static($message, self::CODE_WITH_TYPE, $e, $type, $offset);
67+
return new static($message, self::ERROR_CODE_WITH_TYPE, $e, $type, $offset);
6768
}
6869

6970
/**
@@ -73,7 +74,7 @@ public static function fromEmptyVariable(): self
7374
{
7475
$message = 'Can not read variable name from empty value';
7576

76-
return new self($message, self::CODE_EMPTY);
77+
return new self($message, self::ERROR_CODE_EMPTY);
7778
}
7879

7980
/**
@@ -83,7 +84,7 @@ public static function fromEmptyVariableName(): self
8384
{
8485
$message = 'Variable name cannot be empty';
8586

86-
return new self($message, self::CODE_EMPTY_NAME);
87+
return new self($message, self::ERROR_CODE_EMPTY_NAME);
8788
}
8889

8990
/**
@@ -93,6 +94,6 @@ public static function fromInvalidVariablePrefix(): self
9394
{
9495
$message = 'The variable name must starts with the "$" character';
9596

96-
return new self($message, self::CODE_INVALID_PREFIX);
97+
return new self($message, self::ERROR_CODE_INVALID_PREFIX);
9798
}
9899
}

tests/Unit/Reader/TagNameReaderTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testTagStartsWithAsciiChars(string $char, int $code): void
7070

7171
if (!$allowed) {
7272
self::expectException(InvalidTagNameException::class);
73-
self::expectExceptionCode(InvalidTagNameException::CODE_EMPTY_NAME);
73+
self::expectExceptionCode(InvalidTagNameException::ERROR_CODE_EMPTY_NAME);
7474
}
7575

7676
$sequence = $this->read($tag = "@{$char}suffix");
@@ -84,31 +84,31 @@ public function testTagStartsWithAsciiChars(string $char, int $code): void
8484
public function testWithoutName(): void
8585
{
8686
self::expectException(InvalidTagNameException::class);
87-
self::expectExceptionCode(InvalidTagNameException::CODE_EMPTY_NAME);
87+
self::expectExceptionCode(InvalidTagNameException::ERROR_CODE_EMPTY_NAME);
8888

8989
$this->read('@ description');
9090
}
9191

9292
public function testWithoutNameAndDescription(): void
9393
{
9494
self::expectException(InvalidTagNameException::class);
95-
self::expectExceptionCode(InvalidTagNameException::CODE_EMPTY_NAME);
95+
self::expectExceptionCode(InvalidTagNameException::ERROR_CODE_EMPTY_NAME);
9696

9797
$this->read('@');
9898
}
9999

100100
public function testEmptyTag(): void
101101
{
102102
self::expectException(InvalidTagNameException::class);
103-
self::expectExceptionCode(InvalidTagNameException::CODE_EMPTY);
103+
self::expectExceptionCode(InvalidTagNameException::ERROR_CODE_EMPTY);
104104

105105
$this->read('');
106106
}
107107

108108
public function testWithoutTag(): void
109109
{
110110
self::expectException(InvalidTagNameException::class);
111-
self::expectExceptionCode(InvalidTagNameException::CODE_INVALID_PREFIX);
111+
self::expectExceptionCode(InvalidTagNameException::ERROR_CODE_INVALID_PREFIX);
112112

113113
$this->read('description');
114114
}

tests/Unit/Reader/TypeReaderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public function testWithDescription(): void
4343
public function testSyntaxError(): void
4444
{
4545
self::expectException(InvalidTypeException::class);
46-
self::expectExceptionCode(InvalidTypeException::CODE_WITHOUT_TYPE);
46+
self::expectExceptionCode(InvalidTypeException::ERROR_CODE_WITHOUT_TYPE);
4747

4848
$this->read(':type');
4949
}
5050

5151
public function testEmpty(): void
5252
{
5353
self::expectException(InvalidTypeException::class);
54-
self::expectExceptionCode(InvalidTypeException::CODE_WITHOUT_TYPE);
54+
self::expectExceptionCode(InvalidTypeException::ERROR_CODE_WITHOUT_TYPE);
5555

5656
$this->read('');
5757
}

tests/Unit/Reader/VariableNameReaderTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testTagStartsWithAsciiChars(string $char, int $code): void
7070

7171
if (!$allowed) {
7272
self::expectException(InvalidVariableNameException::class);
73-
self::expectExceptionCode(InvalidVariableNameException::CODE_EMPTY_NAME);
73+
self::expectExceptionCode(InvalidVariableNameException::ERROR_CODE_EMPTY_NAME);
7474
}
7575

7676
$sequence = $this->read($tag = "\${$char}suffix");
@@ -84,31 +84,31 @@ public function testTagStartsWithAsciiChars(string $char, int $code): void
8484
public function testWithoutName(): void
8585
{
8686
self::expectException(InvalidVariableNameException::class);
87-
self::expectExceptionCode(InvalidVariableNameException::CODE_EMPTY_NAME);
87+
self::expectExceptionCode(InvalidVariableNameException::ERROR_CODE_EMPTY_NAME);
8888

8989
$this->read('$ description');
9090
}
9191

9292
public function testWithoutNameAndDescription(): void
9393
{
9494
self::expectException(InvalidVariableNameException::class);
95-
self::expectExceptionCode(InvalidVariableNameException::CODE_EMPTY_NAME);
95+
self::expectExceptionCode(InvalidVariableNameException::ERROR_CODE_EMPTY_NAME);
9696

9797
$this->read('$');
9898
}
9999

100100
public function testEmptyTag(): void
101101
{
102102
self::expectException(InvalidVariableNameException::class);
103-
self::expectExceptionCode(InvalidVariableNameException::CODE_EMPTY);
103+
self::expectExceptionCode(InvalidVariableNameException::ERROR_CODE_EMPTY);
104104

105105
$this->read('');
106106
}
107107

108108
public function testWithoutTag(): void
109109
{
110110
self::expectException(InvalidVariableNameException::class);
111-
self::expectExceptionCode(InvalidVariableNameException::CODE_INVALID_PREFIX);
111+
self::expectExceptionCode(InvalidVariableNameException::ERROR_CODE_INVALID_PREFIX);
112112

113113
$this->read('description');
114114
}

0 commit comments

Comments
 (0)