24Slides /
laravel-saml2
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Slides\Saml2\Commands; |
||||||
| 4 | |||||||
| 5 | /** |
||||||
| 6 | * Trait ValidatesInput |
||||||
| 7 | * |
||||||
| 8 | * @package Slides\Saml2\Commands |
||||||
| 9 | */ |
||||||
| 10 | trait ValidatesInput |
||||||
| 11 | { |
||||||
| 12 | /** |
||||||
| 13 | * Resolve the nameIdFormat. |
||||||
| 14 | * |
||||||
| 15 | * @param string $option |
||||||
| 16 | * |
||||||
| 17 | * @return string|null |
||||||
| 18 | */ |
||||||
| 19 | protected function resolveNameIdFormat(string $option = 'nameIdFormat') |
||||||
| 20 | { |
||||||
| 21 | $value = $this->option($option) ?: 'persistent'; |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 22 | |||||||
| 23 | if ($this->validateNameIdFormat($value)) { |
||||||
| 24 | return $value; |
||||||
| 25 | } |
||||||
| 26 | |||||||
| 27 | $this->error('Name ID format is invalid. Supported values: ' . implode(', ', $this->supportedNameIdFormats())); |
||||||
|
0 ignored issues
–
show
It seems like
error() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 28 | |||||||
| 29 | return null; |
||||||
| 30 | } |
||||||
| 31 | |||||||
| 32 | /** |
||||||
| 33 | * Validate Name ID format. |
||||||
| 34 | * |
||||||
| 35 | * @param string $format |
||||||
| 36 | * |
||||||
| 37 | * @return bool |
||||||
| 38 | */ |
||||||
| 39 | protected function validateNameIdFormat(string $format): bool |
||||||
| 40 | { |
||||||
| 41 | return in_array($format, $this->supportedNameIdFormats()); |
||||||
| 42 | } |
||||||
| 43 | |||||||
| 44 | /** |
||||||
| 45 | * The list of supported Name ID formats. |
||||||
| 46 | * |
||||||
| 47 | * See https://docs.oracle.com/cd/E19316-01/820-3886/6nfcvtepi/index.html |
||||||
| 48 | * |
||||||
| 49 | * @return string[]|array |
||||||
| 50 | */ |
||||||
| 51 | protected function supportedNameIdFormats(): array |
||||||
| 52 | { |
||||||
| 53 | return [ |
||||||
| 54 | 'persistent', |
||||||
| 55 | 'transient', |
||||||
| 56 | 'emailAddress', |
||||||
| 57 | 'unspecified', |
||||||
| 58 | 'X509SubjectName', |
||||||
| 59 | 'WindowsDomainQualifiedName', |
||||||
| 60 | 'kerberos', |
||||||
| 61 | 'entity' |
||||||
| 62 | ]; |
||||||
| 63 | } |
||||||
| 64 | } |