66use CodeIgniter \Shield \Authentication \Authentication ;
77use CodeIgniter \Shield \Authentication \AuthenticationException ;
88use CodeIgniter \Shield \Authentication \AuthenticatorInterface ;
9- use CodeIgniter \Shield \Interfaces \Authenticatable ;
10- use CodeIgniter \Shield \Interfaces \UserProvider ;
11-
9+ use CodeIgniter \Shield \Entities \User ;
10+ use CodeIgniter \Shield \Models \UserModel ;
11+
12+ /**
13+ * AuthenticatorInterface:
14+ *
15+ * @method Result attempt(array $credentials)
16+ * @method Result check(array $credentials)
17+ * @method User|null getUser()
18+ * @method bool loggedIn()
19+ * @method bool login(User $user)
20+ * @method void loginById($userId)
21+ * @method bool logout()
22+ * @method void recordActive()
23+ *
24+ * Authenticators\Session:
25+ * @method $this remember(bool $shouldRemember = true)
26+ */
1227class Auth
1328{
1429 protected Authentication $ authenticate ;
@@ -18,8 +33,8 @@ class Auth
1833 */
1934 protected ?string $ alias = null ;
2035
21- protected ?Authenticatable $ user = null ;
22- protected ?UserProvider $ userProvider = null ;
36+ protected ?User $ user = null ;
37+ protected ?UserModel $ userProvider = null ;
2338
2439 public function __construct (Authentication $ authenticate )
2540 {
@@ -28,8 +43,10 @@ public function __construct(Authentication $authenticate)
2843
2944 /**
3045 * Sets the Authenticator alias that should be used for this request.
46+ *
47+ * @return $this
3148 */
32- public function setAuthenticator (?string $ alias = null )
49+ public function setAuthenticator (?string $ alias = null ): self
3350 {
3451 if (! empty ($ alias )) {
3552 $ this ->alias = $ alias ;
@@ -40,21 +57,17 @@ public function setAuthenticator(?string $alias = null)
4057
4158 /**
4259 * Returns the current authentication class.
43- *
44- * @return AuthenticatorInterface
4560 */
46- public function getAuthenticator ()
61+ public function getAuthenticator (): AuthenticatorInterface
4762 {
4863 return $ this ->authenticate
4964 ->factory ($ this ->alias );
5065 }
5166
5267 /**
5368 * Returns the current user, if logged in.
54- *
55- * @return Authenticatable|null
5669 */
57- public function user ()
70+ public function user (): ? User
5871 {
5972 return $ this ->getAuthenticator ()->loggedIn ()
6073 ? $ this ->getAuthenticator ()->getUser ()
@@ -64,7 +77,7 @@ public function user()
6477 /**
6578 * Returns the current user's id, if logged in.
6679 *
67- * @return mixed |null
80+ * @return int|string |null
6881 */
6982 public function id ()
7083 {
@@ -73,7 +86,7 @@ public function id()
7386 : null ;
7487 }
7588
76- public function authenticate (array $ credentials )
89+ public function authenticate (array $ credentials ): Result
7790 {
7891 $ response = $ this ->authenticate
7992 ->factory ($ this ->alias )
@@ -94,11 +107,11 @@ public function authenticate(array $credentials)
94107 * - auth()->routes($routes);
95108 * - auth()->routes($routes, ['except' => ['login', 'register']])
96109 */
97- public function routes (RouteCollection &$ routes , array $ config = [])
110+ public function routes (RouteCollection &$ routes , array $ config = []): void
98111 {
99112 $ authRoutes = config ('AuthRoutes ' )->routes ;
100113
101- $ routes ->group ('/ ' , ['namespace ' => 'CodeIgniter\Shield\Controllers ' ], static function ($ routes ) use ($ authRoutes , $ config ) {
114+ $ routes ->group ('/ ' , ['namespace ' => 'CodeIgniter\Shield\Controllers ' ], static function (RouteCollection $ routes ) use ($ authRoutes , $ config ) {
102115 foreach ($ authRoutes as $ name => $ row ) {
103116 if (! isset ($ config ['except ' ]) || (isset ($ config ['except ' ]) && ! in_array ($ name , $ config ['except ' ], true ))) {
104117 foreach ($ row as $ params ) {
@@ -116,10 +129,8 @@ public function routes(RouteCollection &$routes, array $config = [])
116129 * Returns the Model that is responsible for getting users.
117130 *
118131 * @throws AuthenticationException
119- *
120- * @return mixed|UserProvider
121132 */
122- public function getProvider ()
133+ public function getProvider (): UserModel
123134 {
124135 if ($ this ->userProvider !== null ) {
125136 return $ this ->userProvider ;
@@ -143,12 +154,11 @@ public function getProvider()
143154 * own, additional, features on top of the required ones,
144155 * like "remember-me" functionality.
145156 *
146- * @param string $method
147- * @param array $args
157+ * @param string[] $args
148158 *
149159 * @throws AuthenticationException
150160 */
151- public function __call ($ method , $ args )
161+ public function __call (string $ method , array $ args )
152162 {
153163 $ authenticate = $ this ->authenticate ->factory ($ this ->alias );
154164
0 commit comments