mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Merge pull request #13857 from akemidx/bug/sc-20532
Bug Fix: Undefined array key 266
This commit is contained in:
commit
9e1cfac995
|
@ -73,10 +73,14 @@ class Helper
|
|||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v3.3]
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public static function defaultChartColors($index = 0)
|
||||
public static function defaultChartColors(int $index = 0)
|
||||
{
|
||||
if ($index < 0) {
|
||||
$index = 0;
|
||||
}
|
||||
|
||||
$colors = [
|
||||
'#008941',
|
||||
'#FF4A46',
|
||||
|
@ -349,7 +353,19 @@ class Helper
|
|||
$total_colors = count($colors);
|
||||
|
||||
if ($index >= $total_colors) {
|
||||
$index = $index - $total_colors;
|
||||
|
||||
\Log::error('Status label count is '.$index.' and exceeds the allowed count of 266.');
|
||||
//patch fix for array key overflow (color count starts at 1, array starts at 0)
|
||||
$index = $index - $total_colors - 1;
|
||||
|
||||
//constraints to keep result in 0-265 range. This should never be needed, but if something happens
|
||||
//to create this many status labels and it DOES happen, this will keep it from failing at least.
|
||||
if($index < 0) {
|
||||
$index = 0;
|
||||
}
|
||||
elseif($index >($total_colors - 1)) {
|
||||
$index = $total_colors - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $colors[$index];
|
||||
|
|
|
@ -11,6 +11,7 @@ use PHPUnit\Framework\Assert;
|
|||
use Tests\Support\InteractsWithSettings;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
class CustomReportTest extends TestCase
|
||||
{
|
||||
use InteractsWithSettings;
|
||||
|
|
19
tests/Unit/Helpers/HelperTest.php
Normal file
19
tests/Unit/Helpers/HelperTest.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HelperTest extends TestCase
|
||||
{
|
||||
public function testDefaultChartColorsMethodHandlesHighValues()
|
||||
{
|
||||
$this->assertIsString(Helper::defaultChartColors(1000));
|
||||
}
|
||||
|
||||
public function testDefaultChartColorsMethodHandlesNegativeNumbers()
|
||||
{
|
||||
$this->assertIsString(Helper::defaultChartColors(-1));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue