diff --git a/system/View/Filters.php b/system/View/Filters.php index 86fd23c4b0a6..9d0954fdb0fd 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 array|bool|float|int|object|resource|string|null $value */ public static function default($value, string $default): string { @@ -208,7 +208,7 @@ public static function prose(string $value): string * - ceil always rounds up * - floor always rounds down * - * @param mixed $precision + * @param int|string $precision * * @return float|string */ diff --git a/system/View/Parser.php b/system/View/Parser.php index 87b99ff0508b..9b425602c904 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,7 @@ class Parser extends View /** * Constructor * - * @param string $viewPath - * @param mixed $loader - * @param bool $debug - * @param LoggerInterface $logger + * @param FileLocator|null $loader */ public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) { @@ -90,9 +88,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 { @@ -153,9 +148,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 - * @param bool $saveData */ public function renderString(string $template, ?array $options = null, ?bool $saveData = null): string { @@ -187,8 +179,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 +495,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 +690,9 @@ public function removePlugin(string $alias) * Converts an object to an array, respecting any * toArray() methods on an object. * - * @param mixed $value + * @param array|bool|float|int|object|string|null $value * - * @return mixed + * @return array|bool|float|int|string|null */ protected function objectToArray($value) { 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 {