Skip to content

Commit 8175195

Browse files
committed
Update login policy interface
1 parent 7e74524 commit 8175195

File tree

4 files changed

+46
-197
lines changed

4 files changed

+46
-197
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
],
1717
"require": {
1818
"php": ">=7.3",
19+
"ext-json": "*",
1920
"ext-mbstring": "*",
2021
"activecollab/cookies": "^2.0",
2122
"activecollab/user": "^4.0",
2223
"google/apiclient": "^2.1",
2324
"psr/http-server-middleware": "^1.0"
2425
},
2526
"require-dev": {
26-
"ext-json": "*",
2727
"friendsofphp/php-cs-fixer": "^2.0",
2828
"lightsaml/lightsaml": "^1.1",
2929
"phpunit/phpunit": "^7.0",

composer.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LoginPolicy/LoginPolicy.php

+21-79
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
* (c) A51 doo <[email protected]>. All rights reserved.
77
*/
88

9+
declare(strict_types=1);
10+
911
namespace ActiveCollab\Authentication\LoginPolicy;
1012

1113
use InvalidArgumentException;
1214

13-
/**
14-
* @package ActiveCollab\Authentication\LoginPolicy
15-
*/
1615
class LoginPolicy implements LoginPolicyInterface
1716
{
1817
/**
@@ -81,18 +80,12 @@ public function __construct($username_format = self::USERNAME_FORMAT_TEXT, $reme
8180
$this->setExternalUpdateProfileUrl($external_update_profile_url);
8281
}
8382

84-
/**
85-
* {@inheritdoc}
86-
*/
87-
public function getUsernameFormat()
83+
public function getUsernameFormat(): string
8884
{
8985
return $this->username_format;
9086
}
9187

92-
/**
93-
* {@inheritdoc}
94-
*/
95-
public function setUsernameFormat($value)
88+
public function setUsernameFormat(string $value): LoginPolicyInterface
9689
{
9790
if (in_array($value, self::VALID_USERNAME_FORMATS)) {
9891
$this->username_format = $value;
@@ -103,139 +96,91 @@ public function setUsernameFormat($value)
10396
return $this;
10497
}
10598

106-
/**
107-
* {@inheritdoc}
108-
*/
109-
public function rememberExtendsSession()
99+
public function rememberExtendsSession(): bool
110100
{
111101
return $this->remember_extends_session;
112102
}
113103

114-
/**
115-
* {@inheritdoc}
116-
*/
117-
public function setRememberExtendsSession($value)
104+
public function setRememberExtendsSession(bool $value): LoginPolicyInterface
118105
{
119-
$this->remember_extends_session = (bool) $value;
106+
$this->remember_extends_session = $value;
120107

121108
return $this;
122109
}
123110

124-
/**
125-
* {@inheritdoc}
126-
*/
127-
public function isPasswordChangeEnabled()
111+
public function isPasswordChangeEnabled(): bool
128112
{
129113
return $this->password_change_enabled;
130114
}
131115

132-
/**
133-
* {@inheritdoc}
134-
*/
135-
public function setIsPasswordChangeEnabled($value)
116+
public function setIsPasswordChangeEnabled(bool $value): LoginPolicyInterface
136117
{
137-
$this->password_change_enabled = (bool) $value;
118+
$this->password_change_enabled = $value;
138119

139120
return $this;
140121
}
141122

142-
/**
143-
* {@inheritdoc}
144-
*/
145-
public function isPasswordRecoveryEnabled()
123+
public function isPasswordRecoveryEnabled(): bool
146124
{
147125
return $this->password_recovery_enabled;
148126
}
149127

150-
/**
151-
* {@inheritdoc}
152-
*/
153-
public function setIsPasswordRecoveryEnabled($value)
128+
public function setIsPasswordRecoveryEnabled(bool $value): LoginPolicyInterface
154129
{
155130
$this->password_recovery_enabled = (bool) $value;
156131

157132
return $this;
158133
}
159134

160-
/**
161-
* {@inheritdoc}
162-
*/
163-
public function getExternalLoginUrl()
135+
public function getExternalLoginUrl(): ?string
164136
{
165137
return $this->external_login_url;
166138
}
167139

168-
/**
169-
* {@inheritdoc}
170-
*/
171-
public function setExternalLoginUrl($value)
140+
public function setExternalLoginUrl(?string $value): LoginPolicyInterface
172141
{
173142
$this->external_login_url = $this->getValidExternalUrlValue($value);
174143

175144
return $this;
176145
}
177146

178-
/**
179-
* {@inheritdoc}
180-
*/
181-
public function getExternalLogoutUrl()
147+
public function getExternalLogoutUrl(): ?string
182148
{
183149
return $this->external_logout_url;
184150
}
185151

186-
/**
187-
* {@inheritdoc}
188-
*/
189-
public function setExternalLogoutUrl($value)
152+
public function setExternalLogoutUrl(?string $value): LoginPolicyInterface
190153
{
191154
$this->external_logout_url = $this->getValidExternalUrlValue($value);
192155

193156
return $this;
194157
}
195158

196-
/**
197-
* {@inheritdoc}
198-
*/
199-
public function getExternalChangePasswordUrl()
159+
public function getExternalChangePasswordUrl(): ?string
200160
{
201161
return $this->external_change_password_url;
202162
}
203163

204-
/**
205-
* {@inheritdoc}
206-
*/
207-
public function setExternalChangePasswordUrl($value)
164+
public function setExternalChangePasswordUrl(?string $value): LoginPolicyInterface
208165
{
209166
$this->external_change_password_url = $this->getValidExternalUrlValue($value);
210167

211168
return $this;
212169
}
213170

214-
/**
215-
* {@inheritdoc}
216-
*/
217-
public function getExternalUpdateProfileUrl()
171+
public function getExternalUpdateProfileUrl(): ?string
218172
{
219173
return $this->external_update_profile_url;
220174
}
221175

222-
/**
223-
* {@inheritdoc}
224-
*/
225-
public function setExternalUpdateProfileUrl($value)
176+
public function setExternalUpdateProfileUrl(?string $value): LoginPolicyInterface
226177
{
227178
$this->external_update_profile_url = $this->getValidExternalUrlValue($value);
228179

229180
return $this;
230181
}
231182

232-
/**
233-
* Validate and return acceptable URL value.
234-
*
235-
* @param string|null $url
236-
* @return string|null
237-
*/
238-
private function getValidExternalUrlValue($url)
183+
private function getValidExternalUrlValue(?string $url): ?string
239184
{
240185
if ($url === null || (is_string($url) && filter_var($url, FILTER_VALIDATE_URL))) {
241186
return $url;
@@ -244,9 +189,6 @@ private function getValidExternalUrlValue($url)
244189
throw new InvalidArgumentException('URL is not valid');
245190
}
246191

247-
/**
248-
* {@inheritdoc}
249-
*/
250192
public function jsonSerialize()
251193
{
252194
return [

src/LoginPolicy/LoginPolicyInterface.php

+22-116
Original file line numberDiff line numberDiff line change
@@ -6,137 +6,43 @@
66
* (c) A51 doo <[email protected]>. All rights reserved.
77
*/
88

9+
declare(strict_types=1);
10+
911
namespace ActiveCollab\Authentication\LoginPolicy;
1012

1113
use JsonSerializable;
1214

13-
/**
14-
* @package ActiveCollab\Authentication\LoginPolicy
15-
*/
1615
interface LoginPolicyInterface extends JsonSerializable
1716
{
1817
const USERNAME_FORMAT_TEXT = 'text';
1918
const USERNAME_FORMAT_EMAIL = 'email';
2019

21-
const VALID_USERNAME_FORMATS = [self::USERNAME_FORMAT_TEXT, self::USERNAME_FORMAT_EMAIL];
22-
23-
/**
24-
* Return username format.
25-
*
26-
* @return string
27-
*/
28-
public function getUsernameFormat();
29-
30-
/**
31-
* Set username format.
32-
*
33-
* @param string $value
34-
* @return $this
35-
*/
36-
public function setUsernameFormat($value);
37-
38-
/**
39-
* Enable Remember Me feature to support extended sessions.
40-
*
41-
* @return bool
42-
*/
43-
public function rememberExtendsSession();
44-
45-
/**
46-
* Set value of Remember Me flag.
47-
*
48-
* @param bool $value
49-
* @return $this
50-
*/
51-
public function setRememberExtendsSession($value);
52-
53-
/**
54-
* Password change is supported by this authentication adapter.
55-
*
56-
* @return bool
57-
*/
58-
public function isPasswordChangeEnabled();
59-
60-
/**
61-
* Set value of is password enabled flag.
62-
*
63-
* @param bool $value
64-
* @return $this
65-
*/
66-
public function setIsPasswordChangeEnabled($value);
67-
68-
/**
69-
* Return true if this authentication adapter supports password recovery.
70-
*
71-
* @return bool
72-
*/
73-
public function isPasswordRecoveryEnabled();
74-
75-
/**
76-
* Set value of is password recovery enabled flag.
77-
*
78-
* @param bool $value
79-
* @return $this
80-
*/
81-
public function setIsPasswordRecoveryEnabled($value);
20+
const VALID_USERNAME_FORMATS = [
21+
self::USERNAME_FORMAT_TEXT,
22+
self::USERNAME_FORMAT_EMAIL,
23+
];
8224

83-
/**
84-
* Get login URL.
85-
*
86-
* @return string|null
87-
*/
88-
public function getExternalLoginUrl();
25+
public function getUsernameFormat(): string;
26+
public function setUsernameFormat(string $value): LoginPolicyInterface;
8927

90-
/**
91-
* Set external login URL.
92-
*
93-
* @param string $value
94-
* @return $this
95-
*/
96-
public function setExternalLoginUrl($value);
28+
public function rememberExtendsSession(): bool;
29+
public function setRememberExtendsSession(bool $value): LoginPolicyInterface;
9730

98-
/**
99-
* Get logout URL.
100-
*
101-
* @return string
102-
*/
103-
public function getExternalLogoutUrl();
31+
public function isPasswordChangeEnabled(): bool;
32+
public function setIsPasswordChangeEnabled(bool $value): LoginPolicyInterface;
10433

105-
/**
106-
* Set external log out URL.
107-
*
108-
* @param string $value
109-
* @return $this
110-
*/
111-
public function setExternalLogoutUrl($value);
34+
public function isPasswordRecoveryEnabled(): bool;
35+
public function setIsPasswordRecoveryEnabled(bool $value): LoginPolicyInterface;
11236

113-
/**
114-
* Get change password URL.
115-
*
116-
* @return string|null
117-
*/
118-
public function getExternalChangePasswordUrl();
37+
public function getExternalLoginUrl(): ?string;
38+
public function setExternalLoginUrl(?string $value): LoginPolicyInterface;
11939

120-
/**
121-
* Set external change password URL.
122-
*
123-
* @param string $value
124-
* @return $this
125-
*/
126-
public function setExternalChangePasswordUrl($value);
40+
public function getExternalLogoutUrl(): ?string;
41+
public function setExternalLogoutUrl(?string $value): LoginPolicyInterface;
12742

128-
/**
129-
* Get update profile URL.
130-
*
131-
* @return string|null
132-
*/
133-
public function getExternalUpdateProfileUrl();
43+
public function getExternalChangePasswordUrl(): ?string;
44+
public function setExternalChangePasswordUrl(?string $value): LoginPolicyInterface;
13445

135-
/**
136-
* Set external update profile URL.
137-
*
138-
* @param string $value
139-
* @return $this
140-
*/
141-
public function setExternalUpdateProfileUrl($value);
46+
public function getExternalUpdateProfileUrl(): ?string;
47+
public function setExternalUpdateProfileUrl(?string $value): LoginPolicyInterface;
14248
}

0 commit comments

Comments
 (0)