From f1e39b0433532bd2ace3bf7d43448beb18d972b1 Mon Sep 17 00:00:00 2001 From: MDW Date: Tue, 15 Oct 2024 00:08:39 +0200 Subject: [PATCH] Qual: Fix phan notices in dolgraph class # Qual: Fix phan notices in dolgraph class This fixes most notices in the dolgraph class. --- dev/tools/phan/baseline.txt | 6 +- htdocs/core/class/dolgraph.class.php | 147 +++++++++++++++++++++++---- 2 files changed, 129 insertions(+), 24 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 9ce6425b6c4e3..7084e2a9564db 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -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'], @@ -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'], diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index b923e1f0f6c33..49a2f02f0040e 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -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 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 /** @@ -59,31 +76,88 @@ 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; /** @@ -91,13 +165,34 @@ class DolGraph */ public $error = ''; + /** + * @var array,int>|array,array,int>> + */ public $bordercolor; // array(R,G,B) + /** + * @var ?array,int> + */ public $bgcolor; // array(R,G,B) + /** + * @var ?array,int> + */ public $bgcolorgrid = array(255, 255, 255); // array(R,G,B) + /** + * @var array,array,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 @@ -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) { @@ -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) { @@ -269,7 +364,7 @@ public function SetTitle($title) /** * Set data * - * @param array $data Data + * @param array $data Data * @return void * @see draw_jflot() for syntax of data array */ @@ -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,array,int>|string> $datacolor Data color array(array(R,G,B),array(R,G,B)...) or array('#......','#......'...) * @return void */ public function SetDataColor($datacolor) @@ -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,array,int>|string> $bordercolor Color array(array(R,G,B),array(R,G,B)...) or array('#FFFFFF','#......'...) * @return void */ public function setBorderColor($bordercolor) @@ -455,7 +550,7 @@ public function SetHeight($h) /** * Set shading * - * @param string $s Shading + * @param int $s Shading * @return void */ public function SetShading($s) @@ -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) @@ -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> $bg_colorgrid array(R,G,B) ou 'onglet' ou 'default' * @return void */ public function SetBgColorGrid($bg_colorgrid = array(255, 255, 255)) @@ -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() { @@ -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() { @@ -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 $arrayofgroupslegend'; $arrayofgroupslegend = array(); //var_dump($this->data); @@ -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] ); @@ -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' } @@ -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; @@ -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; }