Skip to content

Commit

Permalink
refactor: tweak user triggers context
Browse files Browse the repository at this point in the history
  • Loading branch information
Dartui committed Sep 19, 2024
1 parent a826b32 commit 0ee54f8
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 199 deletions.
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1905,56 +1905,21 @@ parameters:
count: 1
path: src/Repository/Trigger/Taxonomy/TermTrigger.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserDeleted\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserDeleted.php

-
message: "#^Access to an undefined property object\\:\\:\\$ID\\.$#"
count: 1
path: src/Repository/Trigger/User/UserLogin.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserLogin\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserLogin.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserLogout\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserLogout.php

-
message: "#^Access to an undefined property object\\:\\:\\$ID\\.$#"
count: 1
path: src/Repository/Trigger/User/UserPasswordChanged.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserPasswordChanged\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserPasswordChanged.php

-
message: "#^Cannot access property \\$data on WP_User\\|false\\.$#"
count: 1
path: src/Repository/Trigger/User/UserPasswordResetRequest.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserProfileUpdated\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserProfileUpdated.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserRegistered\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserRegistered.php

-
message: "#^Property BracketSpace\\\\Notification\\\\Repository\\\\Trigger\\\\User\\\\UserRoleChanged\\:\\:\\$userMeta \\(array\\) does not accept mixed\\.$#"
count: 1
path: src/Repository/Trigger/User/UserRoleChanged.php

-
message: "#^Argument of an invalid type array\\|false supplied for foreach, only iterables are supported\\.$#"
count: 1
Expand Down
21 changes: 3 additions & 18 deletions src/Repository/Trigger/User/UserDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
*/
class UserDeleted extends UserTrigger
{
/**
* User meta data
*
* @var array<mixed>
*/
public $userMeta;

/**
* User deletion date and time
*
* @var int|false
*/
public $userDeletedDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -63,10 +49,6 @@ public function context($userId)
}

$this->userObject = $user;
$this->userMeta = get_user_meta($this->userId);

$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);
$this->userDeletedDatetime = time();
}

/**
Expand All @@ -89,6 +71,9 @@ public function mergeTags()
[
'slug' => 'user_deleted_datetime',
'name' => __('User deletion time', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
12 changes: 3 additions & 9 deletions src/Repository/Trigger/User/UserEmailChangeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ class UserEmailChangeRequest extends UserTrigger
*/
public $confirmationUrl;

/**
* Email change timestamp
*
* @var int
*/
public $emailChangeDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -104,12 +97,10 @@ public function context($userId)

$this->userId = $userId;
$this->userObject = $user;
$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);

// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
$this->oldUserEmail = $user->user_email;
$this->newUserEmail = $data['newemail'];
$this->emailChangeDatetime = time();
$this->siteUrl = get_site_url();
$this->confirmationUrl = esc_url(admin_url('profile.php?newuseremail=' . $data['hash']));
}
Expand Down Expand Up @@ -162,6 +153,9 @@ public function mergeTags()
'slug' => 'email_change_datetime',
'name' => __('Email change time', 'notification'),
'group' => __('Email', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
12 changes: 3 additions & 9 deletions src/Repository/Trigger/User/UserEmailChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class UserEmailChanged extends UserTrigger
*/
public $siteUrl;

/**
* Email changed timestamp
*
* @var int
*/
public $emailChangedDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -87,12 +80,10 @@ public function context($userId, $oldUser, $newData)

$this->userId = $userId;
$this->userObject = $user;
$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);

// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
$this->oldUserEmail = $oldUser->user_email;
$this->newUserEmail = is_string($newData['user_email']) ? $newData['user_email'] : '';
$this->emailChangedDatetime = time();
$this->siteUrl = get_site_url();
}

Expand Down Expand Up @@ -130,6 +121,9 @@ public function mergeTags()
'slug' => 'email_changed_datetime',
'name' => __('Email changed time', 'notification'),
'group' => __('Email', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
21 changes: 3 additions & 18 deletions src/Repository/Trigger/User/UserLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
*/
class UserLogin extends UserTrigger
{
/**
* User meta data
*
* @var array<mixed>
*/
public $userMeta;

/**
* User login date and time
*
* @var int|false
*/
public $userLoggedInDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -66,10 +52,6 @@ public function context($userLogin, $user)
}

$this->userObject = $user;
$this->userMeta = get_user_meta($this->userId);

$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);
$this->userLoggedInDatetime = time();
}

/**
Expand All @@ -92,6 +74,9 @@ public function mergeTags()
[
'slug' => 'user_logged_in_datetime',
'name' => __('User login time', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
13 changes: 3 additions & 10 deletions src/Repository/Trigger/User/UserLoginFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
*/
class UserLoginFailed extends UserTrigger
{
/**
* User login failure date and time
*
* @var int|false
*/
public $userLoginFailedDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -65,9 +58,6 @@ public function context($username)
if (!$user instanceof \WP_User) {
return false;
}

$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);
$this->userLoginFailedDatetime = time();
}

/**
Expand All @@ -90,6 +80,9 @@ public function mergeTags()
[
'slug' => 'user_login_failed_datetime',
'name' => __('User login failed datetime', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
21 changes: 3 additions & 18 deletions src/Repository/Trigger/User/UserLogout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
*/
class UserLogout extends UserTrigger
{
/**
* User meta data
*
* @var array<mixed>
*/
public $userMeta;

/**
* User logout date and time
*
* @var int|false
*/
public $userLogoutDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -68,10 +54,6 @@ public function context($userId = 0)
}

$this->userObject = $user;
$this->userMeta = get_user_meta($userId);

$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);
$this->userLogoutDatetime = time();
}

/**
Expand All @@ -94,6 +76,9 @@ public function mergeTags()
[
'slug' => 'user_logout_datetime',
'name' => __('User logout time', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
22 changes: 4 additions & 18 deletions src/Repository/Trigger/User/UserPasswordChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
*/
class UserPasswordChanged extends UserTrigger
{
/**
* User meta data
*
* @var array<mixed>
*/
public $userMeta;

/**
* Password change date and time
*
* @var int|false
*/
public $passwordChangeDatetime;

/**
* Constructor
*/
Expand Down Expand Up @@ -63,10 +49,7 @@ public function context($user)
return;
}

$this->userMeta = get_user_meta($this->userId);

$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);
$this->passwordChangeDatetime = time();
$this->userObject = $user;
}

/**
Expand All @@ -89,6 +72,9 @@ public function mergeTags()
[
'slug' => 'password_change_datetime',
'name' => __('Password change date', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
14 changes: 3 additions & 11 deletions src/Repository/Trigger/User/UserPasswordResetRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
*/
class UserPasswordResetRequest extends UserTrigger
{
/**
* Password reset request date and time
*
* @var int|false
*/
public $passwordResetRequestDatetime;

/**
* Password reset key
*
Expand Down Expand Up @@ -87,11 +80,7 @@ public function context($username, $resetKey)
}

$this->userObject = $user;

$this->passwordResetKey = $resetKey;

$this->userRegisteredDatetime = strtotime($this->userObject->user_registered);
$this->passwordResetRequestDatetime = time();
}

/**
Expand All @@ -115,6 +104,9 @@ public function mergeTags()
[
'slug' => 'password_reset_request_datetime',
'name' => __('Password reset request date', 'notification'),
'timestamp' => static function () {
return time();
},
]
)
);
Expand Down
Loading

0 comments on commit 0ee54f8

Please sign in to comment.