Skip to content

Commit

Permalink
Merge pull request #225 from silinternational/feature/ssp-2-typehint
Browse files Browse the repository at this point in the history
add correct types for classes inherited from SimpleSAMLphp
  • Loading branch information
briskt authored Jun 18, 2024
2 parents 77bb8f2 + 4e045f0 commit ca8c0de
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 68 deletions.
6 changes: 2 additions & 4 deletions modules/expirychecker/src/Auth/Process/ExpiryDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,9 @@ public function redirect2PasswordChange(
}

/**
* Apply this AuthProc Filter.
*
* @param array &$state The current state.
* @inheritDoc
*/
public function process(&$state): void
public function process(array &$state): void
{
$employeeId = $this->getAttribute($this->employeeIdAttr, $state);

Expand Down
10 changes: 3 additions & 7 deletions modules/mfa/src/Auth/Process/Mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,11 @@ public static function redirectToMfaSetup(array &$state): void

HTTP::redirectTrustedURL($mfaSetupUrl);
}

/**
* Apply this AuthProc Filter. It will either return (indicating that it
* has completed) or it will redirect the user, in which case it will
* later call `SimpleSAML\Auth\ProcessingChain::resumeProcessing($state)`.
*
* @param array &$state The current state.
* @inheritDoc
*/
public function process(&$state): void
public function process(array &$state): void
{
// Get the necessary info from the state data.
$employeeId = $this->getAttribute($this->employeeIdAttr, $state);
Expand Down
8 changes: 2 additions & 6 deletions modules/profilereview/src/Auth/Process/ProfileReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,9 @@ public static function redirectToProfile(&$state)
}

/**
* Apply this AuthProc Filter. It will either return (indicating that it
* has completed) or it will redirect the user, in which case it will
* later call `SimpleSAML\Auth\ProcessingChain::resumeProcessing($state)`.
*
* @param array &$state The current state.
* @inheritDoc
*/
public function process(&$state)
public function process(array &$state): void
{
// Get the necessary info from the state data.
$employeeId = $this->getAttribute($this->employeeIdAttr, $state);
Expand Down
14 changes: 3 additions & 11 deletions modules/silauth/src/Auth/Source/SilAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ public function __construct(array $info, array $config)
]]]);
}

/**
* Initialize login.
*
* This function saves the information about the login, and redirects to a
* login page.
*
* @param array &$state Information about the current authentication.
*/
public function authenticate(&$state): void
public function authenticate(array &$state): void
{
assert('is_array($state)');

Expand Down Expand Up @@ -107,8 +99,8 @@ protected function getTrustedIpAddresses(): array
}
return $trustedIpAddresses;
}
protected function login($username, $password): ?array

