Skip to content

Commit

Permalink
Merge pull request #1768 from atishamte/develop
Browse files Browse the repository at this point in the history
Helper changes
  • Loading branch information
jim-parry authored Feb 28, 2019
2 parents 4d06fa2 + ad9690e commit 9d4ad84
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion system/Helpers/date_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* @return integer
*/
function now(string $timezone = null)
function now(string $timezone = null): int
{
$timezone = empty($timezone) ? app_timezone() : $timezone;

Expand Down
10 changes: 5 additions & 5 deletions system/Helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @param integer $precision
* @param string $locale
*
* @return string
* @return boolean|string
*/
function number_to_size($num, int $precision = 1, string $locale = null)
{
Expand Down Expand Up @@ -178,7 +178,7 @@ function number_to_amount($num, int $precision = 0, string $locale = null)
*
* @return string
*/
function number_to_currency($num, string $currency, string $locale = null)
function number_to_currency($num, string $currency, string $locale = null): string
{
return format_number($num, 1, $locale, [
'type' => NumberFormatter::CURRENCY,
Expand All @@ -202,7 +202,7 @@ function number_to_currency($num, string $currency, string $locale = null)
*
* @return string
*/
function format_number($num, int $precision = 1, string $locale = null, array $options = [])
function format_number($num, int $precision = 1, string $locale = null, array $options = []): string
{
// Locale is either passed in here, negotiated with client, or grabbed from our config file.
$locale = $locale ?? \CodeIgniter\Config\Services::request()->getLocale();
Expand Down Expand Up @@ -259,14 +259,14 @@ function format_number($num, int $precision = 1, string $locale = null, array $o
*
* @param integer $num it will convert to int
*
* @return string
* @return string|null
*/
function number_to_roman($num)
{
$num = (int) $num;
if ($num < 1 || $num > 3999)
{
return;
return null;
}

$_number_to_roman = function ($num, $th) use (&$_number_to_roman) {
Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/security_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*
* @return string
*/
function sanitize_filename(string $filename)
function sanitize_filename(string $filename): string
{
return Services::security()->sanitizeFilename($filename);
}
Expand All @@ -61,7 +61,7 @@ function sanitize_filename(string $filename)
* @param string $str
* @return string
*/
function strip_image_tags(string $str)
function strip_image_tags(string $str): string
{
return preg_replace([
'#<img[\s/]+.*?src\s*=\s*(["\'])([^\\1]+?)\\1.*?\>#i',
Expand Down
26 changes: 13 additions & 13 deletions system/Helpers/text_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function ascii_to_entities(string $str): string
{
/*
If the $temp array has a value but we have moved on, then it seems only
fair that we output that entity and restart $temp before continuing. -Paul
fair that we output that entity and restart $temp before continuing.
*/
if (count($temp) === 1)
{
Expand Down Expand Up @@ -281,7 +281,7 @@ function word_censor(string $str, $censored, string $replacement = ''): string
// \w, \b and a few others do not match on a unicode character
// set for performance reasons. As a result words like über
// will not match on a word boundary. Instead, we'll assume that
// a bad word will be bookeneded by any of these characters.
// a bad word will be bookended by any of these characters.
$delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';

foreach ($censored as $badword)
Expand Down Expand Up @@ -402,7 +402,7 @@ function highlight_code(string $str): string
*
* @param string $str the text string
* @param string $phrase the phrase you'd like to highlight
* @param string $tag_open the openging tag to precede the phrase with
* @param string $tag_open the opening tag to precede the phrase with
* @param string $tag_close the closing tag to end the phrase with
*
* @return string
Expand Down Expand Up @@ -460,7 +460,7 @@ function convert_accented_characters(string $str): string
* Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
* will URLs.
*
* @param string $str the text string
* @param string $str the text string
* @param integer $charlim = 76 the number of characters to wrap at
*
* @return string
Expand Down Expand Up @@ -604,9 +604,9 @@ function ellipsize(string $str, int $max_length, $position = 1, string $ellipsis
*
* Removes slashes contained in a string or in an array
*
* @param mixed string or array
* @param mixed $str string or array
*
* @return mixed string or array
* @return mixed string or array
*/
function strip_slashes($str)
{
Expand All @@ -632,7 +632,7 @@ function strip_slashes($str)
*
* Removes single and double quotes from a string
*
* @param string
* @param string $str
*
* @return string
*/
Expand All @@ -651,7 +651,7 @@ function strip_quotes(string $str): string
*
* Converts single and double quotes to entities
*
* @param string
* @param string $str
*
* @return string
*/
Expand All @@ -677,7 +677,7 @@ function quotes_to_entities(string $str): string
*
* http://www.some-site.com/index.php
*
* @param string
* @param string $str
*
* @return string
*/
Expand Down Expand Up @@ -712,7 +712,7 @@ function reduce_multiples(string $str, string $character = ',', bool $trim = fal
{
$str = preg_replace('#' . preg_quote($character, '#') . '{2,}#', $character, $str);

return ($trim === true) ? trim($str, $character) : $str;
return ($trim) ? trim($str, $character) : $str;
}
}

Expand Down Expand Up @@ -814,7 +814,7 @@ function alternator(): string

$args = func_get_args();

return $args[($i ++ % count($args))];
return $args[($i++ % count($args))];
}
}

Expand All @@ -829,13 +829,13 @@ function alternator(): string
*
* @param string $text String to search the phrase
* @param string $phrase Phrase that will be searched for.
* @param integer $radius The amount of characters returned arround the phrase.
* @param integer $radius The amount of characters returned around the phrase.
* @param string $ellipsis Ending that will be appended
*
* @return string
*
* If no $phrase is passed, will generate an excerpt of $radius characters
* from the begining of $text.
* from the beginning of $text.
*/
function excerpt(string $text, string $phrase = null, int $radius = 100, string $ellipsis = '...'): string
{
Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ function anchor_popup($uri = '', string $title = '', $attributes = false, \Confi
*/
function mailto($email, string $title = '', $attributes = ''): string
{
if ($title === '')
if (trim($title) === '')
{
$title = $email;
}
Expand All @@ -360,7 +360,7 @@ function mailto($email, string $title = '', $attributes = ''): string
*/
function safe_mailto($email, string $title = '', $attributes = ''): string
{
if ($title === '')
if (trim($title) === '')
{
$title = $email;
}
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/helpers/number_helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The following functions are available:
:param string $num: The number want to convert
:returns: The roman number converted from given parameter
:rtype: string
:rtype: string|null

Converts a number into roman::

Expand Down

0 comments on commit 9d4ad84

Please sign in to comment.