From 9b68863a65e1cdfff00b02f5a8e4685317c1df11 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Sat, 17 Sep 2022 21:24:44 +0700 Subject: [PATCH 1/9] docs: replace doctype Parser and Filter --- system/View/Filters.php | 9 +++++---- system/View/Parser.php | 25 ++++++++++--------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/system/View/Filters.php b/system/View/Filters.php index 86fd23c4b0a6..dc693caa8801 100644 --- a/system/View/Filters.php +++ b/system/View/Filters.php @@ -30,7 +30,7 @@ public static function capitalize(string $value): string /** * Formats a date into the given $format. * - * @param mixed $value + * @param int|string|null $value */ public static function date($value, string $format): string { @@ -48,7 +48,7 @@ public static function date($value, string $format): string * Example: * my_date|date_modify(+1 day) * - * @param string $value + * @param int|string|null $value * * @return false|int */ @@ -62,7 +62,7 @@ public static function date_modify($value, string $adjustment) /** * Returns the given default value if $value is empty or undefined. * - * @param mixed $value + * @param int|string|null $value */ public static function default($value, string $default): string { @@ -208,12 +208,13 @@ public static function prose(string $value): string * - ceil always rounds up * - floor always rounds down * - * @param mixed $precision + * @param float|int|string $precision * * @return float|string */ public static function round(string $value, $precision = 2, string $type = 'common') { + $testGatau = 1337.0; if (! is_numeric($precision)) { $type = $precision; $precision = 2; diff --git a/system/View/Parser.php b/system/View/Parser.php index 87b99ff0508b..cd52517a60b5 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -11,6 +11,7 @@ namespace CodeIgniter\View; +use CodeIgniter\Autoloader\FileLocator; use CodeIgniter\View\Exceptions\ViewException; use Config\View as ViewConfig; use ParseError; @@ -72,10 +73,8 @@ class Parser extends View /** * Constructor * - * @param string $viewPath - * @param mixed $loader - * @param bool $debug - * @param LoggerInterface $logger + * @param string $viewPath + * @param FileLocator|null $loader */ public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) { @@ -90,9 +89,6 @@ public function __construct(ViewConfig $config, ?string $viewPath = null, $loade * * Parses pseudo-variables contained in the specified template view, * replacing them with any data that has already been set. - * - * @param array $options - * @param bool $saveData */ public function render(string $view, ?array $options = null, ?bool $saveData = null): string { @@ -155,7 +151,6 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n * replacing them with any data that has already been set. * * @param array $options - * @param bool $saveData */ public function renderString(string $template, ?array $options = null, ?bool $saveData = null): string { @@ -187,8 +182,8 @@ public function renderString(string $template, ?array $options = null, ?bool $sa * so that the variable is correctly handled within the * parsing itself, and contexts (including raw) are respected. * - * @param string $context The context to escape it for: html, css, js, url, raw - * If 'raw', no escaping will happen + * @param string|null $context The context to escape it for: html, css, js, url, raw + * If 'raw', no escaping will happen */ public function setData(array $data = [], ?string $context = null): RendererInterface { @@ -503,9 +498,9 @@ public function setConditionalDelimiters($leftDelimiter = '{', $rightDelimiter = * Handles replacing a pseudo-variable with the actual content. Will double-check * for escaping brackets. * - * @param mixed $pattern - * @param string $content - * @param string $template + * @param array|string $pattern + * @param string $content + * @param string $template */ protected function replaceSingle($pattern, $content, $template, bool $escape = false): string { @@ -698,9 +693,9 @@ public function removePlugin(string $alias) * Converts an object to an array, respecting any * toArray() methods on an object. * - * @param mixed $value + * @param object $value * - * @return mixed + * @return array */ protected function objectToArray($value) { From 09015db3dbeeea64052c140d186bdb986e2ea341 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Sat, 17 Sep 2022 21:44:23 +0700 Subject: [PATCH 2/9] docs: replace doctype parser and run cs-fix --- system/View/Parser.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/system/View/Parser.php b/system/View/Parser.php index cd52517a60b5..9ebcb695cb96 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -72,11 +72,8 @@ class Parser extends View /** * Constructor - * - * @param string $viewPath - * @param FileLocator|null $loader */ - public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) + public function __construct(ViewConfig $config, ?string $viewPath = null, ?FileLocator $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) { // Ensure user plugins override core plugins. $this->plugins = $config->plugins ?? []; From 2273ba030882c285df93ed5883c4b1814b42adfa Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Sat, 17 Sep 2022 22:15:45 +0700 Subject: [PATCH 3/9] docs: replace doctype Parser and Filter --- system/View/Filters.php | 1 - system/View/Parser.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/system/View/Filters.php b/system/View/Filters.php index dc693caa8801..ee68920ae9c7 100644 --- a/system/View/Filters.php +++ b/system/View/Filters.php @@ -214,7 +214,6 @@ public static function prose(string $value): string */ public static function round(string $value, $precision = 2, string $type = 'common') { - $testGatau = 1337.0; if (! is_numeric($precision)) { $type = $precision; $precision = 2; diff --git a/system/View/Parser.php b/system/View/Parser.php index 9ebcb695cb96..9d68f0a16650 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -146,8 +146,6 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n * * Parses pseudo-variables contained in the specified string, * replacing them with any data that has already been set. - * - * @param array $options */ public function renderString(string $template, ?array $options = null, ?bool $saveData = null): string { From 748326388ba2457958baa1af26b701c02e9c038e Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Sun, 18 Sep 2022 06:08:16 +0700 Subject: [PATCH 4/9] docs: change doctype construct parser --- system/View/Parser.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/View/Parser.php b/system/View/Parser.php index 9d68f0a16650..7463eefe9195 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -72,8 +72,10 @@ class Parser extends View /** * Constructor + * + * @param FileLocator|null $loader */ - public function __construct(ViewConfig $config, ?string $viewPath = null, ?FileLocator $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) + public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) { // Ensure user plugins override core plugins. $this->plugins = $config->plugins ?? []; From b5a3cd77b0320fb4e1a0735df74dcb95a47795ee Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Sun, 18 Sep 2022 19:50:06 +0700 Subject: [PATCH 5/9] Update system/View/Filters.php Co-authored-by: MGatner --- system/View/Filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/View/Filters.php b/system/View/Filters.php index ee68920ae9c7..8fad49dd6b97 100644 --- a/system/View/Filters.php +++ b/system/View/Filters.php @@ -208,7 +208,7 @@ public static function prose(string $value): string * - ceil always rounds up * - floor always rounds down * - * @param float|int|string $precision + * @param int|string $precision * * @return float|string */ From c81ee0b5ad6c335401f5e091d4afc74cc4d1794d Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Sun, 18 Sep 2022 20:44:24 +0700 Subject: [PATCH 6/9] tests: added sample tests in setData --- tests/system/View/ParserTest.php | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/system/View/ParserTest.php b/tests/system/View/ParserTest.php index 3fa36585e7ea..54d8a4b0df35 100644 --- a/tests/system/View/ParserTest.php +++ b/tests/system/View/ParserTest.php @@ -265,6 +265,71 @@ public function testParseLoopObjectProperties() $this->assertSame("Super Heroes\nTom Dick Henry ", $this->parser->renderString($template)); } + public function testParseIntegerPositive() + { + $data = [ + 'title' => 'Count:', + 'amount' => 5, + ]; + + $template = '{title} {amount}'; + + $this->parser->setData($data, 'html'); + $this->assertSame('Count: 5', $this->parser->renderString($template)); + } + + public function testParseIntegerNegative() + { + $data = [ + 'title' => 'Count:', + 'amount' => -5, + ]; + + $template = '{title} {amount}'; + + $this->parser->setData($data, 'html'); + $this->assertSame('Count: -5', $this->parser->renderString($template)); + } + + public function testParseFloatPositive() + { + $data = [ + 'title' => 'Rate:', + 'amount' => 5.5, + ]; + + $template = '{title} {amount}'; + + $this->parser->setData($data, 'html'); + $this->assertSame('Rate: 5.5', $this->parser->renderString($template)); + } + + public function testParseFloatNegative() + { + $data = [ + 'title' => 'Rate:', + 'amount' => -5.5, + ]; + + $template = '{title} {amount}'; + + $this->parser->setData($data, 'html'); + $this->assertSame('Rate: -5.5', $this->parser->renderString($template)); + } + + public function testParseNull() + { + $data = [ + 'title' => 'Ticks:', + 'amount' => null, + ]; + + $template = '{title} {amount}'; + + $this->parser->setData($data, 'html'); + $this->assertSame('Ticks: ', $this->parser->renderString($template)); + } + public function testParseLoopEntityProperties() { $power = new class () extends Entity { From 51d2f8408237ca296b659ab693b23e2b87e7b9dd Mon Sep 17 00:00:00 2001 From: ddevsr Date: Mon, 19 Sep 2022 08:44:35 +0700 Subject: [PATCH 7/9] docs: changes doctype objectToArray --- system/View/Parser.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/View/Parser.php b/system/View/Parser.php index 7463eefe9195..07f83d6cb93a 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -121,7 +121,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n } if ($this->tempData === null) { - $this->tempData = $this->data; + $this->tempData = $this->data; // @codeCoverageIgnore } $template = file_get_contents($file); @@ -447,7 +447,7 @@ protected function parseConditionals(string $template): string ob_start(); if ($this->tempData === null) { - $this->tempData = $this->data; + $this->tempData = $this->data; // @codeCoverageIgnore } extract($this->tempData); @@ -690,7 +690,7 @@ public function removePlugin(string $alias) * Converts an object to an array, respecting any * toArray() methods on an object. * - * @param object $value + * @param array|float|int|object|string $value * * @return array */ From 71b527ac3ffc4eaaea964ce0ff0ee1407d56a812 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 19 Sep 2022 20:52:45 +0700 Subject: [PATCH 8/9] docs: change doctype default function --- system/View/Filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/View/Filters.php b/system/View/Filters.php index 8fad49dd6b97..9d0954fdb0fd 100644 --- a/system/View/Filters.php +++ b/system/View/Filters.php @@ -62,7 +62,7 @@ public static function date_modify($value, string $adjustment) /** * Returns the given default value if $value is empty or undefined. * - * @param int|string|null $value + * @param array|bool|float|int|object|resource|string|null $value */ public static function default($value, string $default): string { From d952f05d9cf68cfbebbe1b1d8ccbacd04c9c4e93 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Tue, 20 Sep 2022 21:54:51 +0700 Subject: [PATCH 9/9] docs: change doctype objectToArray to many type --- system/View/Parser.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/View/Parser.php b/system/View/Parser.php index 07f83d6cb93a..9b425602c904 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -121,7 +121,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n } if ($this->tempData === null) { - $this->tempData = $this->data; // @codeCoverageIgnore + $this->tempData = $this->data; } $template = file_get_contents($file); @@ -447,7 +447,7 @@ protected function parseConditionals(string $template): string ob_start(); if ($this->tempData === null) { - $this->tempData = $this->data; // @codeCoverageIgnore + $this->tempData = $this->data; } extract($this->tempData); @@ -690,9 +690,9 @@ public function removePlugin(string $alias) * Converts an object to an array, respecting any * toArray() methods on an object. * - * @param array|float|int|object|string $value + * @param array|bool|float|int|object|string|null $value * - * @return array + * @return array|bool|float|int|string|null */ protected function objectToArray($value) {