Skip to content

Commit

Permalink
Github Actions: Add Phpstan (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Sep 6, 2023
2 parents 062ba04 + bd355b5 commit ca78cf1
Show file tree
Hide file tree
Showing 22 changed files with 1,539 additions and 76 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ jobs:
tools: phpcs

- name: Setup dependencies
run: composer require -n --no-progress overtrue/phplint
run: |
composer require -n --no-progress overtrue/phplint
git clone --depth 1 https://github.com/Icinga/icingaweb2.git vendor/icingaweb2
git clone --depth 1 https://github.com/Icinga/icingadb-web.git vendor/icingadb
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-pdfexport.git vendor/pdfexport
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-library.git vendor/icinga-php-library
git clone --depth 1 -b snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git vendor/icinga-php-thirdparty
- name: PHP Lint
if: success() || matrix.allow_failure
if: ${{ ! cancelled() }}
run: ./vendor/bin/phplint -n --exclude={^vendor/.*} -- .

- name: PHP CodeSniffer
if: success() || matrix.allow_failure
if: ${{ ! cancelled() }}
run: phpcs -wps --colors

- name: PHPStan
if: ${{ ! cancelled() }}
uses: php-actions/phpstan@v3
1 change: 1 addition & 0 deletions application/clicommands/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function defaultAction()
$this->fail($this->translate('Argument id is mandatory'));
}

/** @var Model\Report $report */
$report = Model\Report::on($this->getDb())
->with('timeframe')
->filter(Filter::equal('id', $id))
Expand Down
4 changes: 2 additions & 2 deletions application/clicommands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function indexAction()
}

