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

Fix typing, comments in new StandardFilters class #25730

Merged
merged 1 commit into from
Mar 4, 2023
Merged
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
50 changes: 42 additions & 8 deletions Civi/Token/StandardFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Civi\Token;

/**
* This class is a collection of CiviMail filter functions. For example, consider this message:
* This class is a collection of token filter functions. For example, consider this message:
*
* "Hello {contact.first_name|upper}!"
*
Expand All @@ -21,9 +21,13 @@ class StandardFilters {
* The list of filter criteria, as requested in this template.
* @param string $format
* The format of the active template ('text/plain' or 'text/html').
* @return mixed
*
* @return string
*
* @throws \CRM_Core_Exception
* @noinspection PhpUnusedParameterInspection
*/
public static function upper($value, array $filter, string $format) {
public static function upper($value, array $filter, string $format): string {
switch ($format) {
case 'text/plain':
return mb_strtoupper($value);
Expand All @@ -36,7 +40,19 @@ public static function upper($value, array $filter, string $format) {
}
}

public static function lower($value, array $filter, string $format) {
/**
* Convert to lowercase.
*
* @param string $value
* @param array $filter
* @param string $format
*
* @return string
*
* @throws \CRM_Core_Exception
* @noinspection PhpUnusedParameterInspection
*/
public static function lower($value, array $filter, string $format): string {
switch ($format) {
case 'text/plain':
return mb_strtolower($value);
Expand All @@ -49,7 +65,17 @@ public static function lower($value, array $filter, string $format) {
}
}

public static function boolean($value, array $filter, string $format) {
/**
* Convert to boolean.
*
* @param string $value
* @param array $filter
* @param string $format
*
* @return int
* @noinspection PhpUnusedParameterInspection
*/
public static function boolean($value, array $filter, string $format): int {
return (int) ((bool) $value);
}

Expand All @@ -68,13 +94,21 @@ public static function crmDate($value, array $filter, string $format) {
return static::default($value, $filter, $format);
}

/**
* Return value, falling back to default.
*
* @param $value
* @param array $filter
* @param string $format
*
* @return mixed
* @noinspection PhpUnusedParameterInspection
*/
public static function default($value, array $filter, string $format) {
if (!$value) {
return $filter[1];
}
else {
return $value;
}
return $value;
}

}