Skip to content

Commit d5ae6a0

Browse files
committed
Fix deprecations
1 parent f58852e commit d5ae6a0

78 files changed

Lines changed: 297 additions & 663 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/SimpleSAML/Error/ErrorCodes.php

Lines changed: 41 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use SimpleSAML\Locale\Translate;
88

9-
use function array_key_exists;
109
use function array_merge;
10+
use function strval;
1111

1212
/**
1313
* Class that maps SimpleSAMLphp error codes to translateable strings.
@@ -16,55 +16,50 @@
1616
*/
1717
class ErrorCodes
1818
{
19-
// TODO PHPv8.1 - Consider moving to final consts for these default error codes to prevent overrides.
20-
public const ACSPARAMS = 'ACSPARAMS';
21-
public const ARSPARAMS = 'ARSPARAMS';
22-
public const AUTHSOURCEERROR = 'AUTHSOURCEERROR';
23-
public const BADREQUEST = 'BADREQUEST';
24-
public const CASERROR = 'CASERROR';
25-
public const CONFIG = 'CONFIG';
26-
public const CREATEREQUEST = 'CREATEREQUEST';
27-
public const DISCOPARAMS = 'DISCOPARAMS';
28-
public const GENERATEAUTHNRESPONSE = 'GENERATEAUTHNRESPONSE';
29-
public const INVALIDCERT = 'INVALIDCERT';
30-
public const LDAPERROR = 'LDAPERROR';
31-
public const LOGOUTINFOLOST = 'LOGOUTINFOLOST';
32-
public const LOGOUTREQUEST = 'LOGOUTREQUEST';
33-
public const MEMCACHEDOWN = 'MEMCACHEDOWN';
34-
public const METADATA = 'METADATA';
35-
public const METADATANOTFOUND = 'METADATANOTFOUND';
36-
public const NOACCESS = 'NOACCESS';
37-
public const NOCERT = 'NOCERT';
38-
public const NORELAYSTATE = 'NORELAYSTATE';
39-
public const NOSTATE = 'NOSTATE';
40-
public const NOTFOUND = 'NOTFOUND';
41-
public const NOTFOUNDREASON = 'NOTFOUNDREASON';
42-
public const NOTSET = 'NOTSET';
43-
public const NOTVALIDCERT = 'NOTVALIDCERT';
44-
public const PROCESSASSERTION = 'PROCESSASSERTION';
45-
public const PROCESSAUTHNREQUEST = 'PROCESSAUTHNREQUEST';
46-
public const RESPONSESTATUSNOSUCCESS = 'RESPONSESTATUSNOSUCCESS';
47-
public const SLOSERVICEPARAMS = 'SLOSERVICEPARAMS';
48-
public const SSOPARAMS = 'SSOPARAMS';
49-
public const UNHANDLEDEXCEPTION = 'UNHANDLEDEXCEPTION';
50-
public const UNKNOWNCERT = 'UNKNOWNCERT';
51-
public const USERABORTED = 'USERABORTED';
52-
public const WRONGUSERPASS = 'WRONGUSERPASS';
19+
final public const ACSPARAMS = 'ACSPARAMS';
20+
final public const ARSPARAMS = 'ARSPARAMS';
21+
final public const AUTHSOURCEERROR = 'AUTHSOURCEERROR';
22+
final public const BADREQUEST = 'BADREQUEST';
23+
final public const CASERROR = 'CASERROR';
24+
final public const CONFIG = 'CONFIG';
25+
final public const CREATEREQUEST = 'CREATEREQUEST';
26+
final public const DISCOPARAMS = 'DISCOPARAMS';
27+
final public const GENERATEAUTHNRESPONSE = 'GENERATEAUTHNRESPONSE';
28+
final public const INVALIDCERT = 'INVALIDCERT';
29+
final public const LDAPERROR = 'LDAPERROR';
30+
final public const LOGOUTINFOLOST = 'LOGOUTINFOLOST';
31+
final public const LOGOUTREQUEST = 'LOGOUTREQUEST';
32+
final public const MEMCACHEDOWN = 'MEMCACHEDOWN';
33+
final public const METADATA = 'METADATA';
34+
final public const METADATANOTFOUND = 'METADATANOTFOUND';
35+
final public const NOACCESS = 'NOACCESS';
36+
final public const NOCERT = 'NOCERT';
37+
final public const NORELAYSTATE = 'NORELAYSTATE';
38+
final public const NOSTATE = 'NOSTATE';
39+
final public const NOTFOUND = 'NOTFOUND';
40+
final public const NOTFOUNDREASON = 'NOTFOUNDREASON';
41+
final public const NOTSET = 'NOTSET';
42+
final public const NOTVALIDCERT = 'NOTVALIDCERT';
43+
final public const PROCESSASSERTION = 'PROCESSASSERTION';
44+
final public const PROCESSAUTHNREQUEST = 'PROCESSAUTHNREQUEST';
45+
final public const RESPONSESTATUSNOSUCCESS = 'RESPONSESTATUSNOSUCCESS';
46+
final public const SLOSERVICEPARAMS = 'SLOSERVICEPARAMS';
47+
final public const SSOPARAMS = 'SSOPARAMS';
48+
final public const UNHANDLEDEXCEPTION = 'UNHANDLEDEXCEPTION';
49+
final public const UNKNOWNCERT = 'UNKNOWNCERT';
50+
final public const USERABORTED = 'USERABORTED';
51+
final public const WRONGUSERPASS = 'WRONGUSERPASS';
5352

54-
public const KEY_TITLE = 'title';
55-
public const KEY_DESCRIPTION = 'descr';
53+
final public const KEY_TITLE = 'title';
54+
final public const KEY_DESCRIPTION = 'descr';
5655

5756

5857
/**
5958
* Fetch all default translation strings for error code titles.
6059
*
6160
* @return array A map from error code to error code title
62-
*
63-
* @deprecated Static method access is deprecated. Move to instance method.
64-
* @see self::getDefaultTitles()
65-
* TODO NextMajorRelease Move content to substitute method and remove.
6661
*/
67-
final public static function defaultGetAllErrorCodeTitles(): array
62+
final public function getDefaultTitles(): array
6863
{
6964
return [
7065
self::ACSPARAMS => Translate::noop('No SAML response provided'),
@@ -103,32 +98,6 @@ final public static function defaultGetAllErrorCodeTitles(): array
10398
];
10499
}
105100

106-
/**
107-
* Fetch all default translation strings for error code titles.
108-
*
109-
* @return array A map from error code to error code title
110-
*/
111-
final public function getDefaultTitles(): array
112-
{
113-
// TODO NextMajorRelease Move content from self::defaultGetAllErrorCodeTitles() to this method.
114-
return self::defaultGetAllErrorCodeTitles();
115-
}
116-
117-
/**
118-
* Fetch all title translation strings for custom error codes.
119-
*
120-
* Extend this to define custom error codes and their title translations.
121-
*
122-
* @return array A map from custom error code to error code title
123-
*
124-
* @deprecated Static method access is deprecated. Move to instance method.
125-
* @see self::getCustomTitles()
126-
* TODO NextMajorRelease Remove this method.
127-
*/
128-
public static function getCustomErrorCodeTitles(): array
129-
{
130-
return [];
131-
}
132101

133102
/**
134103
* Fetch all title translation strings for custom error codes.
@@ -143,26 +112,12 @@ public function getCustomTitles(): array
143112
}
144113

145114

146-
/**
147-
* Fetch all translation strings for error code titles.
148-
*
149-
* @return array A map from error code to error code title
150-
*
151-
* @deprecated Static method access is deprecated. Move to instance method.
152-
* @see self::getAllTitles()
153-
* TODO NextMajorRelease Remove this method.
154-
*/
155-
public static function getAllErrorCodeTitles(): array
156-
{
157-
return array_merge(self::defaultGetAllErrorCodeTitles(), static::getCustomErrorCodeTitles());
158-
}
159-
160115
/**
161116
* Fetch all translation strings for error code titles.
162117
*
163118
* @return array A map from error code to error code title
164119
*/
165-
public function getAllTitles(): array
120+
final public function getAllTitles(): array
166121
{
167122
return array_merge($this->getDefaultTitles(), $this->getCustomTitles());
168123
}
@@ -172,12 +127,8 @@ public function getAllTitles(): array
172127
* Fetch all default translation strings for error code descriptions.
173128
*
174129
* @return array A map from error code to error code description
175-
*
176-
* @deprecated Static method access is deprecated. Move to instance method.
177-
* @see self::getDefaultDescriptions()
178-
* TODO NextMajorRelease Move content to substitute method and remove.
179130
*/
180-
final public static function defaultGetAllErrorCodeDescriptions(): array
131+
final public function getDefaultDescriptions(): array
181132
{
182133
return [
183134
self::ACSPARAMS => Translate::noop("" .
@@ -263,32 +214,6 @@ final public static function defaultGetAllErrorCodeDescriptions(): array
263214
];
264215
}
265216

266-
/**
267-
* Fetch all default translation strings for error code descriptions.
268-
*
269-
* @return array A map from error code to error code description
270-
*/
271-
final public function getDefaultDescriptions(): array
272-
{
273-
// TODO NextMajorRelease Move content from self::defaultGetAllErrorCodeDescriptions() to this method.
274-
return self::defaultGetAllErrorCodeDescriptions();
275-
}
276-
277-
/**
278-
* Fetch all description translation strings for custom error codes.
279-
*
280-
* Extend this to define custom error codes and their description translations.
281-
*
282-
* @return array A map from error code to error code description
283-
*
284-
* @deprecated Static method access is deprecated. Move to instance method.
285-
* @see self::getCustomDescriptions()
286-
* TODO NextMajorRelease Remove this method.
287-
*/
288-
public static function getCustomErrorCodeDescriptions(): array
289-
{
290-
return [];
291-
}
292217

293218
/**
294219
* Fetch all description translation strings for custom error codes.
@@ -302,44 +227,13 @@ public function getCustomDescriptions(): array
302227
return [];
303228
}
304229

305-
/**
306-
* Fetch all translation strings for error code descriptions.
307-
*
308-
* @return array A map from error code to error code description
309-
*
310-
* @deprecated Static method access is deprecated. Move to instance method.
311-
* @see self::getAllDescriptions()
312-
* TODO NextMajorRelease Remove this method.
313-
*/
314-
public static function getAllErrorCodeDescriptions(): array
315-
{
316-
return array_merge(self::defaultGetAllErrorCodeDescriptions(), static::getCustomErrorCodeDescriptions());
317-
}
318230

319231
public function getAllDescriptions(): array
320232
{
321233
return array_merge($this->getDefaultDescriptions(), $this->getCustomDescriptions());
322234
}
323235

324236

325-
/**
326-
* Get a map of both errorcode titles and descriptions
327-
*
328-
* Convenience-method for template-callers
329-
*
330-
* @return array An array containing both errorcode maps.
331-
* @deprecated Static method access is deprecated. Move to instance method.
332-
* @see self::getAllMessages()
333-
* TODO NextMajorRelease Remove this method.
334-
*/
335-
public static function getAllErrorCodeMessages(): array
336-
{
337-
return [
338-
self::KEY_TITLE => self::getAllErrorCodeTitles(),
339-
self::KEY_DESCRIPTION => self::getAllErrorCodeDescriptions(),
340-
];
341-
}
342-
343237
/**
344238
* Get a map of both errorcode titles and descriptions
345239
*
@@ -356,27 +250,6 @@ public function getAllMessages(): array
356250
}
357251

358252

359-
/**
360-
* Fetch a translation string for a title for a given error code.
361-
*
362-
* @param string $errorCode The error code to look up
363-
*
364-
* @return string A string to translate
365-
*
366-
* @deprecated Static method access is deprecated. Move to instance method.
367-
* @see self::getTitle()
368-
* TODO NextMajorRelease Remove this method.
369-
*/
370-
public static function getErrorCodeTitle(string $errorCode): string
371-
{
372-
if (array_key_exists($errorCode, self::getAllErrorCodeTitles())) {
373-
$errorCodeTitles = self::getAllErrorCodeTitles();
374-
return $errorCodeTitles[$errorCode];
375-
} else {
376-
return Translate::addTagPrefix($errorCode, 'title_');
377-
}
378-
}
379-
380253
/**
381254
* Fetch a translation string for a title for a given error code.
382255
*
@@ -386,29 +259,9 @@ public static function getErrorCodeTitle(string $errorCode): string
386259
*/
387260
public function getTitle(string $errorCode): string
388261
{
389-
return (string)($this->getAllTitles()[$errorCode] ?? Translate::addTagPrefix($errorCode, 'title_'));
262+
return strval($this->getAllTitles()[$errorCode] ?? Translate::addTagPrefix($errorCode, 'title_'));
390263
}
391264

392-
/**
393-
* Fetch a translation string for a description for a given error code.
394-
*
395-
* @param string $errorCode The error code to look up
396-
*
397-
* @return string A string to translate
398-
*
399-
* @deprecated Static method access is deprecated. Move to instance method.
400-
* @see self::getDescription()
401-
* TODO NextMajorRelease Remove this method.
402-
*/
403-
public static function getErrorCodeDescription(string $errorCode): string
404-
{
405-
if (array_key_exists($errorCode, self::getAllErrorCodeDescriptions())) {
406-
$errorCodeDescriptions = self::getAllErrorCodeDescriptions();
407-
return $errorCodeDescriptions[$errorCode];
408-
} else {
409-
return Translate::addTagPrefix($errorCode, 'descr_');
410-
}
411-
}
412265

413266
/**
414267
* Fetch a translation string for a description for a given error code.
@@ -419,29 +272,9 @@ public static function getErrorCodeDescription(string $errorCode): string
419272
*/
420273
public function getDescription(string $errorCode): string
421274
{
422-
return (string)($this->getAllDescriptions()[$errorCode] ?? Translate::addTagPrefix($errorCode, 'descr_'));
275+
return strval($this->getAllDescriptions()[$errorCode] ?? Translate::addTagPrefix($errorCode, 'descr_'));
423276
}
424277

425-
/**
426-
* Get both title and description for a specific error code
427-
*
428-
* Convenience-method for template-callers
429-
*
430-
* @param string $errorCode The error code to look up
431-
*
432-
* @return array An array containing both errorcode strings.
433-
*
434-
* @deprecated Static method access is deprecated. Move to instance method.
435-
* @see self::getMessage()
436-
* TODO NextMajorRelease Remove this method.
437-
*/
438-
public static function getErrorCodeMessage(string $errorCode): array
439-
{
440-
return [
441-
self::KEY_TITLE => self::getErrorCodeTitle($errorCode),
442-
self::KEY_DESCRIPTION => self::getErrorCodeDescription($errorCode),
443-
];
444-
}
445278

446279
/**
447280
* Get both title and description for a specific error code

tests/modules/admin/src/Controller/ConfigTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SimpleSAML\Test\Module\admin\Controller;
66

7+
use PHPUnit\Framework\Attributes\CoversClass;
78
use PHPUnit\Framework\TestCase;
89
use SimpleSAML\{Configuration, Session, Utils};
910
use SimpleSAML\Module\admin\Controller;
@@ -12,9 +13,9 @@
1213
/**
1314
* Set of tests for the controllers in the "admin" module.
1415
*
15-
* @covers \SimpleSAML\Module\admin\Controller\Config
1616
* @package SimpleSAML\Test
1717
*/
18+
#[CoversClass(Controller\Config::class)]
1819
class ConfigTest extends TestCase
1920
{
2021
/** @var \SimpleSAML\Configuration */

tests/modules/admin/src/Controller/FederationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SimpleSAML\Test\Module\admin\Controller;
66

7+
use PHPUnit\Framework\Attributes\CoversClass;
78
use PHPUnit\Framework\TestCase;
89
use SimpleSAML\{Auth, Configuration, Module, Session, Utils};
910
use SimpleSAML\Metadata\MetaDataStorageHandler;
@@ -17,9 +18,9 @@
1718
/**
1819
* Set of tests for the controllers in the "admin" module.
1920
*
20-
* @covers \SimpleSAML\Module\admin\Controller\Federation
2121
* @package SimpleSAML\Test
2222
*/
23+
#[CoversClass(Controller\Federation::class)]
2324
class FederationTest extends TestCase
2425
{
2526
/** @var string */

0 commit comments

Comments
 (0)