Skip to content

Commit

Permalink
(phpstan) return types update
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesDPC committed Aug 7, 2024
1 parent 9af709f commit e255ffb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
8 changes: 2 additions & 6 deletions src/Controllers/ChimpleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ protected function getActions() : FieldList {

/**
* Return the default validator for the form.
* @returns Validator|null
*/
protected function getValidator() : ?Validator {
return RequiredFields::create(['Name','Email']);
Expand All @@ -263,7 +262,6 @@ protected function getValidator() : ?Validator {
* Returns the validation callback upon errors
* A response is returned only upon errors in XHR submissions
* See FormRequestHandler::getValidationErrorResponse();
* @return callable
*/
protected function getCallbackForXhrValidation() : callable {
return function(ValidationResult $result) {
Expand Down Expand Up @@ -481,9 +479,8 @@ public function subscribe($data = [], Form $form = null)

/**
* Return error response for XHR
* @return HTTPResponse
*/
private function xhrError($code = 500, $message = "", $description = "") {
private function xhrError($code = 500, $message = "", $description = ""): HTTPResponse {
$response = new HTTPResponse();
$response->setStatusCode($code);
$response->addHeader('Content-Type', 'application/json');
Expand All @@ -494,9 +491,8 @@ private function xhrError($code = 500, $message = "", $description = "") {

/**
* Return success response for XHR
* @return HTTPResponse
*/
private function xhrSuccess($code = 200, $message = "", $description = "") {
private function xhrSuccess($code = 200, $message = "", $description = ""): HTTPResponse {
$response = new HTTPResponse();
$response->setStatusCode($code);
$response->addHeader('Content-Type', 'application/json');
Expand Down
16 changes: 5 additions & 11 deletions src/Models/MailchimpConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public static function getApiKey()

/**
* Returns the data centre (dc) component based on the API key e.g us2
* @return string
*/
public static function getDataCentre() : string {
$dc = '';
Expand Down Expand Up @@ -329,9 +328,8 @@ public function getCMSFields()

/**
* Return signup link
* @return string
*/
public function MailchimpLink()
public function MailchimpLink() : string
{
return singleton(ChimpleController::class)->Link();
}
Expand Down Expand Up @@ -405,9 +403,8 @@ public function SubscribeForm($force_xhr = null) : ?SubscribeForm

/**
* Return alerts for the form
* @return string
*/
public function Alerts()
public function Alerts(): string
{
return '<div class="hidden alert alert-success" data-type="success">'
. _t(__CLASS__ . '.SUBSCRIBE_SUCCESS', htmlspecialchars($this->config()->get('success_message')))
Expand Down Expand Up @@ -462,9 +459,8 @@ public function providePermissions()

/**
* Render this record using a template
* @return DBHTMLText|null
*/
public function forTemplate($force_xhr = null)
public function forTemplate($force_xhr = null) : ?DBHTMLText
{
$form = $this->SubscribeForm($force_xhr);
if($form) {
Expand All @@ -479,9 +475,8 @@ public function forTemplate($force_xhr = null)
* The 2nd parameter is a 1 or 0 representing whether to handle the submission via XHR
* This is called from a template calling $ChimpleSubscribeForm('code'[,0|1])
* @param array $args
* @return DBHTMLText|null
*/
public static function get_chimple_subscribe_form(...$args)
public static function get_chimple_subscribe_form(...$args) : ?DBHTMLText
{
$code = isset($args[0]) ? $args[0] : '';
if ($code) {
Expand All @@ -507,9 +502,8 @@ public static function get_chimple_subscribe_form(...$args)
/**
* Get the subscribe form for the current global config
* This is called from a template calling $ChimpleSubscribeForm('code')
* @return DBHTMLText|null
*/
public static function get_chimple_global_subscribe_form()
public static function get_chimple_global_subscribe_form() : ?DBHTMLText
{
$config = self::getGlobalConfig();
if ($config) {
Expand Down
25 changes: 8 additions & 17 deletions src/Models/MailchimpSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ public function getSurnameFromName()

/**
* Get the API client
* @return MailchimpApiClient
*/
public static function api() : MailchimpApiClient {
// already set up..
Expand Down Expand Up @@ -452,9 +451,8 @@ public function getMailchimpListId()

/**
* Applies merge fields prior to subscription attempt
* @return array
*/
protected function applyMergeFields() {
protected function applyMergeFields(): array {
$merge_fields = [];

// get subscriber meta data
Expand Down Expand Up @@ -498,7 +496,6 @@ protected function applyMergeFields() {

/**
* Get the default subscription record data for adding/updating member in list
* @return array
*/
public function getSubscribeRecord() : array {
// merge fields to send
Expand Down Expand Up @@ -530,10 +527,9 @@ public function getSubscriberTags() {

/**
* Called after a successful subscription, obfuscates email, name and surname
* @return void
*/
private function obfuscate() {
$obfuscate = function($in) {
$obfuscate = function(string $in) : string {
$length = strlen($in);
if($length == 0) {
return "";
Expand All @@ -550,16 +546,15 @@ private function obfuscate() {
$replaced = substr_replace($in, str_repeat($chr, $sub_length), 1, $sub_length);
return $replaced;
};
$this->Email = $obfuscate($this->Email);
$this->Name = $obfuscate($this->Name);
$this->Surname = $obfuscate($this->Surname);
$this->Email = $obfuscate($this->Email ?? '');
$this->Name = $obfuscate($this->Name ?? '');
$this->Surname = $obfuscate($this->Surname ?? '');
}

/**
* Get the hash that is used as the MC subscribed Id value
* @return string
*/
public static function getMailchimpSubscribedId($email) {
public static function getMailchimpSubscribedId($email): string {
if(!is_string($email) || !$email) {
return '';
} else {
Expand All @@ -572,9 +567,8 @@ public static function getMailchimpSubscribedId($email) {
* @param string $list_id the Audience ID
* @param string $email an email address, this is hashed using the MC hashing strategy
* @param string $api_key @deprecated
* @return boolean|array
*/
public static function checkExistsInList(string $list_id, string $email, string $api_key = '') {
public static function checkExistsInList(string $list_id, string $email, string $api_key = '') : array|false {

// sanity check on input
if(!$email) {
Expand Down Expand Up @@ -612,9 +606,8 @@ public static function checkExistsInList(string $list_id, string $email, string

/**
* Subscribe *this* particular record
* @return bool
*/
public function subscribe()
public function subscribe() : bool
{
try {

Expand Down Expand Up @@ -700,7 +693,6 @@ public function subscribe()
* Return all current tags for a subscriber and handle pagination at the time of the API call
* @param bool $force whether to get the tags from the remote or use previously retrieved tags
* @param int $count the number of records to return per request
* @return array an array of values, each value is a string tag
*/
private function getCurrentSubscriberTags(bool $force = false, int $count = 10) : array {

Expand Down Expand Up @@ -815,7 +807,6 @@ protected function modifySubscriberTags() : bool {
/**
* Batch subscribe via API - hit from MailchimpSubscribeJob
* Retrieve all subscribers marked new and attempt to subscribe them
* @return array
*/
public static function batch_subscribe($limit = 100, $report_only = false) : array
{
Expand Down

0 comments on commit e255ffb

Please sign in to comment.