From 3bc447608b7aed93ad5d7ac22a8bc765f4704c5e Mon Sep 17 00:00:00 2001 From: marco76tv Date: Tue, 5 Sep 2023 11:05:22 +0200 Subject: [PATCH] rector --- .github/workflows/rector.yaml | 31 ++++++++++ Actions/Chart/GetTypeOptions.php | 2 +- Actions/JpGraph/ApplyGraphStyleAction.php | 32 +++++----- Actions/JpGraph/ApplyPlotStyleAction.php | 42 ++++++------- Actions/JpGraph/GetGraphAction.php | 64 ++++++++++---------- Actions/JpGraph/V1/Bar2Action.php | 26 ++++---- Actions/JpGraph/V1/Bar3Action.php | 14 ++--- Actions/JpGraph/V1/Horizbar1Action.php | 12 ++-- Actions/JpGraph/V1/LineSubQuestionAction.php | 6 +- Actions/JpGraph/V1/Pie1Action.php | 40 ++++++------ Actions/JpGraph/V1/PieAvgAction.php | 24 ++++---- Datas/AnswerData.php | 12 ++-- Datas/AnswersChartData.php | 11 +--- Datas/ChartData.php | 26 ++++---- Models/BaseModel.php | 9 +-- Models/Chart.php | 5 +- Models/MixedChart.php | 4 +- Routes/api.php | 4 +- Tables/Columns/ChartColumn.php | 8 +-- 19 files changed, 190 insertions(+), 182 deletions(-) create mode 100644 .github/workflows/rector.yaml diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml new file mode 100644 index 000000000..e41c939fb --- /dev/null +++ b/.github/workflows/rector.yaml @@ -0,0 +1,31 @@ +# Inspiration https://github.com/symplify/symplify/blob/main/.github/workflows/rector.yaml +name: Rector + +on: + pull_request: null + +jobs: + rector: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + token: "${{ secrets.ACCESS_TOKEN || secrets.GITHUB_TOKEN }}" + + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + + - uses: "ramsey/composer-install@v2" + + - run: vendor/bin/rector --ansi + + - uses: EndBug/add-and-commit@v5.1.0 + with: + add: . + message: "[ci-review] Rector Rectify" + author_name: "GitHub Action" + author_email: "action@github.com" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Actions/Chart/GetTypeOptions.php b/Actions/Chart/GetTypeOptions.php index 027e29998..dfc74e575 100644 --- a/Actions/Chart/GetTypeOptions.php +++ b/Actions/Chart/GetTypeOptions.php @@ -44,6 +44,6 @@ public function execute(): array $data[$k1] = 'mixed:' . $v; } - return array_merge($options, $data); + return [...$options, ...$data]; } } diff --git a/Actions/JpGraph/ApplyGraphStyleAction.php b/Actions/JpGraph/ApplyGraphStyleAction.php index e1ddea80b..67f5ecfa5 100644 --- a/Actions/JpGraph/ApplyGraphStyleAction.php +++ b/Actions/JpGraph/ApplyGraphStyleAction.php @@ -13,51 +13,51 @@ class ApplyGraphStyleAction { use QueueableAction; - public function execute(Graph &$graph, ChartData $chart): Graph + public function execute(Graph &$graph, ChartData $chartData): Graph { // Nice shadow $graph->SetShadow(); - $graph->SetBox($chart->show_box); + $graph->SetBox($chartData->show_box); - $graph->footer->right->SetFont($chart->font_family, $chart->font_style); + $graph->footer->right->SetFont($chartData->font_family, $chartData->font_style); // $graph->footer->right->Set('Totale Risposte '.$this->vars['tot']); if (null !== $graph->xaxis) { - $this->applyGraphXStyle($graph->xaxis, $chart); + $this->applyGraphXStyle($graph->xaxis, $chartData); } if (null !== $graph->yaxis) { - $this->applyGraphYStyle($graph->yaxis, $chart); + $this->applyGraphYStyle($graph->yaxis, $chartData); } return $graph; } - public function applyGraphXStyle(Axis &$xaxis, ChartData $data): void + public function applyGraphXStyle(Axis &$axis, ChartData $chartData): void { - $xaxis->SetFont($data->font_family, $data->font_style, $data->font_size); - $xaxis->SetLabelAngle($data->x_label_angle); + $axis->SetFont($chartData->font_family, $chartData->font_style, $chartData->font_size); + $axis->SetLabelAngle($chartData->x_label_angle); // Some extra margin looks nicer - $xaxis->SetLabelMargin($data->x_label_margin); + $axis->SetLabelMargin($chartData->x_label_margin); // Label align for X-axis // $graph->xaxis->SetLabelAlign('right', 'center'); } - public function applyGraphYStyle(Axis &$yaxis, ChartData $data): void + public function applyGraphYStyle(Axis &$axis, ChartData $chartData): void { // Add some grace to y-axis so the bars doesn't go // all the way to the end of the plot area // "restringe" la visualizzazione delle barre - $yaxis->scale->SetGrace($data->y_grace); + $axis->scale->SetGrace($chartData->y_grace); // dddx($style['yaxis_hide']); // We don't want to display Y-axis // visualizza delle colonne verticali "in sottofondo/di riferimento" // if (null == $data->yaxis_hide || 0 == $data->yaxis_hide) { - if ($data->yaxis_hide) { - $yaxis->Hide(); + if ($chartData->yaxis_hide) { + $axis->Hide(); } - $yaxis->HideZeroLabel(); - $yaxis->HideLine(false); - $yaxis->HideTicks(false, false); + $axis->HideZeroLabel(); + $axis->HideLine(false); + $axis->HideTicks(false, false); } } diff --git a/Actions/JpGraph/ApplyPlotStyleAction.php b/Actions/JpGraph/ApplyPlotStyleAction.php index 0b4308e94..090f6ac16 100644 --- a/Actions/JpGraph/ApplyPlotStyleAction.php +++ b/Actions/JpGraph/ApplyPlotStyleAction.php @@ -12,68 +12,66 @@ class ApplyPlotStyleAction { use QueueableAction; - public function execute(BarPlot $plot, ChartData $data): BarPlot + public function execute(BarPlot $barPlot, ChartData $chartData): BarPlot { - $colors = []; - // $plot->SetFillColor($colors); // trasparenza, da 0 a 1 // $plot->SetFillColor($this->data[5]['color'].'@'.$this->vars['transparency']); // trasparenza, da 0 a 1 - $plot->SetFillColor($data->list_color ?? 'red@' . $data->transparency); // trasparenza, da 0 a 1 + $barPlot->SetFillColor($chartData->list_color ?? 'red@' . $chartData->transparency); // trasparenza, da 0 a 1 // $bplot->SetShadow('darkgreen', 1, 1); // dddx([get_defined_vars(), $this->vars]); - $plot->SetColor($data->list_color ?? 'red'); + $barPlot->SetColor($chartData->list_color ?? 'red'); // You can change the width of the bars if you like - $plot->SetWidth($data->plot_perc_width / 100); + $barPlot->SetWidth($chartData->plot_perc_width / 100); // $plot->SetWidth(10); // We want to display the value of each bar at the top // se tolto non mostra i valori // Right side of || is always false. // if (null == $data->plot_value_show || 0 == $data->plot_value_show) { - if ($data->plot_value_show) { - $plot->value->Show(); + if ($chartData->plot_value_show) { + $barPlot->value->Show(); } - $plot->value->SetFont($data->font_family, $data->font_style, $data->font_size); + $barPlot->value->SetFont($chartData->font_family, $chartData->font_style, $chartData->font_size); - $plot->value->SetAlign('left', 'center'); + $barPlot->value->SetAlign('left', 'center'); // colore del font che scrivi - if (null !== $data->plot_value_color) { - $plot->value->SetColor($data->plot_value_color); + if (null !== $chartData->plot_value_color) { + $barPlot->value->SetColor($chartData->plot_value_color); } else { - $plot->value->SetColor('black', 'darkred'); + $barPlot->value->SetColor('black', 'darkred'); } // visualizza il risultato con % oppure no // $plot->value->SetFormat('%.2f %'); // 2f significa 2 cifre decimali, 1f solo una cifra decimale - switch ($data->plot_value_format) { + switch ($chartData->plot_value_format) { case 1: - $plot->value->SetFormat('%.1f %'); + $barPlot->value->SetFormat('%.1f %'); break; case 2: - $plot->value->SetFormat('%.1f'); + $barPlot->value->SetFormat('%.1f'); break; case 3: - $plot->value->SetFormat('%.0f'); + $barPlot->value->SetFormat('%.0f'); break; default: - $plot->value->SetFormat('%.1f %'); + $barPlot->value->SetFormat('%.1f %'); } // Center the values in the bar // if (null == $data->plot_value_pos || 0 == $data->plot_value_pos) { - if (0 === $data->plot_value_pos) { - $plot->SetValuePos('center'); + if (0 === $chartData->plot_value_pos) { + $barPlot->SetValuePos('center'); } - $plot->value->setAngle($data->x_label_angle); + $barPlot->value->setAngle($chartData->x_label_angle); // $plot->value->setAngle(50); - return $plot; + return $barPlot; } } diff --git a/Actions/JpGraph/GetGraphAction.php b/Actions/JpGraph/GetGraphAction.php index b4a865e44..ae852bf33 100644 --- a/Actions/JpGraph/GetGraphAction.php +++ b/Actions/JpGraph/GetGraphAction.php @@ -14,71 +14,71 @@ class GetGraphAction { use QueueableAction; - public function execute(ChartData $data): Graph + public function execute(ChartData $chartData): Graph { - $graph = new Graph($data->width, $data->height, 'auto'); + $graph = new Graph($chartData->width, $chartData->height, 'auto'); $graph->SetScale('textlin'); $graph->SetShadow(); - $theme_class = new UniversalTheme; + $universalTheme = new UniversalTheme; - $graph->SetTheme($theme_class); + $graph->SetTheme($universalTheme); - if (isset($data->min)) { - $graph->yscale->SetAutoMin($data->min); + if (isset($chartData->min)) { + $graph->yscale->SetAutoMin($chartData->min); } - if (isset($data->max)) { - $graph->yscale->SetAutoMax($data->max); + if (isset($chartData->max)) { + $graph->yscale->SetAutoMax($chartData->max); } - if (isset($data->title)) { - $graph->title->Set($data->title); - $graph->title->SetFont($data->font_family, $data->font_style, 11); + if ($chartData->title !== null) { + $graph->title->Set($chartData->title); + $graph->title->SetFont($chartData->font_family, $chartData->font_style, 11); } - if (isset($data->subtitle)) { - $graph->subtitle->Set($data->subtitle); - $graph->subtitle->SetFont($data->font_family, $data->font_style, 11); + if ($chartData->subtitle !== null) { + $graph->subtitle->Set($chartData->subtitle); + $graph->subtitle->SetFont($chartData->font_family, $chartData->font_style, 11); } - if (isset($data->footer)) { - $graph->footer->center->Set($data->footer); - $graph->footer->center->SetFont($data->font_family, $data->font_style, 10); + if ($chartData->footer !== null) { + $graph->footer->center->Set($chartData->footer); + $graph->footer->center->SetFont($chartData->font_family, $chartData->font_style, 10); } - $graph->SetBox($data->show_box); + $graph->SetBox($chartData->show_box); - $graph->footer->right->SetFont($data->font_family, $data->font_style); + $graph->footer->right->SetFont($chartData->font_family, $chartData->font_style); - $this->applyGraphXStyle($graph->xaxis, $data); - $this->applyGraphYStyle($graph->yaxis, $data); + $this->applyGraphXStyle($graph->xaxis, $chartData); + $this->applyGraphYStyle($graph->yaxis, $chartData); return $graph; } - public function applyGraphXStyle(Axis &$xaxis, ChartData $data): void + public function applyGraphXStyle(Axis &$axis, ChartData $chartData): void { - $xaxis->SetFont($data->font_family, $data->font_style, $data->font_size); - $xaxis->SetLabelAngle($data->x_label_angle); + $axis->SetFont($chartData->font_family, $chartData->font_style, $chartData->font_size); + $axis->SetLabelAngle($chartData->x_label_angle); // Some extra margin looks nicer - $xaxis->SetLabelMargin($data->x_label_margin); + $axis->SetLabelMargin($chartData->x_label_margin); // Label align for X-axis // $graph->xaxis->SetLabelAlign('right', 'center'); } - public function applyGraphYStyle(Axis &$yaxis, ChartData $data): void + public function applyGraphYStyle(Axis &$axis, ChartData $chartData): void { // Add some grace to y-axis so the bars doesn't go // all the way to the end of the plot area // "restringe" la visualizzazione delle barre - $yaxis->scale->SetGrace($data->y_grace); + $axis->scale->SetGrace($chartData->y_grace); // dddx($style['yaxis_hide']); // We don't want to display Y-axis // visualizza delle colonne verticali "in sottofondo/di riferimento" // if (null == $data->yaxis_hide || 0 == $data->yaxis_hide) { - if ($data->yaxis_hide) { - $yaxis->Hide(); + if ($chartData->yaxis_hide) { + $axis->Hide(); } - $yaxis->HideZeroLabel(); - $yaxis->HideLine(false); - $yaxis->HideTicks(false, false); + $axis->HideZeroLabel(); + $axis->HideLine(false); + $axis->HideTicks(false, false); } } diff --git a/Actions/JpGraph/V1/Bar2Action.php b/Actions/JpGraph/V1/Bar2Action.php index fa760c295..96fffd55f 100644 --- a/Actions/JpGraph/V1/Bar2Action.php +++ b/Actions/JpGraph/V1/Bar2Action.php @@ -19,19 +19,19 @@ class Bar2Action { use QueueableAction; - public function execute(AnswersChartData $answerChartData): Graph + public function execute(AnswersChartData $answersChartData): Graph { - $data = $answerChartData->answers->toCollection()->pluck('avg')->all(); - $data1 = $answerChartData->answers->toCollection()->pluck('value')->all(); + $data = $answersChartData->answers->toCollection()->pluck('avg')->all(); + $data1 = $answersChartData->answers->toCollection()->pluck('value')->all(); $legends = [0]; if (isset($data1[0]) && is_array($data1[0])) { // questionario multiplo $legends = array_keys($data1[0]); - $data = $answerChartData->answers->toCollection()->pluck('value')->all(); - $data1 = $answerChartData->answers->toCollection()->pluck('avg')->all(); + $data = $answersChartData->answers->toCollection()->pluck('value')->all(); + $data1 = $answersChartData->answers->toCollection()->pluck('avg')->all(); } - $labels = $answerChartData->answers->toCollection()->pluck('label')->all(); - $chart = $answerChartData->chart; + $labels = $answersChartData->answers->toCollection()->pluck('label')->all(); + $chart = $answersChartData->chart; $graph = app(GetGraphAction::class)->execute($chart); $graph->img->SetMargin(50, 50, 50, 100); $graph->ygrid->SetFill(false); @@ -41,7 +41,7 @@ public function execute(AnswersChartData $answerChartData): Graph $graph->yaxis->HideTicks(false, false); $graph->yscale->ticks->SupressZeroLabel(false); - $graph->xaxis->SetTickLabels($labels) + 10; + $graph->xaxis->SetTickLabels($labels); /* $bplot = new BarPlot($data); @@ -63,11 +63,7 @@ public function execute(AnswersChartData $answerChartData): Graph $bplot = []; foreach ($legends as $i => $legend) { - if (0 === $legend) { - $tmp_data = $data; - } else { - $tmp_data = array_column($data, $legend); - } + $tmp_data = 0 === $legend ? $data : array_column($data, $legend); // dddx(['data' => $data, 'tmp_data' => $tmp_data]); $tmp = new BarPlot($tmp_data); @@ -91,9 +87,9 @@ public function execute(AnswersChartData $answerChartData): Graph } // Create the grouped bar plot - $gbplot = new GroupBarPlot($bplot); + $groupBarPlot = new GroupBarPlot($bplot); // ...and add it to the graPH - $graph->Add($gbplot); + $graph->Add($groupBarPlot); // $graph->Add($bplot); diff --git a/Actions/JpGraph/V1/Bar3Action.php b/Actions/JpGraph/V1/Bar3Action.php index e228c9d63..597c56509 100644 --- a/Actions/JpGraph/V1/Bar3Action.php +++ b/Actions/JpGraph/V1/Bar3Action.php @@ -21,10 +21,10 @@ class Bar3Action { use QueueableAction; - public function execute(AnswersChartData $answerChartData): Graph + public function execute(AnswersChartData $answersChartData): Graph { - $chart = $answerChartData->chart; - $answers = $answerChartData->answers; + $chart = $answersChartData->chart; + $answers = $answersChartData->answers; $graph = app(GetGraphAction::class)->execute($chart); $graph->img->SetMargin(50, 50, 50, 100); $labels = $answers->toCollection()->pluck('label')->all(); @@ -67,10 +67,10 @@ public function execute(AnswersChartData $answerChartData): Graph } // Create the grouped bar plot - $gbplot = new AccBarPlot($bplot); - $gbplot->SetWidth($chart->plot_perc_width / 100); + $accBarPlot = new AccBarPlot($bplot); + $accBarPlot->SetWidth($chart->plot_perc_width / 100); // ...and add it to the graPH - $graph->Add($gbplot); + $graph->Add($accBarPlot); if (count($datay) > 1) { // dddx($this->data->first()['title_type']); @@ -82,7 +82,7 @@ public function execute(AnswersChartData $answerChartData): Graph $graph->title->SetFont($chart->font_family, $chart->font_style, 11); } - if (isset($chart->totali)) { + if (property_exists($chart, 'totali') && $chart->totali !== null) { $str = ''; foreach ($chart->totali as $k => $v) { $str .= $k . ' ' . $v . ' - '; diff --git a/Actions/JpGraph/V1/Horizbar1Action.php b/Actions/JpGraph/V1/Horizbar1Action.php index bd2ba45f7..970304285 100644 --- a/Actions/JpGraph/V1/Horizbar1Action.php +++ b/Actions/JpGraph/V1/Horizbar1Action.php @@ -17,19 +17,19 @@ class Horizbar1Action { use QueueableAction; - public function execute(AnswersChartData $answerChartData): Graph + public function execute(AnswersChartData $answersChartData): Graph { - $data = $answerChartData->answers->toCollection()->pluck('avg')->all(); + $data = $answersChartData->answers->toCollection()->pluck('avg')->all(); - $labels = $answerChartData->answers->toCollection() + $labels = $answersChartData->answers->toCollection() ->pluck('label') - ->map(static function ($item) { + ->map(static function ($item): string { Assert::string($item); return wordwrap($item, 25, PHP_EOL); }) ->all(); - $chart = $answerChartData->chart; + $chart = $answersChartData->chart; $graph = app(GetGraphAction::class)->execute($chart); $graph->SetScale('textlin'); @@ -39,7 +39,7 @@ public function execute(AnswersChartData $answerChartData): Graph $graph = app(ApplyGraphStyleAction::class)->execute($graph, $chart); - $graph->xaxis->SetTickLabels($labels) + 10; + $graph->xaxis->SetTickLabels($labels); $bplot = new BarPlot($data); // $bplot = $this->applyPlotStyle($bplot); diff --git a/Actions/JpGraph/V1/LineSubQuestionAction.php b/Actions/JpGraph/V1/LineSubQuestionAction.php index 2d857cdd8..6ca04270d 100644 --- a/Actions/JpGraph/V1/LineSubQuestionAction.php +++ b/Actions/JpGraph/V1/LineSubQuestionAction.php @@ -16,10 +16,10 @@ class LineSubQuestionAction { use QueueableAction; - public function execute(AnswersChartData $answerChartData): Graph + public function execute(AnswersChartData $answersChartData): Graph { - $chart = $answerChartData->chart; - $answers = $answerChartData->answers; + $chart = $answersChartData->chart; + $answers = $answersChartData->answers; $graph = app(GetGraphAction::class)->execute($chart); $labels = $answers->toCollection()->pluck('label')->all(); diff --git a/Actions/JpGraph/V1/Pie1Action.php b/Actions/JpGraph/V1/Pie1Action.php index dfdada783..50c323e46 100644 --- a/Actions/JpGraph/V1/Pie1Action.php +++ b/Actions/JpGraph/V1/Pie1Action.php @@ -18,11 +18,11 @@ class Pie1Action { use QueueableAction; - public function execute(AnswersChartData $answerChartData): Graph + public function execute(AnswersChartData $answersChartData): Graph { - $labels = $answerChartData->answers->toCollection()->pluck('label')->all(); - $data = $answerChartData->answers->toCollection()->pluck('avg')->all(); - $chart = $answerChartData->chart; + $labels = $answersChartData->answers->toCollection()->pluck('label')->all(); + $data = $answersChartData->answers->toCollection()->pluck('avg')->all(); + $chart = $answersChartData->chart; // dddx(['labels' => $labels, 'data' => $data, 'answers' => $answers]); // dddx($chart->max); if (isset($chart->max)) { @@ -34,7 +34,7 @@ public function execute(AnswersChartData $answerChartData): Graph $data[] = $other; $labels[] = $chart->answer_value_no_txt; - if (2 === count($labels) && strlen($labels[0]) < 3) { + if (2 === count($labels) && strlen((string) $labels[0]) < 3) { $labels[0] = $chart->answer_value_txt; } } @@ -47,7 +47,7 @@ public function execute(AnswersChartData $answerChartData): Graph $graph = app(ApplyGraphStyleAction::class)->execute($graph, $chart); // Create the pie plot - $p1 = new PiePlotC($data); + $piePlotC = new PiePlotC($data); // $p1->SetSliceColors(explode(',', $chart->list_color)); // trasparenza da 0 a 1, inserito per ogni colore @@ -55,21 +55,21 @@ public function execute(AnswersChartData $answerChartData): Graph foreach ($color_array as $k => $color) { $color_array[$k] = $color . '@' . $chart->transparency; } - $p1->SetSliceColors($color_array); + $piePlotC->SetSliceColors($color_array); - $p1->SetLegends($labels); + $piePlotC->SetLegends($labels); // $graph->legend->SetPos(0.5,0.98,'center','bottom'); // Enable and set policy for guide-lines. Make labels line up vertically - $p1->SetGuideLines(true, false); - $p1->SetGuideLinesAdjust(1.5); + $piePlotC->SetGuideLines(true, false); + $piePlotC->SetGuideLinesAdjust(1.5); // Use percentage values in the legends values (This is also the default) - $p1->SetLabelType(PIE_VALUE_PER); - $p1->value->Show(); + $piePlotC->SetLabelType(PIE_VALUE_PER); + $piePlotC->value->Show(); // $p1->SetMidSize(0.8); - $p1->SetMidSize($chart->plot_perc_width / 100); + $piePlotC->SetMidSize($chart->plot_perc_width / 100); // $mandatory = $chart->mandatory; // if (null === $chart->mandatory) { @@ -82,19 +82,19 @@ public function execute(AnswersChartData $answerChartData): Graph $graph->subtitle->SetFont($chart->font_family, $chart->font_style, 11); // Label font and color setup - $p1->value->SetFont(FF_ARIAL, FS_BOLD, 10); - $p1->value->SetColor('black'); + $piePlotC->value->SetFont(FF_ARIAL, FS_BOLD, 10); + $piePlotC->value->SetColor('black'); // Setup the title on the center circle - $p1->midtitle->Set(''); - $p1->midtitle->SetFont(FF_ARIAL, FS_NORMAL, 10); - $p1->value->SetFormat('%2.1f%%'); + $piePlotC->midtitle->Set(''); + $piePlotC->midtitle->SetFont(FF_ARIAL, FS_NORMAL, 10); + $piePlotC->value->SetFormat('%2.1f%%'); // Set color for mid circle - $p1->SetMidColor('white'); + $piePlotC->SetMidColor('white'); // Add plot to pie graph - $graph->Add($p1); + $graph->Add($piePlotC); return $graph; } diff --git a/Actions/JpGraph/V1/PieAvgAction.php b/Actions/JpGraph/V1/PieAvgAction.php index 54c5baed2..52e06ac33 100644 --- a/Actions/JpGraph/V1/PieAvgAction.php +++ b/Actions/JpGraph/V1/PieAvgAction.php @@ -20,12 +20,12 @@ class PieAvgAction { use QueueableAction; - public function execute(AnswersChartData $answerChartData): Graph + public function execute(AnswersChartData $answersChartData): Graph { - $labels = $answerChartData->answers->toCollection()->pluck('label')->all(); + $labels = $answersChartData->answers->toCollection()->pluck('label')->all(); - $data = $answerChartData->answers->toCollection()->pluck('avg')->all(); - $chart = $answerChartData->chart; + $data = $answersChartData->answers->toCollection()->pluck('avg')->all(); + $chart = $answersChartData->chart; if (isset($chart->max)) { $sum = collect($data)->sum(); $other = $chart->max - $sum; @@ -47,8 +47,8 @@ public function execute(AnswersChartData $answerChartData): Graph $graph = app(ApplyGraphStyleAction::class)->execute($graph, $chart); // Create the pie plot - $p1 = new PiePlotC($data); - $p1->SetStartAngle(180); + $piePlotC = new PiePlotC($data); + $piePlotC->SetStartAngle(180); // trasparenza da 0 a 1, inserito per ogni colore $color_array = explode(',', $chart->list_color); @@ -57,16 +57,16 @@ public function execute(AnswersChartData $answerChartData): Graph $color_array[$k] = $color . '@0.6'; } // dddx($color_array); - $p1->SetSliceColors($color_array); + $piePlotC->SetSliceColors($color_array); // nasconde i label - $p1->value->Show(false); + $piePlotC->value->Show(false); // Set color for mid circle - $p1->SetMidColor('white'); + $piePlotC->SetMidColor('white'); // $p1->SetMidSize(0.8); - $p1->SetMidSize($chart->plot_perc_width / 100); + $piePlotC->SetMidSize($chart->plot_perc_width / 100); $graph->title->Set($chart->title); $graph->title->SetFont($chart->font_family, $chart->font_style, 11); @@ -89,10 +89,10 @@ public function execute(AnswersChartData $answerChartData): Graph $graph->footer->SetMargin(0, 0, $y); // con 0 metto al centro la percentuale - $p1->SetLabelPos(0); + $piePlotC->SetLabelPos(0); // Add plot to pie graph - $graph->Add($p1); + $graph->Add($piePlotC); return $graph; } diff --git a/Datas/AnswerData.php b/Datas/AnswerData.php index 1a990a917..0c0f17f1e 100644 --- a/Datas/AnswerData.php +++ b/Datas/AnswerData.php @@ -8,13 +8,13 @@ class AnswerData extends Data { - public ?string $label; + public ?string $label = null; public int $gid = 0; public float|array $value = 0; public float|array|string $value1 = ''; - public ?string $_key; - public ?string $key; - public ?string $_sub; + public ?string $_key = null; + public ?string $key = null; + public ?string $_sub = null; public ?string $_sort = null; // public ?array $sub_labels; @@ -22,6 +22,6 @@ class AnswerData extends Data public float|array|string $avg = 0; // public int $tot = 1; // public int $tot_nulled = 0; - public ?string $title; - public ?string $subtitle; + public ?string $title = null; + public ?string $subtitle = null; } diff --git a/Datas/AnswersChartData.php b/Datas/AnswersChartData.php index f131797d4..9e39b09f4 100644 --- a/Datas/AnswersChartData.php +++ b/Datas/AnswersChartData.php @@ -41,11 +41,7 @@ public function getChartJsType(): string $type = 'line'; break; case 'bar2': - $type = 'bar'; - break; case 'bar1': - $type = 'bar'; - break; case 'bar3': $type = 'bar'; break; @@ -75,7 +71,7 @@ public function getChartJsData(): array if ($other > 0.01) { $data[] = $other; $labels[] = $this->chart->answer_value_no_txt ?? 'answer_value_no_txt'; - if (2 === count($labels) && strlen((string) $labels[0]) < 3) { + if (2 === count($labels) && strlen($labels[0]) < 3) { $labels[0] = $this->chart->answer_value_txt; } } @@ -102,7 +98,7 @@ public function getChartJsData(): array if ($other > 0.01) { $data[] = $other; $labels[] = $this->chart->answer_value_no_txt ?? 'answer_value_no_txt'; - if (2 === count($labels) && strlen((string) $labels[0]) < 3) { + if (2 === count($labels) && strlen($labels[0]) < 3) { $labels[0] = $this->chart->answer_value_txt; } } @@ -134,7 +130,6 @@ public function getChartJsData(): array public function getChartJsOptions(): array { - $legend_display = true; $title = []; if ('no_set' !== $this->title) { @@ -159,7 +154,7 @@ public function getChartJsOptions(): array 'title' => $title, ]; - if (in_array($this->chart->type, ['horizbar1'])) { + if ($this->chart->type == 'horizbar1') { $options['indexAxis'] = 'y'; } diff --git a/Datas/ChartData.php b/Datas/ChartData.php index 42cb72480..9c52e2637 100644 --- a/Datas/ChartData.php +++ b/Datas/ChartData.php @@ -15,33 +15,33 @@ class ChartData extends Data public float $min; public int $width; public int $height; - public ?string $title; - public ?string $subtitle; + public ?string $title = null; + public ?string $subtitle = null; public string $list_color; // public string $color; // #000000 // non si deve piĆ¹ usare, sostituito da list_color - public ?string $bg_color; // #000000 + public ?string $bg_color = null; // #000000 public string $font_family; public string $font_size; public string $font_style; - public ?int $y_grace; - public ?int $yaxis_hide; + public ?int $y_grace = null; + public ?int $yaxis_hide = null; public string $x_label_angle; public int $show_box; public int $x_label_margin; public int $plot_perc_width; public bool $plot_value_show; - public ?string $plot_value_format; + public ?string $plot_value_format = null; public ?string $plot_value_color = '#000000'; public string $transparency; - public ?string $engine_type; - public ?string $footer; + public ?string $engine_type = null; + public ?string $footer = null; public int $plot_value_pos = 0; - public ?string $answer_value_no_txt; - public ?string $answer_value_txt; + public ?string $answer_value_no_txt = null; + public ?string $answer_value_txt = null; // public ?string $legend; - public ?array $legend; - public ?array $sublabels; - public ?float $avg; + public ?array $legend = null; + public ?array $sublabels = null; + public ?float $avg = null; public function getColors(): array { diff --git a/Models/BaseModel.php b/Models/BaseModel.php index da1250cb5..d27fd5816 100644 --- a/Models/BaseModel.php +++ b/Models/BaseModel.php @@ -48,14 +48,7 @@ abstract class BaseModel extends Model /** * @var array */ - protected $casts = [ - // 'published_at' => 'datetime:Y-m-d', // da verificare - ]; - - /** - * @var array - */ - protected array $dates = ['published_at', 'created_at', 'updated_at']; + protected $casts = ['published_at' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime']; /** * @var string diff --git a/Models/Chart.php b/Models/Chart.php index 067b89c99..8e0617c1b 100644 --- a/Models/Chart.php +++ b/Models/Chart.php @@ -277,11 +277,8 @@ public function getTypeAttribute(?string $value): ?string if (null !== $value) { return $value; } - if (isset($this->attributes['type'])) { - return $this->attributes['type']; - } - return (string) $this->getPanelRow('chart_type', 'type'); + return $this->attributes['type'] ?? (string) $this->getPanelRow('chart_type', 'type'); } public function getWidthAttribute(?string $value): ?int diff --git a/Models/MixedChart.php b/Models/MixedChart.php index 1580ee549..77eee1522 100644 --- a/Models/MixedChart.php +++ b/Models/MixedChart.php @@ -51,8 +51,8 @@ class MixedChart extends BaseModel public function charts(): MorphMany { Relation::morphMap([ - 'question_chart' => 'Modules\Quaeris\Models\QuestionChart', - 'mixed_chart' => 'Modules\Chart\Models\MixedChart', + 'question_chart' => \Modules\Quaeris\Models\QuestionChart::class, + 'mixed_chart' => \Modules\Chart\Models\MixedChart::class, ]); return $this->morphMany(Chart::class, 'post'); diff --git a/Routes/api.php b/Routes/api.php index 9ff57db62..0e066c402 100644 --- a/Routes/api.php +++ b/Routes/api.php @@ -15,6 +15,4 @@ | */ -Route::middleware('auth:api')->get('/chart', static function (Request $request) { - return $request->user(); -}); +\Illuminate\Support\Facades\Route::middleware('auth:api')->get('/chart', static fn(Request $request) => $request->user()); diff --git a/Tables/Columns/ChartColumn.php b/Tables/Columns/ChartColumn.php index 641937d68..6cf05f47e 100644 --- a/Tables/Columns/ChartColumn.php +++ b/Tables/Columns/ChartColumn.php @@ -45,11 +45,11 @@ class ChartColumn extends Column protected string $view = 'chart::tables.columns.chart-column'; - public function setAnswersChartData(AnswersChartData $answersData): self + public function setAnswersChartData(AnswersChartData $answersChartData): self { - $this->chartData = $answersData->getChartJsData(); - $this->chartType = $answersData->getChartJsType(); - $this->chartOptions = $answersData->getChartJsOptions(); + $this->chartData = $answersChartData->getChartJsData(); + $this->chartType = $answersChartData->getChartJsType(); + $this->chartOptions = $answersChartData->getChartJsOptions(); $this->cachedData = null; // dddx([$this->getCachedData(),$this->getData()]);