Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Add generic types #524

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Authenticator/LoginHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ public function finishRegistration(HTTPRequest $request): HTTPResponse
}

// If we've completed registration and the member is not already logged in then we need to log them in
/** @var EnforcementManager $enforcementManager */
$enforcementManager = EnforcementManager::create();
$mustLogin = $request->getSession()->get(static::SESSION_KEY . '.mustLogin');

Expand Down Expand Up @@ -457,7 +456,6 @@ public function redirectAfterSuccessfulLogin(): HTTPResponse
}

$request = $this->getRequest();
/** @var EnforcementManager $enforcementManager */
$enforcementManager = EnforcementManager::create();

// Assert that the member has a valid registration.
Expand All @@ -469,7 +467,6 @@ public function redirectAfterSuccessfulLogin(): HTTPResponse
&& !$enforcementManager->hasCompletedRegistration($member)
) {
// Log them out again
/** @var IdentityStore $identityStore */
$identityStore = Injector::inst()->get(IdentityStore::class);
$identityStore->logOut($request);

Expand Down
2 changes: 0 additions & 2 deletions src/BackupCode/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public function start(StoreInterface $store): array
// Create or update the RegisteredMethod on the member. This breaks the normal flow as it's created on "start"
// instead of after receiving a response from the user

/** @var MethodInterface $method */
$method = Injector::inst()->get(Method::class);

/** @var BackupCodeGeneratorInterface $generator */
$generator = Injector::inst()->get(BackupCodeGeneratorInterface::class);
$codes = $generator->generate();

Expand Down
2 changes: 1 addition & 1 deletion src/Extension/AccountReset/MFAResetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* resets the 'MFA Skipped' flag on the member so that they are prompted to
* set up MFA again when they next log in.
*
* @package SilverStripe\MFA\Extension\AccountReset
* @extends Extension<SecurityExtension>
*/
class MFAResetExtension extends Extension
{
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/AccountReset/MemberExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
/**
* Provides DB columns / methods for account resets on Members
*
* @package SilverStripe\MFA\Extension
* @property Member&MemberExtension $owner
* @property string $AccountResetHash
* @property DBDatetime $AccountResetExpired
*
* @extends DataExtension<Member&static>
*/
class MemberExtension extends DataExtension
{
Expand Down
4 changes: 1 addition & 3 deletions src/Extension/AccountReset/SecurityAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
* This extension is applied to SecurityAdmin to provide an additional endpoint
* for sending account reset requests.
*
* @package SilverStripe\MFA\Extension
* @property SecurityAdmin $owner
* @extends Extension<SecurityAdmin>
*/
class SecurityAdminExtension extends Extension
{
Expand Down Expand Up @@ -84,7 +83,6 @@ public function reset(HTTPRequest $request): HTTPResponse
);
}

/** @var Member $memberToReset */
$memberToReset = Member::get()->byID($request->param('ID'));

if ($memberToReset === null) {
Expand Down
3 changes: 1 addition & 2 deletions src/Extension/AccountReset/SecurityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* itself be extended to add procedures to the reset action (such as removing
* additional authentication factors, sending alerts, etc.)
*
* @package SilverStripe\MFA\Extension
* @property Security $owner
* @extends Extension<Security>
*/
class SecurityExtension extends Extension
{
Expand Down
3 changes: 2 additions & 1 deletion src/Extension/MemberExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* @property MethodInterface $DefaultRegisteredMethod
* @property string $DefaultRegisteredMethodID
* @property bool $HasSkippedMFARegistration
* @property Member|MemberExtension $owner
* @method HasManyList<RegisteredMethod> RegisteredMFAMethods()
*
* @extends DataExtension<Member&static>
*/
class MemberExtension extends DataExtension implements PermissionProvider
{
Expand Down
3 changes: 3 additions & 0 deletions src/Extension/RequirementsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use SilverStripe\Core\Extension;
use SilverStripe\MFA\RequestHandler\BaseHandlerTrait;

/**
* @extends Extension<LeftAndMain>
*/
class RequirementsExtension extends Extension
{
use BaseHandlerTrait;
Expand Down
3 changes: 3 additions & 0 deletions src/Extension/SiteConfigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
use SilverStripe\Forms\OptionsetField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\View\Requirements;

/**
* Adds multi-factor authentication related settings to the SiteConfig "Access" tab
*
* @property bool $MFARequired
* @property string $MFAGracePeriodExpires
*
* @extends DataExtension<SiteConfig>
*/
class SiteConfigExtension extends DataExtension
{
Expand Down
1 change: 0 additions & 1 deletion src/FormField/RegisteredMFAMethodListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function getSchemaDataDefaults()
if (!$this->value && $this->getForm() && $this->getForm()->getRecord() instanceof Member) {
$member = $this->getForm()->getRecord();
} else {
/** @var Member $member */
$member = DataObject::get_by_id(Member::class, $this->value);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Report/EnabledMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EnabledMembers extends Report
* Cached registered methods fetched for the current list of members. This should only be populated at render time
* as methods will be fetched for the current "records" on the report
*
* @var DataList|null
* @var ArrayList<RegisteredMethod>|null
*/
private $registeredMethods = null;

Expand All @@ -49,7 +49,7 @@ public function description(): string
* Supplies the list displayed in the report
*
* @param array $params
* @return DataList
* @return DataList<Member>
*/
public function sourceRecords($params): DataList
{
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function getMethodClassToTitleMapping(): array
}

/**
* @return ArrayList
* @return ArrayList<RegisteredMethod>
*/
protected function getRegisteredMethodsForRecords(): ArrayList
{
Expand Down
1 change: 0 additions & 1 deletion src/Service/RegisteredMethodManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public function deleteFromMember(Member $member, MethodInterface $method): bool
$remainingMethods = $member->RegisteredMFAMethods()->count();
if ($remainingMethods === 2) {
// If there is only one other method (other than backup codes) then set that as the default method
/** @var RegisteredMethod|null $remainingMethodExceptBackup */
$remainingMethodExceptBackup = $member->RegisteredMFAMethods()
->filter('MethodClassName:Not', $backupMethod)
->first();
Expand Down