Skip to content

Commit 621f363

Browse files
committed
feat: move errors handling to Reflection class
1 parent f062b9b commit 621f363

File tree

7 files changed

+24
-146
lines changed

7 files changed

+24
-146
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,6 @@ parameters:
360360
count: 1
361361
path: src/Parser/Node/DocBlockNode.php
362362

363-
-
364-
message: "#^Property Doctum\\\\Parser\\\\Node\\\\DocBlockNode\\:\\:\\$errors has no typehint specified\\.$#"
365-
count: 1
366-
path: src/Parser/Node/DocBlockNode.php
367-
368363
-
369364
message: "#^Method Doctum\\\\Parser\\\\Node\\\\DocBlockNode\\:\\:addTag\\(\\) has no return typehint specified\\.$#"
370365
count: 1
@@ -435,21 +430,6 @@ parameters:
435430
count: 1
436431
path: src/Parser/Node/DocBlockNode.php
437432

438-
-
439-
message: "#^Method Doctum\\\\Parser\\\\Node\\\\DocBlockNode\\:\\:addError\\(\\) has no return typehint specified\\.$#"
440-
count: 1
441-
path: src/Parser/Node/DocBlockNode.php
442-
443-
-
444-
message: "#^Method Doctum\\\\Parser\\\\Node\\\\DocBlockNode\\:\\:addError\\(\\) has parameter \\$error with no typehint specified\\.$#"
445-
count: 1
446-
path: src/Parser/Node/DocBlockNode.php
447-
448-
-
449-
message: "#^Method Doctum\\\\Parser\\\\Node\\\\DocBlockNode\\:\\:getErrors\\(\\) has no return typehint specified\\.$#"
450-
count: 1
451-
path: src/Parser/Node/DocBlockNode.php
452-
453433
-
454434
message: "#^Property Doctum\\\\Parser\\\\NodeVisitor\\:\\:\\$context has no typehint specified\\.$#"
455435
count: 1
@@ -1050,11 +1030,6 @@ parameters:
10501030
count: 1
10511031
path: src/Reflection/ClassReflection.php
10521032

1053-
-
1054-
message: "#^Property Doctum\\\\Reflection\\\\ClassReflection\\:\\:\\$errors has no typehint specified\\.$#"
1055-
count: 1
1056-
path: src/Reflection/ClassReflection.php
1057-
10581033
-
10591034
message: "#^Property Doctum\\\\Reflection\\\\ClassReflection\\:\\:\\$fromCache has no typehint specified\\.$#"
10601035
count: 1
@@ -1390,21 +1365,6 @@ parameters:
13901365
count: 1
13911366
path: src/Reflection/ClassReflection.php
13921367

1393-
-
1394-
message: "#^Method Doctum\\\\Reflection\\\\ClassReflection\\:\\:getErrors\\(\\) has no return typehint specified\\.$#"
1395-
count: 1
1396-
path: src/Reflection/ClassReflection.php
1397-
1398-
-
1399-
message: "#^Method Doctum\\\\Reflection\\\\ClassReflection\\:\\:setErrors\\(\\) has no return typehint specified\\.$#"
1400-
count: 1
1401-
path: src/Reflection/ClassReflection.php
1402-
1403-
-
1404-
message: "#^Method Doctum\\\\Reflection\\\\ClassReflection\\:\\:setErrors\\(\\) has parameter \\$errors with no typehint specified\\.$#"
1405-
count: 1
1406-
path: src/Reflection/ClassReflection.php
1407-
14081368
-
14091369
message: "#^Method Doctum\\\\Reflection\\\\ClassReflection\\:\\:isFromCache\\(\\) has no return typehint specified\\.$#"
14101370
count: 1
@@ -1505,11 +1465,6 @@ parameters:
15051465
count: 1
15061466
path: src/Reflection/FunctionReflection.php
15071467

1508-
-
1509-
message: "#^Property Doctum\\\\Reflection\\\\FunctionReflection\\:\\:\\$errors has no typehint specified\\.$#"
1510-
count: 1
1511-
path: src/Reflection/FunctionReflection.php
1512-
15131468
-
15141469
message: "#^Method Doctum\\\\Reflection\\\\FunctionReflection\\:\\:setByRef\\(\\) has no return typehint specified\\.$#"
15151470
count: 1
@@ -1610,21 +1565,6 @@ parameters:
16101565
count: 1
16111566
path: src/Reflection/FunctionReflection.php
16121567