if ($reports->count() === 0) {
printf($this->translate("No reports found\n"));
print $this->translate("No reports found\n");
exit;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ protected function outputTable($reports, array $dataCallbacks)
$beautifier .= "\n";

printf($format, ...array_keys($columnsAndLengths));
printf($beautifier);
print $beautifier;

foreach ($rows as $row) {
printf($format, ...$row);
Expand Down
16 changes: 11 additions & 5 deletions application/controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function init()
{
$reportId = $this->params->getRequired('id');

/** @var Model\Report $report */
$report = Model\Report::on($this->getDb())
->with(['timeframe'])
->filter(Filter::equal('id', $reportId))
Expand Down Expand Up @@ -74,8 +75,8 @@ public function cloneAction()

foreach ($reportlet->getConfig() as $name => $value) {
if ($name === 'name') {
if (preg_match('/(?:Clone )(\d+)$/', $value, $matches)) {
$value = preg_replace('/\d+$/', ++$matches[1], $value);
if (preg_match('/(?:Clone )(\d+)$/', $value, $m)) {
$value = preg_replace('/\d+$/', (string) ((int) $m[1] + 1), $value);
} else {
$value .= ' Clone 1';
}
Expand Down Expand Up @@ -153,7 +154,11 @@ public function scheduleAction()
$form = ScheduleForm::fromReport($this->report);
$form->setAction((string) Url::fromRequest())
->on(ScheduleForm::ON_SUCCESS, function () use ($form) {
$pressedButton = $form->getPressedSubmitElement()->getName();
$pressedButton = $form->getPressedSubmitElement();
if ($pressedButton) {
$pressedButton = $pressedButton->getName();
}

if ($pressedButton === 'remove') {
Notification::success($this->translate('Removed schedule successfully'));
} elseif ($pressedButton === 'send') {
Expand Down Expand Up @@ -192,8 +197,9 @@ public function downloadAction()

switch ($type) {
case 'pdf':
/** @var Hook\PdfexportHook */
Pdfexport::first()->streamPdfFromHtml($this->report->toPdf(), $name);
/** @var Hook\PdfexportHook $exports */
$exports = Pdfexport::first();
$exports->streamPdfFromHtml($this->report->toPdf(), $name);
exit;
case 'csv':
$response = $this->getResponse();
Expand Down
1 change: 1 addition & 0 deletions application/controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function indexAction()

$this->addControl($sortControl);

/** @var Report $report */
foreach ($reports as $report) {
$url = Url::fromPath('reporting/report', ['id' => $report->id])->getAbsoluteUrl('&');

Expand Down
2 changes: 2 additions & 0 deletions application/controllers/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function indexAction()
{
$this->createTabs()->activate('preview');

/** @var Model\Template $template */
$template = Model\Template::on($this->getDb())
->filter(Filter::equal('id', $this->params->getRequired('id')))
->first();
Expand All @@ -50,6 +51,7 @@ public function editAction()

$this->createTabs()->activate('edit');

/** @var Model\Template $template */
$template = Model\Template::on($this->getDb())
->filter(Filter::equal('id', $this->params->getRequired('id')))
->first();
Expand Down
4 changes: 4 additions & 0 deletions application/controllers/TemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function indexAction()

$this->addControl($sortControl);


$tableRows = [];

/** @var Model\Template $template */
foreach ($templates as $template) {
if ($canManage) {
$subjectLink = new Link(
Expand Down
48 changes: 0 additions & 48 deletions application/controllers/TestController.php

This file was deleted.

1 change: 1 addition & 0 deletions application/controllers/TimeframeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TimeframeController extends Controller

public function init()
{
/** @var Model\Timeframe $timeframe */
$timeframe = Model\Timeframe::on($this->getDb())
->filter(Filter::equal('id', $this->params->getRequired('id')))
->first();
Expand Down
2 changes: 1 addition & 1 deletion library/Reporting/Actions/SendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function execute(Report $report, array $config)
$mail = new Mail();

$mail->setFrom(
Config::module('reporting', 'config', 'true')->get('mail', 'from', 'reporting@icinga')
Config::module('reporting', 'config', true)->get('mail', 'from', 'reporting@icinga')
);

if (isset($config['subject'])) {
Expand Down
5 changes: 3 additions & 2 deletions library/Reporting/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Icinga\Data\ResourceFactory;
use ipl\Sql;
use PDO;
use stdClass;

trait Database
{
Expand Down Expand Up @@ -35,7 +36,7 @@ protected function listTimeframes()
->columns(['id', 'name']);

$timeframes = [];

/** @var stdClass $row */
foreach ($this->getDb()->select($select) as $row) {
$timeframes[$row->id] = $row->name;
}
Expand All @@ -50,7 +51,7 @@ protected function listTemplates()
->columns(['id', 'name']);

$templates = [];

/** @var stdClass $row */
foreach ($this->getDb()->select($select) as $row) {
$templates[$row->id] = $row->name;
}
Expand Down
2 changes: 1 addition & 1 deletion library/Reporting/Hook/ReportHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function initConfigForm(Form $form)
/**
* Get the description of the report
*
* @return string
* @return ?string
*/
public function getDescription()
{
Expand Down
4 changes: 2 additions & 2 deletions library/Reporting/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class Mail
/** @var string */
public const DEFAULT_SUBJECT = 'Icinga Reporting';

/** @var string */
/** @var ?string */
protected $from;

/** @var string */
protected $subject = self::DEFAULT_SUBJECT;

/** @var Zend_Mail_Transport_Sendmail */
/** @var ?Zend_Mail_Transport_Sendmail */
protected $transport;

/** @var array */
Expand Down
2 changes: 0 additions & 2 deletions library/Reporting/Reportlet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Reportlet
public static function fromModel(Model\Reportlet $reportletModel): self
{
$reportlet = new static();

$reportlet->id = $reportletModel->id;
$reportlet->class = $reportletModel->class;

$reportletConfig = [
Expand Down
5 changes: 4 additions & 1 deletion library/Reporting/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public function run(): ExtendedPromiseInterface
$deferred->resolve();
});

return $deferred->promise();
/** @var ExtendedPromiseInterface $promise */
$promise = $deferred->promise();

return $promise;
}
}
6 changes: 5 additions & 1 deletion library/Reporting/Web/Forms/ReportForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Reporting\ProvidedReports;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\Form;
use ipl\Html\HtmlDocument;
use ipl\Validator\CallbackValidator;
use ipl\Web\Compat\CompatForm;

Expand Down Expand Up @@ -148,7 +149,10 @@ protected function assemble()
'formnovalidate' => true
]);
$this->registerElement($removeButton);
$this->getElement('submit')->getWrapper()->prepend($removeButton);

/** @var HtmlDocument $wrapper */
$wrapper = $this->getElement('submit')->getWrapper();
$wrapper->prepend($removeButton);
}
}

Expand Down
13 changes: 10 additions & 3 deletions library/Reporting/Web/Forms/ScheduleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use Icinga\Application\Icinga;
use Icinga\Application\Web;
use Icinga\Authentication\Auth;
use Icinga\Module\Reporting\Database;
use Icinga\Module\Reporting\Hook\ActionHook;
Expand All @@ -14,6 +15,7 @@
use Icinga\Util\Json;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\Form;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Scheduler\Contract\Frequency;
use ipl\Web\Compat\CompatForm;
Expand All @@ -35,7 +37,9 @@ class ScheduleForm extends CompatForm
public function __construct()
{
$this->scheduleElement = new ScheduleElement('schedule_element');
$this->scheduleElement->setIdProtector([Icinga::app()->getRequest(), 'protectId']);
/** @var Web $app */
$app = Icinga::app();
$this->scheduleElement->setIdProtector([$app->getRequest(), 'protectId']);
}

public function getPartUpdates(): array
Expand Down Expand Up @@ -122,7 +126,10 @@ protected function assemble()
'formnovalidate' => true
]);
$this->registerElement($sendButton);
$this->getElement('submit')->getWrapper()->prepend($sendButton);

/** @var HtmlDocument $wrapper */
$wrapper = $this->getElement('submit')->getWrapper();
$wrapper->prepend($sendButton);

/** @var FormSubmitElement $removeButton */
$removeButton = $this->createElement('submit', 'remove', [
Expand All @@ -131,7 +138,7 @@ protected function assemble()
'formnovalidate' => true
]);
$this->registerElement($removeButton);
$this->getElement('submit')->getWrapper()->prepend($removeButton);
$wrapper->prepend($removeButton);
}
}

Expand Down
6 changes: 5 additions & 1 deletion library/Reporting/Web/Forms/TemplateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Icinga\Module\Reporting\Database;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\Html;
use ipl\Html\HtmlDocument;
use ipl\Web\Compat\CompatForm;

class TemplateForm extends CompatForm
Expand Down Expand Up @@ -143,7 +144,10 @@ protected function assemble()
'formnovalidate' => true
]);
$this->registerElement($removeButton);
$this->getElement('submit')->getWrapper()->prepend($removeButton);

/** @var HtmlDocument $wrapper */
$wrapper = $this->getElement('submit')->getWrapper();
$wrapper->prepend($removeButton);
}
}

Expand Down
6 changes: 5 additions & 1 deletion library/Reporting/Web/Forms/TimeframeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Icinga\Module\Reporting\Database;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\FormElement\LocalDateTimeElement;
use ipl\Html\HtmlDocument;
use ipl\Validator\CallbackValidator;
use ipl\Web\Compat\CompatForm;

Expand Down Expand Up @@ -174,7 +175,10 @@ protected function assemble()
'formnovalidate' => true
]);
$this->registerElement($removeButton);
$this->getElement('submit')->getWrapper()->prepend($removeButton);

/** @var HtmlDocument $wrapper */
$wrapper = $this->getElement('submit')->getWrapper();
$wrapper->prepend($removeButton);
}
}

Expand Down
6 changes: 3 additions & 3 deletions library/Reporting/Web/Widget/HeaderOrFooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ protected function resolveVariable($variable)

protected function createColumn(array $data, $key)
{
$typeKey = "${key}_type";
$valueKey = "${key}_value";
$type = isset($data[$typeKey]) ? $data[$typeKey] : null;
$typeKey = "{$key}_type";
$valueKey = "{$key}_value";
$type = $data[$typeKey] ?? null;

switch ($type) {
case 'text':
Expand Down
Loading

0 comments on commit ca78cf1

Please sign in to comment.