@@ -41,10 +41,8 @@ class GrantFactory
4141
4242 /**
4343 * Defines a grant singleton in the registry.
44- *
45- * @return self
4644 */
47- public function setGrant (string $ name , AbstractGrant $ grant )
45+ public function setGrant (string $ name , AbstractGrant $ grant ): static
4846 {
4947 $ this ->registry [$ name ] = $ grant ;
5048
@@ -55,10 +53,8 @@ public function setGrant(string $name, AbstractGrant $grant)
5553 * Returns a grant singleton by name.
5654 *
5755 * If the grant has not be registered, a default grant will be loaded.
58- *
59- * @return AbstractGrant
6056 */
61- public function getGrant (string $ name )
57+ public function getGrant (string $ name ): AbstractGrant
6258 {
6359 if (!isset ($ this ->registry [$ name ])) {
6460 $ this ->registerDefaultGrant ($ name );
@@ -70,10 +66,8 @@ public function getGrant(string $name)
7066
7167 /**
7268 * Registers a default grant singleton by name.
73- *
74- * @return self
7569 */
76- protected function registerDefaultGrant (string $ name )
70+ protected function registerDefaultGrant (string $ name ): static
7771 {
7872 // PascalCase the grant. E.g: 'authorization_code' becomes 'AuthorizationCode'
7973 $ class = str_replace (' ' , '' , ucwords (str_replace (['- ' , '_ ' ], ' ' , $ name )));
@@ -87,11 +81,9 @@ protected function registerDefaultGrant(string $name)
8781 /**
8882 * Determines if a variable is a valid grant.
8983 *
90- * @return bool
91- *
9284 * @phpstan-assert-if-true class-string<AbstractGrant> | AbstractGrant $class
9385 */
94- public function isGrant (mixed $ class )
86+ public function isGrant (mixed $ class ): bool
9587 {
9688 if (!is_string ($ class ) && !is_object ($ class )) {
9789 return false ;
@@ -103,22 +95,18 @@ public function isGrant(mixed $class)
10395 /**
10496 * Checks if a variable is a valid grant.
10597 *
106- * @return void
107- *
10898 * @throws InvalidGrantException
10999 *
110100 * @phpstan-assert class-string<AbstractGrant> | AbstractGrant $class
111101 */
112- public function checkGrant (mixed $ class )
102+ public function checkGrant (mixed $ class ): void
113103 {
114104 if (!$ this ->isGrant ($ class )) {
115- if (is_object ($ class )) {
116- $ type = $ class ::class;
117- } elseif (is_scalar ($ class )) {
118- $ type = $ class ;
119- } else {
120- $ type = gettype ($ class );
121- }
105+ $ type = match (true ) {
106+ is_object ($ class ) => $ class ::class,
107+ is_scalar ($ class ) => $ class ,
108+ default => gettype ($ class ),
109+ };
122110
123111 throw new InvalidGrantException (sprintf ('Grant "%s" must extend AbstractGrant ' , $ type ));
124112 }
0 commit comments