Skip to content

Commit

Permalink
Qual: Fix phan notices in dolgraph class
Browse files Browse the repository at this point in the history
# Qual: Fix phan notices in dolgraph class

This fixes most notices in the dolgraph class.
  • Loading branch information
mdeweerd committed Oct 14, 2024
1 parent 046166f commit f1e39b0
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 24 deletions.
6 changes: 3 additions & 3 deletions dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ return [
'htdocs/core/boxes/box_graph_ticket_by_severity.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/core/boxes/box_last_modified_ticket.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/core/boxes/box_last_ticket.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/core/boxes/box_project.php' => ['PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullableInternal'],
'htdocs/core/boxes/box_project_opportunities.php' => ['PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullableInternal'],
'htdocs/core/boxes/box_project.php' => ['PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable'],
'htdocs/core/boxes/box_project_opportunities.php' => ['PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable'],
'htdocs/core/boxes/box_services_contracts.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'htdocs/core/boxes/box_task.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/core/boxes/box_validated_projects.php' => ['PhanPluginUnknownPropertyType'],
Expand All @@ -274,7 +274,7 @@ return [
'htdocs/core/class/discount.class.php' => ['PhanPluginUnknownPropertyType'],
'htdocs/core/class/doleditor.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType'],
'htdocs/core/class/dolgeoip.class.php' => ['PhanTypeMismatchProperty'],
'htdocs/core/class/dolgraph.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchDimFetch', 'PhanUndeclaredProperty'],
'htdocs/core/class/dolgraph.class.php' => ['PhanUndeclaredProperty'],
'htdocs/core/class/dolreceiptprinter.class.php' => ['PhanEmptyForeach', 'PhanPluginUnknownArrayPropertyType', 'PhanPluginUnknownPropertyType'],
'htdocs/core/class/emailsenderprofile.class.php' => ['PhanPluginUnknownPropertyType', 'PhanUndeclaredProperty'],
'htdocs/core/class/evalmath.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType', 'PhanTypeMismatchArgumentProbablyReal'],
Expand Down
147 changes: 126 additions & 21 deletions htdocs/core/class/dolgraph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,30 @@
*/
class DolGraph
{
/**
* @var string[]
*/
public $type = array(); // Array with type of each series. Example: array('bars', 'horizontalbars', 'lines', 'pies', 'piesemicircle', 'polar'...)
/**
* @var string
*/
public $mode = 'side'; // Mode bars graph: side, depth
/**
* @var string
*/
private $_library; // Graphic library to use (jflot, chart, artichow)

//! Array of data
/**
* @var array<array{0:string,1:float,1:float}> Array of data
*/
public $data; // Data of graph: array(array('abs1',valA1,valB1), array('abs2',valA2,valB2), ...)
/**
* @var string
*/
public $title; // Title of graph
/**
* @var string
*/
public $cssprefix = ''; // To add into css styles

/**
Expand All @@ -59,45 +76,123 @@ class DolGraph
*/
public $height = 200;

/**
* @var int
*/
public $MaxValue = 0;
/**
* @var int
*/
public $MinValue = 0;
/**
* @var int
*/
public $SetShading = 0;

/**
* @var float
*/
public $horizTickIncrement = -1;
/**
* @var float
*/
public $SetNumXTicks = -1;
/**
* @var float
*/
public $labelInterval = -1;
/**
* @var string
*/
public $YLabel;

/**
* @var bool
*/
public $hideXGrid = false;
/**
* @var bool
*/
public $hideXValues = false;
/**
* @var bool
*/
public $hideYGrid = false;

/**
* @var string[]
*/
public $Legend = array();
/**
* @var float
*/
public $LegendWidthMin = 0;
/**
* @var int<0,1>
*/
public $showlegend = 1;
/**
* @var int<0,1>
*/
public $showpointvalue = 1;
/**
* @var int<0,1>
*/
public $showpercent = 0;
/**
* @var float
*/
public $combine = 0; // 0.05 if you want to combine records < 5% into "other"
/**
* @var object
*/
public $graph; // Object Graph (Artichow, Phplot...)
/**
* @var boolean Mirrors graph values
* @var bool Mirrors graph values
*/
public $mirrorGraphValues = false;
/**
* @var null|string[]
*/
public $tooltipsTitles = null;
/**
* @var null|string[]
*/
public $tooltipsLabels = null;

/**
* @var string Error code (or message)
*/
public $error = '';

/**
* @var array<int<0,2>,int>|array<int<0,2>,array<int<0,2>,int>>
*/
public $bordercolor; // array(R,G,B)
/**
* @var ?array<int<0,2>,int>
*/
public $bgcolor; // array(R,G,B)
/**
* @var ?array<int<0,2>,int>
*/
public $bgcolorgrid = array(255, 255, 255); // array(R,G,B)
/**
* @var array<int<0,2>,array<int<0,2>,int>>
*/
public $datacolor; // array(array(R,G,B),...)
/**
* @var float
*/
public $borderwidth = 1;
/**
* @var string
*/
public $borderskip = 'start';

/**
* @var string
*/
private $stringtoshow; // To store string to output graph into HTML page


Expand Down Expand Up @@ -149,7 +244,7 @@ public function __construct($library = 'auto')
* Utiliser SetNumTicks ou SetHorizTickIncrement mais pas les 2
*
* @param float $xi Xi
* @return boolean True
* @return bool True
*/
public function SetHorizTickIncrement($xi)
{
Expand Down Expand Up @@ -203,8 +298,8 @@ public function SetHideXGrid($bool)
/**
* Hide X Values
*
* @param boolean $bool XValues or not
* @return boolean true
* @param bool $bool XValues or not
* @return bool true
*/
public function setHideXValues($bool)
{
Expand Down Expand Up @@ -269,7 +364,7 @@ public function SetTitle($title)
/**
* Set data
*
* @param array $data Data
* @param array<array{0:string,1:float,2:float}> $data Data
* @return void
* @see draw_jflot() for syntax of data array
*/
Expand All @@ -283,7 +378,7 @@ public function SetData($data)
/**
* Set data color
*
* @param array $datacolor Data color array(array(R,G,B),array(R,G,B)...) or array('#......','#......'...)
* @param array<int<0,2>,array<int<0,2>,int>|string> $datacolor Data color array(array(R,G,B),array(R,G,B)...) or array('#......','#......'...)
* @return void
*/
public function SetDataColor($datacolor)
Expand All @@ -295,7 +390,7 @@ public function SetDataColor($datacolor)
/**
* Set border color
*
* @param array $bordercolor Border Color array(array(R,G,B),array(R,G,B)...) or array('#FFFFFF','#......'...)
* @param array<int<0,2>,array<int<0,2>,int>|string> $bordercolor Color array(array(R,G,B),array(R,G,B)...) or array('#FFFFFF','#......'...)
* @return void
*/
public function setBorderColor($bordercolor)
Expand Down Expand Up @@ -455,7 +550,7 @@ public function SetHeight($h)
/**
* Set shading
*
* @param string $s Shading
* @param int $s Shading
* @return void
*/
public function SetShading($s)
Expand All @@ -468,7 +563,7 @@ public function SetShading($s)
/**
* Set shading
*
* @param string $s Shading
* @param string $s Css prefix
* @return void
*/
public function SetCssPrefix($s)
Expand Down Expand Up @@ -585,7 +680,7 @@ public function SetBgColor($bg_color = array(255, 255, 255))
/**
* Define background color of grid
*
* @param array $bg_colorgrid array(R,G,B) ou 'onglet' ou 'default'
* @param 'onglet'|'default'|array<int<0,2>,int> $bg_colorgrid array(R,G,B) ou 'onglet' ou 'default'
* @return void
*/
public function SetBgColorGrid($bg_colorgrid = array(255, 255, 255))
Expand Down Expand Up @@ -621,7 +716,7 @@ public function ResetDataColor()
/**
* Get max value among all values of all series
*
* @return int Max value
* @return ?float Max value
*/
public function GetMaxValueInData()
{
Expand Down Expand Up @@ -651,7 +746,7 @@ public function GetMaxValueInData()
/**
* Return min value of all values of all series
*
* @return int Min value of all data
* @return ?float Min value of all data
*/
public function GetMinValueInData()
{
Expand Down Expand Up @@ -1096,6 +1191,7 @@ private function draw_chart($file, $fileurl) // @phpstan-ignore-line
//if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x

$series = array();
'@phan-var-force array<int,array{stacknum:int,legend:string,legendwithgroup:string}> $arrayofgroupslegend';
$arrayofgroupslegend = array();
//var_dump($this->data);

Expand All @@ -1110,12 +1206,12 @@ private function draw_chart($file, $fileurl) // @phpstan-ignore-line
$legends[$x] = (array_key_exists('label', $valarray) ? $valarray['label'] : $valarray[0]);
$array_of_ykeys = array_keys($valarray);
$alabelexists = 1;
$tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
$tmpykey = explode('_', (string) ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
if (isset($tmpykey[2]) && (!empty($tmpykey[2]) || $tmpykey[2] == '0')) { // This is a 'Group by' array
$tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : $valarray[$i + 1]);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
$arrayofgroupslegend[$i] = array(
'stacknum' => $tmpykey[1],
'stacknum' => (int) $tmpykey[1],
'legend' => $this->Legend[$tmpykey[1]],
'legendwithgroup' => $this->Legend[$tmpykey[1]] . ' - ' . $tmpykey[2]
);
Expand Down Expand Up @@ -1251,12 +1347,18 @@ private function draw_chart($file, $fileurl) // @phpstan-ignore-line
if ($i > 0) {
$this->stringtoshow .= ', ' . "\n";
}
if (is_array($this->datacolor[$i])) {
if ($this->datacolor !== null) {
$datacolor_item = $this->datacolor[$i];
} else {
$datacolor_item = null;
}

if (is_array($datacolor_item) || $datacolor_item === null) {
$color = 'null'; // If datacolor is array(R, G, B)
} else {
$tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) {
$color = '#' . str_replace('-', '', $tmp); // If $val is '-123'
$tmpcolor = str_replace('#', '', $datacolor_item);
if (strpos($tmpcolor, '-') !== false) {
$color = '#' . str_replace('-', '', $tmpcolor); // If $val is '-123'
} else {
$color = 'null'; // If $val is '123' or '#123'
}
Expand Down Expand Up @@ -1430,6 +1532,7 @@ private function draw_chart($file, $fileurl) // @phpstan-ignore-line
$i = 0;
$iinstack = 0;
$oldstacknum = -1;
$color = '#000000';
while ($i < $nblot) { // Loop on each series
$foundnegativecolor = 0;
$usecolorvariantforgroupby = 0;
Expand All @@ -1447,9 +1550,11 @@ private function draw_chart($file, $fileurl) // @phpstan-ignore-line
}

if ($usecolorvariantforgroupby) {
$newcolor = $this->datacolor[$arrayofgroupslegend[$i]['stacknum']];
$idx = $arrayofgroupslegend[$i]['stacknum'];

$newcolor = $this->datacolor[$idx];
// If we change the stack
if ($oldstacknum == -1 || $arrayofgroupslegend[$i]['stacknum'] != $oldstacknum) {
if ($oldstacknum == -1 || $idx != $oldstacknum) {
$iinstack = 0;
}

Expand Down

0 comments on commit f1e39b0

Please sign in to comment.