Skip to content

Commit 9d4ad84

Browse files
authored
Merge pull request #1768 from atishamte/develop
Helper changes
2 parents 4d06fa2 + ad9690e commit 9d4ad84

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

system/Helpers/date_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*
4848
* @return integer
4949
*/
50-
function now(string $timezone = null)
50+
function now(string $timezone = null): int
5151
{
5252
$timezone = empty($timezone) ? app_timezone() : $timezone;
5353

system/Helpers/number_helper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* @param integer $precision
4646
* @param string $locale
4747
*
48-
* @return string
48+
* @return boolean|string
4949
*/
5050
function number_to_size($num, int $precision = 1, string $locale = null)
5151
{
@@ -178,7 +178,7 @@ function number_to_amount($num, int $precision = 0, string $locale = null)
178178
*
179179
* @return string
180180
*/
181-
function number_to_currency($num, string $currency, string $locale = null)
181+
function number_to_currency($num, string $currency, string $locale = null): string
182182
{
183183
return format_number($num, 1, $locale, [
184184
'type' => NumberFormatter::CURRENCY,
@@ -202,7 +202,7 @@ function number_to_currency($num, string $currency, string $locale = null)
202202
*
203203
* @return string
204204
*/
205-
function format_number($num, int $precision = 1, string $locale = null, array $options = [])
205+
function format_number($num, int $precision = 1, string $locale = null, array $options = []): string
206206
{
207207
// Locale is either passed in here, negotiated with client, or grabbed from our config file.
208208
$locale = $locale ?? \CodeIgniter\Config\Services::request()->getLocale();
@@ -259,14 +259,14 @@ function format_number($num, int $precision = 1, string $locale = null, array $o
259259
*
260260
* @param integer $num it will convert to int
261261
*
262-
* @return string
262+
* @return string|null
263263
*/
264264
function number_to_roman($num)
265265
{
266266
$num = (int) $num;
267267
if ($num < 1 || $num > 3999)
268268
{
269-
return;
269+
return null;
270270
}
271271

272272
$_number_to_roman = function ($num, $th) use (&$_number_to_roman) {

system/Helpers/security_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
*
4646
* @return string
4747
*/
48-
function sanitize_filename(string $filename)
48+
function sanitize_filename(string $filename): string
4949
{
5050
return Services::security()->sanitizeFilename($filename);
5151
}
@@ -61,7 +61,7 @@ function sanitize_filename(string $filename)
6161
* @param string $str
6262
* @return string
6363
*/
64-
function strip_image_tags(string $str)
64+
function strip_image_tags(string $str): string
6565
{
6666
return preg_replace([
6767
'#<img[\s/]+.*?src\s*=\s*(["\'])([^\\1]+?)\\1.*?\>#i',

system/Helpers/text_helper.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function ascii_to_entities(string $str): string
150150
{
151151
/*
152152
If the $temp array has a value but we have moved on, then it seems only
153-
fair that we output that entity and restart $temp before continuing. -Paul
153+
fair that we output that entity and restart $temp before continuing.
154154
*/
155155
if (count($temp) === 1)
156156
{
@@ -281,7 +281,7 @@ function word_censor(string $str, $censored, string $replacement = ''): string
281281
// \w, \b and a few others do not match on a unicode character
282282
// set for performance reasons. As a result words like über
283283
// will not match on a word boundary. Instead, we'll assume that
284-
// a bad word will be bookeneded by any of these characters.
284+
// a bad word will be bookended by any of these characters.
285285
$delim = '[-_\'\"`(){}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
286286

287287
foreach ($censored as $badword)
@@ -402,7 +402,7 @@ function highlight_code(string $str): string
402402
*
403403
* @param string $str the text string
404404
* @param string $phrase the phrase you'd like to highlight
405-
* @param string $tag_open the openging tag to precede the phrase with
405+
* @param string $tag_open the opening tag to precede the phrase with
406406
* @param string $tag_close the closing tag to end the phrase with
407407
*
408408
* @return string
@@ -460,7 +460,7 @@ function convert_accented_characters(string $str): string
460460
* Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
461461
* will URLs.
462462
*
463-
* @param string $str the text string
463+
* @param string $str the text string
464464
* @param integer $charlim = 76 the number of characters to wrap at
465465
*
466466
* @return string
@@ -604,9 +604,9 @@ function ellipsize(string $str, int $max_length, $position = 1, string $ellipsis
604604
*
605605
* Removes slashes contained in a string or in an array
606606
*
607-
* @param mixed string or array
607+
* @param mixed $str string or array
608608
*
609-
* @return mixed string or array
609+
* @return mixed string or array
610610
*/
611611
function strip_slashes($str)
612612
{
@@ -632,7 +632,7 @@ function strip_slashes($str)
632632
*
633633
* Removes single and double quotes from a string
634634
*
635-
* @param string
635+
* @param string $str
636636
*
637637
* @return string
638638
*/
@@ -651,7 +651,7 @@ function strip_quotes(string $str): string
651651
*
652652
* Converts single and double quotes to entities
653653
*
654-
* @param string
654+
* @param string $str
655655
*
656656
* @return string
657657
*/
@@ -677,7 +677,7 @@ function quotes_to_entities(string $str): string
677677
*
678678
* http://www.some-site.com/index.php
679679
*
680-
* @param string
680+
* @param string $str
681681
*
682682
* @return string
683683
*/
@@ -712,7 +712,7 @@ function reduce_multiples(string $str, string $character = ',', bool $trim = fal
712712
{
713713
$str = preg_replace('#' . preg_quote($character, '#') . '{2,}#', $character, $str);
714714

715-
return ($trim === true) ? trim($str, $character) : $str;
715+
return ($trim) ? trim($str, $character) : $str;
716716
}
717717
}
718718

@@ -814,7 +814,7 @@ function alternator(): string
814814

815815
$args = func_get_args();
816816

817-
return $args[($i ++ % count($args))];
817+
return $args[($i++ % count($args))];
818818
}
819819
}
820820

@@ -829,13 +829,13 @@ function alternator(): string
829829
*
830830
* @param string $text String to search the phrase
831831
* @param string $phrase Phrase that will be searched for.
832-
* @param integer $radius The amount of characters returned arround the phrase.
832+
* @param integer $radius The amount of characters returned around the phrase.
833833
* @param string $ellipsis Ending that will be appended
834834
*
835835
* @return string
836836
*
837837
* If no $phrase is passed, will generate an excerpt of $radius characters
838-
* from the begining of $text.
838+
* from the beginning of $text.
839839
*/
840840
function excerpt(string $text, string $phrase = null, int $radius = 100, string $ellipsis = '...'): string
841841
{

system/Helpers/url_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function anchor_popup($uri = '', string $title = '', $attributes = false, \Confi
334334
*/
335335
function mailto($email, string $title = '', $attributes = ''): string
336336
{
337-
if ($title === '')
337+
if (trim($title) === '')
338338
{
339339
$title = $email;
340340
}
@@ -360,7 +360,7 @@ function mailto($email, string $title = '', $attributes = ''): string
360360
*/
361361
function safe_mailto($email, string $title = '', $attributes = ''): string
362362
{
363-
if ($title === '')
363+
if (trim($title) === '')
364364
{
365365
$title = $email;
366366
}

user_guide_src/source/helpers/number_helper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ The following functions are available:
109109
110110
:param string $num: The number want to convert
111111
:returns: The roman number converted from given parameter
112-
:rtype: string
112+
:rtype: string|null
113113

114114
Converts a number into roman::
115115

0 commit comments

Comments
 (0)