From ffb0746d2d54f63bda91a6cba474252a14cd889b Mon Sep 17 00:00:00 2001 From: jharder Date: Thu, 21 Dec 2023 12:27:49 -0600 Subject: [PATCH] Fix for deprecation warning in SimpleGraphHelper::bar() (#981) * Fix for deprecation warning in float-to-int conversion * Add test for using float with SimpleGraphHelper::bar * phpcs fix --- src/View/Helper/SimpleGraphHelper.php | 6 ++--- .../View/Helper/SimpleGraphHelperTest.php | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/View/Helper/SimpleGraphHelper.php b/src/View/Helper/SimpleGraphHelper.php index 559bea48..bbc593a7 100644 --- a/src/View/Helper/SimpleGraphHelper.php +++ b/src/View/Helper/SimpleGraphHelper.php @@ -47,12 +47,12 @@ class SimpleGraphHelper extends Helper /** * bar method * - * @param float $value Value to be graphed - * @param int $offset how much indentation + * @param float|int $value Value to be graphed + * @param float|int $offset how much indentation * @param array $options Graph options * @return string Html graph */ - public function bar(float $value, int $offset, array $options = []): string + public function bar(float|int $value, float|int $offset, array $options = []): string { $settings = array_merge($this->_defaultSettings, $options); $max = $settings['max']; diff --git a/tests/TestCase/View/Helper/SimpleGraphHelperTest.php b/tests/TestCase/View/Helper/SimpleGraphHelperTest.php index d258acb2..275c7bf1 100644 --- a/tests/TestCase/View/Helper/SimpleGraphHelperTest.php +++ b/tests/TestCase/View/Helper/SimpleGraphHelperTest.php @@ -113,4 +113,29 @@ public function testBarOffset() ]; $this->assertHtml($expected, $output); } + + /** + * Test bar() using float offset values + * + * @return void + */ + public function testBarWithFloat() + { + $output = $this->Graph->bar(10.5, 10.5); + $expected = [ + ['div' => [ + 'class' => 'c-graph-bar', + 'style' => 'width: 350px', + ]], + ['div' => [ + 'class' => 'c-graph-bar__value', + 'style' => 'margin-left: 37px; width: 37px', + 'title' => 'Starting 10.5ms into the request, taking 10.5ms', + ]], + ' ', + '/div', + '/div', + ]; + $this->assertHtml($expected, $output); + } }