1613-
-
1614-
message: "#^Method Doctum\\\\Reflection\\\\FunctionReflection\\:\\:getErrors\\(\\) has no return typehint specified\\.$#"
1615-
count: 1
1616-
path: src/Reflection/FunctionReflection.php
1617-
1618-
-
1619-
message: "#^Method Doctum\\\\Reflection\\\\FunctionReflection\\:\\:setErrors\\(\\) has no return typehint specified\\.$#"
1620-
count: 1
1621-
path: src/Reflection/FunctionReflection.php
1622-
1623-
-
1624-
message: "#^Method Doctum\\\\Reflection\\\\FunctionReflection\\:\\:setErrors\\(\\) has parameter \\$errors with no typehint specified\\.$#"
1625-
count: 1
1626-
path: src/Reflection/FunctionReflection.php
1627-
16281568
-
16291569
message: "#^Method Doctum\\\\Reflection\\\\FunctionReflection\\:\\:setRelativeFilePath\\(\\) has no return typehint specified\\.$#"
16301570
count: 1
@@ -1970,11 +1910,6 @@ parameters:
19701910
count: 1
19711911
path: src/Reflection/MethodReflection.php
19721912

1973-
-
1974-
message: "#^Property Doctum\\\\Reflection\\\\MethodReflection\\:\\:\\$errors has no typehint specified\\.$#"
1975-
count: 1
1976-
path: src/Reflection/MethodReflection.php
1977-
19781913
-
19791914
message: "#^Method Doctum\\\\Reflection\\\\MethodReflection\\:\\:setByRef\\(\\) has no return typehint specified\\.$#"
19801915
count: 1
@@ -2090,21 +2025,6 @@ parameters:
20902025
count: 1
20912026
path: src/Reflection/MethodReflection.php
20922027

2093-
-
2094-
message: "#^Method Doctum\\\\Reflection\\\\MethodReflection\\:\\:getErrors\\(\\) has no return typehint specified\\.$#"
2095-
count: 1
2096-
path: src/Reflection/MethodReflection.php
2097-
2098-
-
2099-
message: "#^Method Doctum\\\\Reflection\\\\MethodReflection\\:\\:setErrors\\(\\) has no return typehint specified\\.$#"
2100-
count: 1
2101-
path: src/Reflection/MethodReflection.php
2102-
2103-
-
2104-
message: "#^Method Doctum\\\\Reflection\\\\MethodReflection\\:\\:setErrors\\(\\) has parameter \\$errors with no typehint specified\\.$#"
2105-
count: 1
2106-
path: src/Reflection/MethodReflection.php
2107-
21082028
-
21092029
message: "#^Method Doctum\\\\Reflection\\\\MethodReflection\\:\\:getSourcePath\\(\\) has no return typehint specified\\.$#"
21102030
count: 1
@@ -2270,11 +2190,6 @@ parameters:
22702190
count: 1
22712191
path: src/Reflection/PropertyReflection.php
22722192

2273-
-
2274-
message: "#^Property Doctum\\\\Reflection\\\\PropertyReflection\\:\\:\\$errors has no typehint specified\\.$#"
2275-
count: 1
2276-
path: src/Reflection/PropertyReflection.php
2277-
22782193
-
22792194
message: "#^Method Doctum\\\\Reflection\\\\PropertyReflection\\:\\:setModifiers\\(\\) has no return typehint specified\\.$#"
22802195
count: 1
@@ -2335,21 +2250,6 @@ parameters:
23352250
count: 1
23362251
path: src/Reflection/PropertyReflection.php
23372252

2338-
-
2339-
message: "#^Method Doctum\\\\Reflection\\\\PropertyReflection\\:\\:getErrors\\(\\) has no return typehint specified\\.$#"
2340-
count: 1
2341-
path: src/Reflection/PropertyReflection.php
2342-
2343-
-
2344-
message: "#^Method Doctum\\\\Reflection\\\\PropertyReflection\\:\\:setErrors\\(\\) has no return typehint specified\\.$#"
2345-
count: 1
2346-
path: src/Reflection/PropertyReflection.php
2347-
2348-
-
2349-
message: "#^Method Doctum\\\\Reflection\\\\PropertyReflection\\:\\:setErrors\\(\\) has parameter \\$errors with no typehint specified\\.$#"
2350-
count: 1
2351-
path: src/Reflection/PropertyReflection.php
2352-
23532253
-
23542254
message: "#^Method Doctum\\\\Reflection\\\\PropertyReflection\\:\\:toArray\\(\\) has no return typehint specified\\.$#"
23552255
count: 1

