From c90ba8c4fc20dde88017219b72d619f6855e897c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 9 Aug 2018 15:38:19 +0700 Subject: [PATCH] remove unneeded (string) cast as type hinted --- system/Helpers/form_helper.php | 8 -------- system/Helpers/url_helper.php | 15 ++++----------- system/Validation/FormatRules.php | 6 +++--- system/View/Parser.php | 2 +- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index fcac0adbabe8..1706147b3b41 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -802,8 +802,6 @@ function set_select(string $field, string $value = '', bool $default = false): s if (is_array($input)) { - $value = (string) $value; - // Note: in_array('', array(0)) returns TRUE, do not use it foreach ($input as &$v) { @@ -840,9 +838,6 @@ function set_select(string $field, string $value = '', bool $default = false): s */ function set_checkbox(string $field, string $value = '', bool $default = false): string { - // Form inputs are always strings ... - $value = (string) $value; - $request = Services::request(); // Try any old input data we may have first @@ -897,9 +892,6 @@ function set_checkbox(string $field, string $value = '', bool $default = false): */ function set_radio(string $field, string $value = '', bool $default = false): string { - // Form inputs are always strings ... - $value = (string) $value; - $request = Services::request(); // Try any old input data we may have first diff --git a/system/Helpers/url_helper.php b/system/Helpers/url_helper.php index 50145dad2d56..01ac81dd0df0 100644 --- a/system/Helpers/url_helper.php +++ b/system/Helpers/url_helper.php @@ -242,13 +242,11 @@ function index_page(\Config\App $altConfig = null): string * * @return string */ - function anchor($uri = '', $title = '', $attributes = '', \Config\App $altConfig = null): string + function anchor($uri = '', string $title = '', $attributes = '', \Config\App $altConfig = null): string { // use alternate config if provided, else default one $config = empty($altConfig) ? config(\Config\App::class) : $altConfig; - $title = (string) $title; - $site_url = is_array($uri) ? site_url($uri, null, $config) : (preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri, null, $config)); // eliminate trailing slash $site_url = rtrim($site_url, '/'); @@ -286,12 +284,11 @@ function anchor($uri = '', $title = '', $attributes = '', \Config\App $altConfig * * @return string */ - function anchor_popup($uri = '', $title = '', $attributes = false, \Config\App $altConfig = null): string + function anchor_popup($uri = '', string $title = '', $attributes = false, \Config\App $altConfig = null): string { // use alternate config if provided, else default one $config = empty($altConfig) ? config(\Config\App::class) : $altConfig; - $title = (string) $title; $site_url = preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri, '', $config); $site_url = rtrim($site_url, '/'); @@ -351,10 +348,8 @@ function anchor_popup($uri = '', $title = '', $attributes = false, \Config\App $ * * @return string */ - function mailto($email, $title = '', $attributes = ''): string + function mailto($email, string $title = '', $attributes = ''): string { - $title = (string) $title; - if ($title === '') { $title = $email; @@ -381,10 +376,8 @@ function mailto($email, $title = '', $attributes = ''): string * * @return string */ - function safe_mailto($email, $title = '', $attributes = ''): string + function safe_mailto($email, string $title = '', $attributes = ''): string { - $title = (string) $title; - if ($title === '') { $title = $email; diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index 94beb66cc9b3..c662768392be 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -100,7 +100,7 @@ public function alpha_dash(string $str = null): bool */ public function alpha_numeric(string $str = null): bool { - return ctype_alnum((string) $str); + return ctype_alnum($str); } //-------------------------------------------------------------------- @@ -155,7 +155,7 @@ public function integer(string $str = null): bool */ public function is_natural(string $str = null): bool { - return ctype_digit((string) $str); + return ctype_digit($str); } //-------------------------------------------------------------------- @@ -168,7 +168,7 @@ public function is_natural(string $str = null): bool */ public function is_natural_no_zero(string $str = null): bool { - return ($str != 0 && ctype_digit((string) $str)); + return ($str != 0 && ctype_digit($str)); } //-------------------------------------------------------------------- diff --git a/system/View/Parser.php b/system/View/Parser.php index 13ae9139e6fd..abe1fd11146e 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -328,7 +328,7 @@ protected function parseSingle(string $key, string $val): array { $pattern = '#' . $this->leftDelimiter . '!?\s*' . preg_quote($key) . '\s*\|*\s*([|a-zA-Z0-9<>=\(\),:_\-\s\+]+)*\s*!?' . $this->rightDelimiter . '#ms'; - return [$pattern => (string) $val]; + return [$pattern => $val]; } //--------------------------------------------------------------------