Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Actions: Add PHPStan #423

Merged
merged 38 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
78ffc0a
Github Actions: Add PhpStan
sukhwinder33445 Jun 19, 2023
d3c8915
RedisConfigForm: Fix `Variable '$pem' is probably undefined`
sukhwinder33445 Aug 16, 2023
5a64a83
CommandActions: Fix `Variable '$form' is probably undefined`
sukhwinder33445 Aug 16, 2023
106e7ab
UrlMigration: Fix `Variable '$modalPath, $exprRule' are probably unde…
sukhwinder33445 Aug 16, 2023
2a26f28
(Csv/Json)ResultSet::current(): Add phpDoc
sukhwinder33445 Aug 16, 2023
807ef84
CustomVarRendererHook: Remove not used param $object
sukhwinder33445 Aug 16, 2023
49a8455
VolatileStateResults::current(): Add required attribute #[\ReturnType…
sukhwinder33445 Aug 16, 2023
61f6891
(Grid/View)ModeSwitcher: Fix `Variable '$active, $inactive' are proba…
sukhwinder33445 Aug 16, 2023
beffc0f
DowntimeCard: Add `$start, $end` explicitly as non-dynamic property
sukhwinder33445 Aug 16, 2023
bce9c53
ObjectDetail: Fix `Variable '$userQuery' is probably undefined`
sukhwinder33445 Aug 16, 2023
e6a8256
PerfDataTable: Remove unnecessary `if` condition, $col is always set
sukhwinder33445 Aug 16, 2023
0e38493
Models: Fix method name case
sukhwinder33445 Aug 16, 2023
7a3eefb
HostsController: Check `! $compact` as in `ServicesContoller`
sukhwinder33445 Aug 17, 2023
7c66c0e
IcingaRedis: Fix incorrect PhpDoc
sukhwinder33445 Aug 17, 2023
a21e0d2
IcingaRedis: Call private static methods with `self` instead of `static`
sukhwinder33445 Aug 17, 2023
2365d6e
ConpatObject: Fix method name case
sukhwinder33445 Aug 17, 2023
a60ffe8
(Object(s)DetailExtension/ObjectAction)Hook: Fix incorrect var name i…
sukhwinder33445 Aug 17, 2023
87f8728
SlaReport: Fix `Variables '$interval, $boundry, $format' are probably…
sukhwinder33445 Aug 17, 2023
8bcdb9a
Sni: Fix incorrect method name case
sukhwinder33445 Aug 17, 2023
7af6bb7
ObjectSuggestion: Fix incorrect variable type hint
sukhwinder33445 Aug 17, 2023
2d195e0
PerfDataTable: Remove unnecessary loop and $columns[] variable
sukhwinder33445 Aug 18, 2023
1863c7f
PerfDataTable: Remove unnecessory property `$containsSparkline`
sukhwinder33445 Aug 18, 2023
57809e7
PerfDataTable: Don't iterate unnecessarily
sukhwinder33445 Aug 18, 2023
922b09f
PerfDataTable: Use strict comparison
sukhwinder33445 Aug 18, 2023
076fc02
PerfDataTable: Simplify the code
sukhwinder33445 Aug 18, 2023
0ff9cca
PerfDataTable: Respect given $limit
sukhwinder33445 Aug 18, 2023
fce52f6
State: Add missing abstract methods
sukhwinder33445 Aug 21, 2023
960c21d
Create(Hosts/Services)SlaReport: Fix method name case
sukhwinder33445 Aug 21, 2023
239c33a
PerfData: Fix method name case
sukhwinder33445 Aug 21, 2023
d2f1a4d
Add variable type hint to `Icinga::app()`'s returned object
sukhwinder33445 Aug 21, 2023
b1c844d
Sni: Add variable type hint
sukhwinder33445 Aug 21, 2023
030fa31
BaseHistoryListItem: Fix false positive
sukhwinder33445 Aug 21, 2023
fe641e0
CustomVarTable: Import missing class `Closure`
sukhwinder33445 Aug 21, 2023
ad39b11
Controller: `PrintableHtmlDocument::setTitle()` expects string as param
sukhwinder33445 Aug 23, 2023
e4446e6
UrlMigration: Remove unnecessary empty check
sukhwinder33445 Aug 21, 2023
1fa4f3d
Phpstan: Set level to max and add baseline file
sukhwinder33445 Aug 23, 2023
dd230a5
Github Actions: Do not cancel further tests if one fails
sukhwinder33445 Aug 30, 2023
7a9427f
State: Add phpDoc for properties and update phpstan baseline
sukhwinder33445 Sep 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
os: ['ubuntu-latest']

steps:
Expand All @@ -31,16 +31,27 @@ 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/icingaweb2-module-reporting.git vendor/reporting
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-x509.git vendor/x509
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

test:
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/HostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function indexAction()
$hosts->peekAhead($compact);

$this->filter($hosts, $filter);
if (isset($summary)) {
if (! $compact) {
$this->filter($summary, $filter);
yield $this->export($hosts, $summary);
} else {
Expand Down
1 change: 1 addition & 0 deletions application/forms/RedisConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public function onSuccess()
));

$useTls = $this->getElement('redis_tls')->isChecked();
$pem = null;
foreach (['ca', 'cert', 'key'] as $name) {
$textarea = $this->getElement('redis_' . $name . '_pem');
if ($useTls && $textarea !== null && ($pem = $textarea->getValue())) {
Expand Down
1 change: 1 addition & 0 deletions library/Icingadb/Common/CommandActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public function sendCustomNotificationAction()
public function toggleFeaturesAction()
{
$commandObjects = $this->getCommandTargets();
$form = null;
if (count($commandObjects) > 1) {
$this->isGrantedOnCommandTargets('i/am-only-used/to-establish/the-object-auth-cache');
$form = new ToggleObjectFeaturesForm($this->getFeatureStatus());
Expand Down
6 changes: 3 additions & 3 deletions library/Icingadb/Common/IcingaRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected static function fetchState(string $key, array $ids, array $columns): G
*
* @param Redis|null $redis
*
* @return ?float|int
* @return float|int|null
*/
public static function getLastIcingaHeartbeat(Redis $redis = null)
{
Expand Down Expand Up @@ -241,7 +241,7 @@ public static function getPrimaryRedis(Config $moduleConfig = null, Config $redi
'port' => $section->get('port', 6380),
'password' => $section->get('password', ''),
'timeout' => 0.5
] + static::getTlsParams($moduleConfig));
] + self::getTlsParams($moduleConfig));

$redis->ping();

Expand Down Expand Up @@ -278,7 +278,7 @@ public static function getSecondaryRedis(Config $moduleConfig = null, Config $re
'port' => $section->get('port', 6380),
'password' => $section->get('password', ''),
'timeout' => 0.5
] + static::getTlsParams($moduleConfig));
] + self::getTlsParams($moduleConfig));

$redis->ping();

Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Compat/CompatObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function fetchCustomvars(): self
return $this;
}

$this->customvars = (new CustomvarFlat())->unflattenVars($this->object->customvar_flat);
$this->customvars = (new CustomvarFlat())->unFlattenVars($this->object->customvar_flat);

return $this;
}
Expand Down
10 changes: 2 additions & 8 deletions library/Icingadb/Compat/UrlMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ protected function rewrite(Filter\Rule $filter, array $legacyColumns, Filter\Cha
if ($filter instanceof Filter\Condition) {
$column = $filter->getColumn();

$modelPath = null;
$exprRule = null;
if (isset($legacyColumns[$column])) {
if ($legacyColumns[$column] === self::DROP) {
return false;
Expand Down Expand Up @@ -288,10 +290,6 @@ protected static function hostsColumns(): array
}
}

if (empty($columns)) {
return false;
}

return Filter::equal('columns', implode(',', $columns));
},

Expand Down Expand Up @@ -519,10 +517,6 @@ protected static function servicesColumns(): array
}
}

if (empty($columns)) {
return false;
}

return Filter::equal('columns', implode(',', $columns));
},

Expand Down
5 changes: 4 additions & 1 deletion library/Icingadb/Data/CsvResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class CsvResultSet extends ResultSet
{
protected $isCacheDisabled = true;

public function current()
/**
* @return array<string, ?string>
*/
public function current(): array
{
return $this->extractKeysAndValues(parent::current());
}
Expand Down
5 changes: 4 additions & 1 deletion library/Icingadb/Data/JsonResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class JsonResultSet extends ResultSet
{
protected $isCacheDisabled = true;

public function current()
/**
* @return array<string, ?string>
*/
public function current(): array
{
return $this->createObject(parent::current());
}
Expand Down
6 changes: 4 additions & 2 deletions library/Icingadb/Data/PivotTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Module\Icingadb\Data;

use Icinga\Application\Icinga;
use Icinga\Application\Web;
use ipl\Orm\Query;
use ipl\Stdlib\Contract\Paginatable;
use ipl\Stdlib\Filter;
Expand Down Expand Up @@ -209,9 +210,10 @@ public function setYAxisHeader(string $yAxisHeader): self
*/
protected function getPaginationParameter(string $axis, string $param, int $default = null): int
{
$request = Icinga::app()->getRequest();
/** @var Web $app */
$app = Icinga::app();

$value = $request->getParam($param, '');
$value = $app->getRequest()->getParam($param, '');
if (strpos($value, ',') > 0) {
$parts = explode(',', $value, 2);
return intval($parts[$axis === 'x' ? 0 : 1]);
Expand Down
4 changes: 2 additions & 2 deletions library/Icingadb/Hook/ActionsHook/ObjectActionsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ final public static function loadActions(Model $object): HtmlElement
{
switch (true) {
case $object instanceof Host:
/** @var HostActionsHook $hook */
$hookName = 'Icingadb\\HostActions';
break;
case $object instanceof Service:
/** @var ServiceActionsHook $hook */
$hookName = 'Icingadb\\ServiceActions';
break;
default:
Expand All @@ -54,6 +52,8 @@ final public static function loadActions(Model $object): HtmlElement
}

$list = new HtmlElement('ul', Attributes::create(['class' => 'object-detail-actions']));

/** @var HostActionsHook|ServiceActionsHook $hook */
foreach (Hook::all($hookName) as $hook) {
try {
foreach ($hook->getActionsForObject($object) as $link) {
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Hook/CustomVarRendererHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final public static function prepareForObject(Model $object): Closure
}
}

return function (string $key, $value) use ($hooks, $object) {
return function (string $key, $value) use ($hooks) {
$newKey = $key;
$newValue = $value;
$group = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,18 @@ final public static function loadExtensions(Model $object): array
{
switch (true) {
case $object instanceof Host:
/** @var HostDetailExtensionHook $hook */
$hookName = 'Icingadb\\HostDetailExtension';
break;
case $object instanceof Service:
/** @var ServiceDetailExtensionHook $hook */
$hookName = 'Icingadb\\ServiceDetailExtension';
break;
case $object instanceof User:
/** @var UserDetailExtensionHook $hook */
$hookName = 'Icingadb\\UserDetailExtension';
break;
case $object instanceof Usergroup:
/** @var UsergroupDetailExtensionHook $hook */
$hookName = 'Icingadb\\UsergroupDetailExtension';
break;
case $object instanceof History:
/** @var EventDetailExtensionHook $hook */
$hookName = 'Icingadb\\EventDetailExtension';
break;
default:
Expand All @@ -70,6 +65,14 @@ final public static function loadExtensions(Model $object): array

$extensions = [];
$lastUsedLocations = [];

/**
* @var $hook HostDetailExtensionHook
* @var $hook ServiceDetailExtensionHook
* @var $hook UserDetailExtensionHook
* @var $hook UsergroupDetailExtensionHook
* @var $hook EventDetailExtensionHook
*/
foreach (Hook::all($hookName) as $hook) {
$location = $hook->getLocation();
if ($location < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ final public static function loadExtensions(string $objectType, Query $query, Fi
{
switch ($objectType) {
case 'host':
/** @var HostsDetailExtensionHook $hook */
sukhwinder33445 marked this conversation as resolved.
Show resolved Hide resolved
$hookName = 'Icingadb\\HostsDetailExtension';
break;
case 'service':
/** @var ServicesDetailExtensionHook $hook */
$hookName = 'Icingadb\\ServicesDetailExtension';
break;
default:
Expand All @@ -54,6 +52,7 @@ final public static function loadExtensions(string $objectType, Query $query, Fi

$extensions = [];
$lastUsedLocations = [];
/** @var HostsDetailExtensionHook|ServicesDetailExtensionHook $hook */
foreach (Hook::all($hookName) as $hook) {
$location = $hook->getLocation();
if ($location < 0) {
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/CheckcommandArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public function createBehaviors(Behaviors $behaviors)
public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('checkcommand', CheckCommand::class);
$relations->belongsTo('checkcommand', Checkcommand::class);
}
}
2 changes: 1 addition & 1 deletion library/Icingadb/Model/CheckcommandCustomvar.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function createBehaviors(Behaviors $behaviors)
public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('checkcommand', CheckCommand::class);
$relations->belongsTo('checkcommand', Checkcommand::class);
$relations->belongsTo('customvar', Customvar::class);
$relations->belongsTo('customvar_flat', CustomvarFlat::class)
->setCandidateKey('customvar_id')
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/CheckcommandEnvvar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public function createBehaviors(Behaviors $behaviors)
public function createRelations(Relations $relations)
{
$relations->belongsTo('environment', Environment::class);
$relations->belongsTo('checkcommand', CheckCommand::class);
$relations->belongsTo('checkcommand', Checkcommand::class);
}
}
12 changes: 2 additions & 10 deletions library/Icingadb/Model/HostState.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,13 @@ public function createRelations(Relations $relations)
->setJoinType('LEFT');
}

/**
* Get the host state as the textual representation
*
* @return string
*/

public function getStateText(): string
{
return HostStates::text($this->soft_state);
}

/**
* Get the host state as the translated textual representation
*
* @return string
*/

public function getStateTextTranslated(): string
{
return HostStates::text($this->soft_state);
Expand Down
10 changes: 0 additions & 10 deletions library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,11 @@ public function createRelations(Relations $relations)
->setJoinType('LEFT');
}

/**
* Get the host state as the textual representation
*
* @return string
*/
public function getStateText(): string
{
return ServiceStates::text($this->soft_state);
}

/**
* Get the host state as the translated textual representation
*
* @return string
*/
public function getStateTextTranslated(): string
{
return ServiceStates::text($this->soft_state);
Expand Down
Loading