Skip to content

Commit

Permalink
Github Actions: Add PhpStan (#142)
Browse files Browse the repository at this point in the history
- Add PHPStan static analyser with dynamic property check
- Fix the static analyser tools
  • Loading branch information
nilmerg authored Jul 7, 2023
2 parents 7fc95e8 + fe131e3 commit fbc089f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 40 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:

- name: Setup dependencies
run: composer require -n --no-progress overtrue/phplint
&& git clone --single-branch --branch master https://github.com/Icinga/icingaweb2.git vendor/icingaweb2
&& git clone --single-branch --branch master https://github.com/Icinga/icingadb-web.git vendor/modules/icingadb-web
&& git clone --single-branch --branch snapshot/nightly https://github.com/Icinga/icinga-php-library.git vendor/icinga-php-library
&& git clone --single-branch --branch snapshot/nightly https://github.com/Icinga/icinga-php-thirdparty.git vendor/icinga-php-thirdparty

- name: PHP Lint
if: success() || matrix.allow_failure
Expand All @@ -40,3 +44,7 @@ jobs:
- name: PHP CodeSniffer
if: success() || matrix.allow_failure
run: phpcs -wps --colors

- name: PHPStan
uses: php-actions/phpstan@v3
if: success() || matrix.allow_failure
4 changes: 2 additions & 2 deletions library/Cube/Cube.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

abstract class Cube
{
/** @var string Prefix for slice params */
/** @var ?string Prefix for slice params */
public const SLICE_PREFIX = null;

/** @var bool Whether the icingadb backend is in use */
/** @var ?bool Whether the icingadb backend is in use */
public const IS_USING_ICINGADB = null;

/** @var array<string, Dimension> Available dimensions */
Expand Down
20 changes: 19 additions & 1 deletion library/Cube/Dimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,30 @@ interface Dimension
public function getName();

/**
* The label of this dimension
* Fetch label of this dimension
*
* @return string
*/
public function getLabel();

/**
* Add a label
*
* @param string $label
*
* @return $this
*/
public function addLabel(string $label);

/**
* Set the label for the dimension
*
* @param string $label
*
* @return $this
*/
public function setLabel(string $label);

/**
* Column expression
*
Expand Down
12 changes: 0 additions & 12 deletions library/Cube/IcingaDb/CustomVariableDimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,13 @@ public function getLabel()
return $this->label ?: $this->getName();
}

/**
* Set the label
*
* @param string $label
* @return $this
*/
public function setLabel($label)
{
$this->label = $label;

return $this;
}

/**
* Add a label
*
* @param string $label
* @return $this
*/
public function addLabel($label)
{
if ($this->label === null) {
Expand Down
14 changes: 1 addition & 13 deletions library/Cube/Ido/CustomVarDimension.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,13 @@ public function getLabel()
return $this->varLabel ?: $this->getName();
}

/**
* Set the label
*
* @param string $label
* @return $this
*/
public function setLabel($label)
{
$this->varLabel = $label;

return $this;
}

/**
* Add a label
*
* @param string $label
* @return $this
*/
public function addLabel($label)
{
if ($this->varLabel === null) {
Expand Down Expand Up @@ -138,7 +126,7 @@ public function addToCube(Cube $cube)
$objectId = 'o.object_id';
}
$name = $this->safeVarname($this->varName);
/** @var $cube IdoCube */
/** @var IdoCube $cube */
$alias = $cube->db()->quoteIdentifier(['c_' . $name]);

if ($cube->isPgsql()) {
Expand Down
4 changes: 2 additions & 2 deletions library/Cube/ProvidedHook/Cube/IcingaDbActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Icinga\Module\Cube\Hook\IcingaDbActionsHook;
use Icinga\Module\Cube\IcingaDb\IcingaDbCube;
use Icinga\Module\Cube\Icingadb\IcingadbServiceStatusCube;
use Icinga\Module\Cube\IcingaDb\IcingaDbServiceStatusCube;
use ipl\Stdlib\Filter;
use ipl\Web\Filter\QueryString;
use ipl\Web\Url;
Expand All @@ -14,7 +14,7 @@ class IcingaDbActions extends IcingaDbActionsHook
public function createActionLinks(IcingaDbCube $cube)
{
$type = 'host';
if ($cube instanceof IcingadbServiceStatusCube) {
if ($cube instanceof IcingaDbServiceStatusCube) {
$type = 'service';
}

Expand Down
4 changes: 2 additions & 2 deletions library/Cube/Web/ActionLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function renderAll(Cube $cube, View $view)
try {
$hook->prepareActionLinks($cube, $view);
} catch (Exception $e) {
$html[] = static::renderErrorItem($e, $view);
$html[] = self::renderErrorItem($e, $view);
}

foreach ($hook->getActionLinks()->getLinks() as $link) {
Expand All @@ -50,7 +50,7 @@ public static function renderAll(Cube $cube, View $view)
}

if (empty($html)) {
$html[] = static::renderErrorItem(
$html[] = self::renderErrorItem(
$view->translate('No action links have been provided for this cube'),
$view
);
Expand Down
3 changes: 0 additions & 3 deletions library/Cube/Web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ abstract class Controller extends CompatController
use Database;
use Auth;

/** @var View This helps IDEs to understand that this is not ZF view */
public $view;

/** @var string[] Preserved params for searchbar and search editor controls */
protected $preserveParams = [
'dimensions',
Expand Down
6 changes: 1 addition & 5 deletions library/Cube/Web/IdoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Icinga\Module\Cube\IcingaDb\CustomVariableDimension;
use Icinga\Module\Cube\IcingaDb\IcingaDbCube;
use Icinga\Module\Cube\Ido\IdoCube;
use Icinga\Web\View;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use ipl\Stdlib\Str;
use ipl\Web\Compat\CompatController;
Expand All @@ -19,9 +18,6 @@

abstract class IdoController extends CompatController
{
/** @var View This helps IDEs to understand that this is not ZF view */
public $view;

/**
* Return this controllers' cube
*
Expand Down Expand Up @@ -95,7 +91,7 @@ private function prepareCube(): IdoCube
&& Module::exists('icingadb')
&& $this->hasIcingadbDimensionParams($vars)
) {
$this->transformicingadbDimensionParamsAndRedirect($vars);
$this->transformIcingadbDimensionParamsAndRedirect($vars);
} elseif ($resolved) {
$this->redirectNow(Url::fromRequest()->without('resolved'));
}
Expand Down
16 changes: 16 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
level: 1
checkFunctionNameCase: true
checkMissingIterableValueType: true
checkInternalClassCaseSensitivity: true
checkDynamicProperties: true
paths:
- application
- library
scanDirectories:
- vendor
ignoreErrors:
- '#Unsafe usage of new static\(\)#'
universalObjectCratesClasses:
- Icinga\Web\View
- ipl\Orm\Model

0 comments on commit fbc089f

Please sign in to comment.