src/Parser/Node/DocBlockNode.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class DocBlockNode
1616
protected $shortDesc;
1717
protected $longDesc;
1818
protected $tags = [];
19+
/** @var string[] */
1920
protected $errors = [];
2021

2122
public function addTag($key, $value)
@@ -78,12 +79,15 @@ public function getDesc()
7879
return $this->shortDesc . "\n\n" . $this->longDesc;
7980
}
8081

81-
public function addError($error)
82+
public function addError(string $error): void
8283
{
8384
$this->errors[] = $error;
8485
}
8586

86-
public function getErrors()
87+
/**
88+
* @return string[]
89+
*/
90+
public function getErrors(): array
8791
{
8892
return $this->errors;
8993
}

src/Reflection/ClassReflection.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ class ClassReflection extends Reflection
209209
protected $category = self::CATEGORY_CLASS;
210210
protected $projectClass = true;
211211
protected $aliases = [];
212-
protected $errors = [];
213212
protected $fromCache = false;
214213

215214
public function __toString()
@@ -597,16 +596,6 @@ public function setAliases($aliases)
597596
$this->aliases = $aliases;
598597
}
599598

600-
public function getErrors()
601-
{
602-
return $this->errors;
603-
}
604-
605-
public function setErrors($errors)
606-
{
607-
$this->errors = $errors;
608-
}
609-
610599
public function isFromCache()
611600
{
612601
return $this->fromCache;

src/Reflection/FunctionReflection.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class FunctionReflection extends Reflection
2020
protected $project;
2121
protected $relativeFilePath;
2222
protected $exceptions = [];
23-
protected $errors = [];
2423

2524
public function __toString()
2625
{
@@ -139,16 +138,6 @@ public function getRawExceptions()
139138
return $this->exceptions;
140139
}
141140

142-
public function getErrors()
143-
{
144-
return $this->errors;
145-
}
146-
147-
public function setErrors($errors)
148-
{
149-
$this->errors = $errors;
150-
}
151-
152141
public function setRelativeFilePath($relativeFilePath)
153142
{
154143
$this->relativeFilePath = $relativeFilePath;

src/Reflection/MethodReflection.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class MethodReflection extends Reflection
2020
protected $byRef;
2121
protected $modifiers;
2222
protected $exceptions = [];
23-
protected $errors = [];
2423

2524
public function __toString()
2625
{
@@ -138,16 +137,6 @@ public function getRawExceptions()
138137
return $this->exceptions;
139138
}
140139

141-
public function getErrors()
142-
{
143-
return $this->errors;
144-
}
145-
146-
public function setErrors($errors)
147-
{
148-
$this->errors = $errors;
149-
}
150-
151140
public function getSourcePath()
152141
{
153142
return $this->class->getSourcePath($this->line);

src/Reflection/PropertyReflection.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class PropertyReflection extends Reflection
1818
protected $class;
1919
protected $modifiers;
2020
protected $default;
21-
protected $errors = [];
2221

2322
public function __toString()
2423
{
@@ -80,16 +79,6 @@ public function setClass(ClassReflection $class)
8079
$this->class = $class;
8180
}
8281

83-
public function getErrors()
84-
{
85-
return $this->errors;
86-
}
87-
88-
public function setErrors($errors)
89-
{
90-
$this->errors = $errors;
91-
}
92-
9382
public function toArray()
9483
{
9584
return [

src/Reflection/Reflection.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ abstract class Reflection
3333
protected $tags;
3434
protected $docComment;
3535
protected $see = [];
36+
/** @var string[] */
37+
protected $errors = [];
3638

3739
public function __construct(string $name, $line)
3840
{
@@ -209,4 +211,20 @@ private function prepareMethodSee(array $seeElem)
209211

210212
return $seeElem;
211213
}
214+
215+
/**
216+
* @return string[]
217+
*/
218+
public function getErrors(): array
219+
{
220+
return $this->errors;
221+
}
222+
223+
/**
224+
* @param string[] $errors
225+
*/
226+
public function setErrors(array $errors): void
227+
{
228+
$this->errors = $errors;
229+
}
212230
}

0 commit comments

Comments
 (0)