protected function login(string $username, string $password): array
{
$logger = new Psr3StdOutLogger();
$captcha = new Captcha($this->recaptchaConfig['secret'] ?? null);
Expand Down
2 changes: 1 addition & 1 deletion modules/silauth/src/Auth/Source/auth/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static function getSecondsUntilUnblocked(
* </pre>
* @throws \Exception
*/
public function getUserAttributes(): ?array
public function getUserAttributes(): array
{
if ($this->userAttributes === null) {
throw new \Exception(
Expand Down
19 changes: 8 additions & 11 deletions modules/silauth/src/Auth/Source/tests/unit/csrf/FakeSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,32 @@

namespace SimpleSAML\Module\silauth\Auth\Source\tests\unit\csrf;

use SimpleSAML\Session;

/**
* Class to mimic the bare basics of the SimpleSAML\Session class in order to
* allow good testing of the CsrfProtector class.
*/
class FakeSession extends \SimpleSAML\Session
class FakeSession extends Session
{
private $inMemoryDataStore;
private array $inMemoryDataStore;

private function __construct($transient = false)
private function __construct(bool $transient = false)
{
$this->inMemoryDataStore = [];
}

/**
* @param string $type
* @param string|null $id
* @return mixed
*/
public function getData($type, $id)
public function getData(string $type, ?string $id): mixed
{
return $this->inMemoryDataStore[$type][$id] ?? null;
}

public static function getSessionFromRequest($sessionId = null)
public static function getSessionFromRequest(): Session
{
return new self();
}

public function setData($type, $id, $data, $timeout = null)
public function setData(string $type, string $id, mixed $data, int|string|null $timeout = null): void
{
// Make sure an array exists for that type of data.
$this->inMemoryDataStore[$type] = $this->inMemoryDataStore[$type] ?? [];
Expand Down
6 changes: 2 additions & 4 deletions modules/sildisco/src/Auth/Process/AddIdp2NameId.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ public function appendIdp(NameID $nameId, string $IDPNamespace): void


/**
* Apply filter to copy attributes.
*
* @param array &$state The current state array
* @inheritDoc
*/
public function process(&$state): void
public function process(array &$state): void
{
assert('is_array($state)');

Expand Down
4 changes: 2 additions & 2 deletions modules/sildisco/src/Auth/Process/LogUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function __construct(array $config, mixed $reserved)
/**
* Log info for a user's login to Dynamodb
*
* @param array &$state The current state array
* @inheritDoc
*/
public function process(&$state): void
public function process(array &$state): void
{
if (! $this->configsAreValid()) {
return;
Expand Down
5 changes: 3 additions & 2 deletions modules/sildisco/src/Auth/Process/TagGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public function prependIdp2Groups(array $attributes, string $attributeLabel, str
/**
* Apply filter to copy attributes.
*
* @param array &$state The current request
* @inheritDoc
*/
public function process(&$state) {
public function process(array &$state): void
{
assert('is_array($request)');
assert('array_key_exists("Attributes", $request)');

Expand Down
5 changes: 3 additions & 2 deletions modules/sildisco/src/Auth/Process/TrackIdps.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class TrackIdps extends \SimpleSAML\Auth\ProcessingFilter {
/**
* Apply filter to save IDPs to session.
*
* @param array &$request The current request
* @inheritDoc
*/
public function process(&$request) {
public function process(array &$state): void
{
// get the authenticating Idp and add it to the list of previous ones
$session = \SimpleSAML\Session::getSessionFromRequest();
$sessionDataType = "sildisco:authentication";
Expand Down
23 changes: 5 additions & 18 deletions modules/sildisco/src/IdPDisco.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ class IdPDisco extends \SimpleSAML\XHTML\IdPDisco


/**
* Log a message.
*
* This is an helper function for logging messages. It will prefix the messages with our discovery service type.
*
* @param string $message The message which should be logged.
* @inheritDoc
*/
protected function log($message): void
protected function log(string $message): void
{
\SimpleSAML\Logger::info('SildiscoIdPDisco.'.$this->instance.': '.$message);
}
Expand Down Expand Up @@ -72,9 +68,7 @@ private function getSPEntityIDAndReducedIdpList(): array
}

/**
* Handles a request to this discovery service.
*
* The IdP disco parameters should be set before calling this function.
* @inheritDoc
*/
public function handleRequest(): void
{
Expand Down Expand Up @@ -160,16 +154,9 @@ public static function enableBetaEnabled(array $idpList, ?bool $isBetaTester=nul
}

/**
* Validates the given IdP entity id.
*
* Takes a string with the IdP entity id, and returns the entity id if it is valid, or
* null if not. Ensures that the selected IdP is allowed for the current SP
*
* @param string|null $idp The entity id we want to validate. This can be null, in which case we will return null.
*
* @return string|null The entity id if it is valid, null if not.
* @inheritDoc
*/
protected function validateIdP($idp): ?string
protected function validateIdP(?string $idp): ?string
{
if ($idp === null) {
return null;
Expand Down

0 comments on commit ca8c0de

Please sign in to comment.