Skip to content

Commit

Permalink
Fix for deprecation warning in SimpleGraphHelper::bar() (#981)
Browse files Browse the repository at this point in the history
* Fix for deprecation warning in float-to-int conversion

* Add test for using float with SimpleGraphHelper::bar

* phpcs fix
  • Loading branch information
jharder authored Dec 21, 2023
1 parent 12dedc1 commit ffb0746
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/View/Helper/SimpleGraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
25 changes: 25 additions & 0 deletions tests/TestCase/View/Helper/SimpleGraphHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ffb0746

Please sign in to comment.