Skip to content

Commit ffb0746

Browse files
authored
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
1 parent 12dedc1 commit ffb0746

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/View/Helper/SimpleGraphHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class SimpleGraphHelper extends Helper
4747
/**
4848
* bar method
4949
*
50-
* @param float $value Value to be graphed
51-
* @param int $offset how much indentation
50+
* @param float|int $value Value to be graphed
51+
* @param float|int $offset how much indentation
5252
* @param array $options Graph options
5353
* @return string Html graph
5454
*/
55-
public function bar(float $value, int $offset, array $options = []): string
55+
public function bar(float|int $value, float|int $offset, array $options = []): string
5656
{
5757
$settings = array_merge($this->_defaultSettings, $options);
5858
$max = $settings['max'];

tests/TestCase/View/Helper/SimpleGraphHelperTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,29 @@ public function testBarOffset()
113113
];
114114
$this->assertHtml($expected, $output);
115115
}
116+
117+
/**
118+
* Test bar() using float offset values
119+
*
120+
* @return void
121+
*/
122+
public function testBarWithFloat()
123+
{
124+
$output = $this->Graph->bar(10.5, 10.5);
125+
$expected = [
126+
['div' => [
127+
'class' => 'c-graph-bar',
128+
'style' => 'width: 350px',
129+
]],
130+
['div' => [
131+
'class' => 'c-graph-bar__value',
132+
'style' => 'margin-left: 37px; width: 37px',
133+
'title' => 'Starting 10.5ms into the request, taking 10.5ms',
134+
]],
135+
' ',
136+
'/div',
137+
'/div',
138+
];
139+
$this->assertHtml($expected, $output);
140+
}
116141
}

0 commit comments

Comments
 (0)