22
33namespace DragonCode \LaravelRoutesCore \Models ;
44
5- use DragonCode \LaravelRoutesCore \ Traits \Makeable ;
6- use Illuminate \Support \Str ;
5+ use DragonCode \Support \ Concerns \Makeable ;
6+ use DragonCode \Support \ Facades \ Helpers \Str ;
77use phpDocumentor \Reflection \DocBlock ;
88use phpDocumentor \Reflection \DocBlockFactory ;
99use ReflectionClass ;
10- use ReflectionException ;
1110use ReflectionMethod ;
1211use Reflector ;
1312
1413class Reader
1514{
1615 use Makeable;
1716
18- protected $ controller ;
19-
20- protected $ method ;
21-
22- public function __construct (string $ controller , ?string $ method = null )
23- {
24- $ this ->controller = $ controller ;
25- $ this ->method = $ method ;
17+ public function __construct (
18+ protected string $ controller ,
19+ protected ?string $ method = null
20+ ) {
2621 }
2722
28- /**
29- * @throws ReflectionException
30- *
31- * @return \phpDocumentor\Reflection\DocBlock|null
32- */
33- public function forClass ()
23+ public function forClass (): ?DocBlock
3424 {
3525 [$ controller , $ method ] = $ this ->parse ();
3626
@@ -39,12 +29,7 @@ public function forClass()
3929 );
4030 }
4131
42- /**
43- * @throws ReflectionException
44- *
45- * @return \phpDocumentor\Reflection\DocBlock|null
46- */
47- public function forMethod ()
32+ public function forMethod (): ?DocBlock
4833 {
4934 [$ controller , $ method ] = $ this ->parse ();
5035
@@ -54,11 +39,6 @@ public function forMethod()
5439 ) : null ;
5540 }
5641
57- /**
58- * @param Reflector|null $reflection
59- *
60- * @return \phpDocumentor\Reflection\DocBlock|null
61- */
6242 protected function get (?Reflector $ reflection = null ): ?DocBlock
6343 {
6444 if ($ reflection && $ comment = $ reflection ->getDocComment ()) {
@@ -71,42 +51,23 @@ protected function get(?Reflector $reflection = null): ?DocBlock
7151 protected function parse (): array
7252 {
7353 if (is_null ($ this ->method )) {
74- return Str::contains ($ this ->controller , '@ ' )
75- ? [Str::before ($ this ->controller , '@ ' ), Str::after ($ this ->controller , '@ ' )]
76- : [$ this ->controller , null ];
54+ if (Str::contains ($ this ->controller , '@ ' )) {
55+ return [Str::before ($ this ->controller , '@ ' ), Str::after ($ this ->controller , '@ ' )];
56+ }
57+
58+ return [$ this ->controller , null ];
7759 }
7860
7961 return [$ this ->controller , $ this ->method ];
8062 }
8163
82- /**
83- * Getting class reflection instance.
84- *
85- * @param string $class
86- *
87- * @throws ReflectionException
88- *
89- * @return ReflectionClass
90- */
91- protected function reflectionClass (string $ class )
64+ protected function reflectionClass (string $ class ): ReflectionClass
9265 {
9366 return new ReflectionClass ($ class );
9467 }
9568
96- /**
97- * Getting method reflection instance from reflection class.
98- *
99- * @param ReflectionClass $class
100- * @param string $method
101- *
102- * @throws ReflectionException
103- *
104- * @return ReflectionMethod|null
105- */
106- protected function reflectionMethod (ReflectionClass $ class , string $ method )
69+ protected function reflectionMethod (ReflectionClass $ class , string $ method ): ?ReflectionMethod
10770 {
108- return $ class ->hasMethod ($ method )
109- ? $ class ->getMethod ($ method )
110- : null ;
71+ return $ class ->hasMethod ($ method ) ? $ class ->getMethod ($ method ) : null ;
11172 }
11273}
0 commit comments