Skip to content

Commit

Permalink
Github Actions: Add PhpStan (#5040)
Browse files Browse the repository at this point in the history
Blocked by: #5061 
closes #5052, #4920,
#5003
  • Loading branch information
nilmerg committed Aug 23, 2023
2 parents 847ba4f + 2818757 commit 6c68578
Show file tree
Hide file tree
Showing 144 changed files with 26,805 additions and 229 deletions.
17 changes: 14 additions & 3 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 @@ -29,9 +29,16 @@ jobs:
with:
php-version: ${{ matrix.php }}
tools: phpcs
extensions: ldap

- name: Setup dependencies
run: composer require -n --no-progress overtrue/phplint
run: |
composer require -n --no-progress overtrue/phplint
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
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-x509.git vendor/modules/x509-web
git clone --depth 1 https://github.com/Icinga/icingadb-web.git vendor/modules/icingadb-web
git clone --depth 1 https://github.com/Icinga/icingaweb2-module-pdfexport.git vendor/modules/pdfexport-web
- name: PHP Lint
if: success() || matrix.allow_failure
Expand All @@ -41,6 +48,10 @@ jobs:
if: success() || matrix.allow_failure
run: phpcs

- name: PHPStan
uses: php-actions/phpstan@v3
if: success() || matrix.allow_failure

test:
name: Unit tests with php ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -51,7 +62,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']
include:
- php: '7.2'
Expand Down
4 changes: 2 additions & 2 deletions application/clicommands/VersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function showAction()
}
}

printf("%-${maxLength}s %-9s \n", 'MODULE', 'VERSION');
printf("%-{$maxLength}s %-9s \n", 'MODULE', 'VERSION');
foreach ($modules as $module) {
printf("%-${maxLength}s %-9s \n", $module->getName(), $module->getVersion());
printf("%-{$maxLength}s %-9s \n", $module->getName(), $module->getVersion());
}
}
}
2 changes: 1 addition & 1 deletion application/controllers/AuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function loginAction()
if ($authenticated) {
$rememberMe = $rememberMeOld->renew();
$this->getResponse()->setCookie($rememberMe->getCookie());
$rememberMe->persist($rememberMeOld->getAesCrypt()->getIv());
$rememberMe->persist($rememberMeOld->getAesCrypt()->getIV());
}
} catch (RuntimeException $e) {
Logger::error("Can't authenticate user via remember me cookie: %s", $e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/StaticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function imgAction()
}

$s = stat($filePath);
$eTag = sprintf('%x-%x-%x', $s['ino'], $s['size'], (float) str_pad($s['mtime'], 16, '0'));
$eTag = sprintf('%x-%x-%x', $s['ino'], $s['size'], (float) str_pad((string) $s['mtime'], 16, '0'));

$this->getResponse()->setHeader(
'Cache-Control',
Expand Down
7 changes: 4 additions & 3 deletions application/forms/Config/ResourceConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Icinga\Forms\Config\Resource\SshResourceForm;
use Icinga\Web\Form;
use Icinga\Web\Notification;
use Zend_Form_Element;

class ResourceConfigForm extends ConfigForm
{
Expand Down Expand Up @@ -98,7 +99,7 @@ public function add(array $values)
* @param string $name The name of the resource to edit
* @param array $values The values to edit the configuration with
*
* @return array The edited configuration
* @return ConfigObject The edited configuration
*
* @throws InvalidArgumentException In case the resource does not exist
*/
Expand Down Expand Up @@ -134,7 +135,7 @@ public function edit($name, array $values)
*
* @param string $name The name of the resource to remove
*
* @return array The removed resource configuration
* @return ConfigObject The removed resource configuration
*
* @throws InvalidArgumentException In case the resource does not exist
*/
Expand Down Expand Up @@ -294,7 +295,7 @@ public function createElements(array $formData)
*
* @param Form $form
*
* @return Inspection
* @return ?Inspection
*/
public static function inspectResource(Form $form)
{
Expand Down
1 change: 1 addition & 0 deletions application/forms/Config/User/CreateMembershipForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public function onSuccess()
}

$single = null;
$groupName = null;
foreach ($this->getValue('groups') as $backendAndGroup) {
list($backendName, $groupName) = explode(';', $backendAndGroup, 2);
try {
Expand Down
1 change: 1 addition & 0 deletions application/forms/Config/UserGroup/AddMemberForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function onSuccess()
}

$single = null;
$userName = null;
foreach ($userNames as $userName) {
try {
$this->backend->insert(
Expand Down
1 change: 1 addition & 0 deletions application/forms/Navigation/NavigationConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ protected function getItemForm($type)
$className = StringHelper::cname($type, '-') . 'Form';

$form = null;
$classPath = null;
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $module) {
$classPath = 'Icinga\\Module\\'
. ucfirst($module->getName())
Expand Down
6 changes: 3 additions & 3 deletions application/forms/PreferenceForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function onSuccess()
$defaultTheme = Config::app()->get('themes', 'default', StyleSheet::DEFAULT_THEME);

$this->preferences = new Preferences($this->store ? $this->store->load() : array());
$webPreferences = $this->preferences->get('icingaweb', array());
$webPreferences = $this->preferences->get('icingaweb');
foreach ($this->getValues() as $key => $value) {
if ($value === ''
|| $value === null
Expand Down Expand Up @@ -215,6 +215,7 @@ public function createElements(array $formData)
$themeFile = StyleSheet::getThemeFile($formData['theme']);
}

$disabled = [];
if ($themeFile !== null) {
$file = @file_get_contents($themeFile);
if ($file && strpos($file, StyleSheet::LIGHT_MODE_IDENTIFIER) === false) {
Expand Down Expand Up @@ -242,8 +243,7 @@ public function createElements(array $formData)
['src' => $this->getView()->href('img/theme-mode-thumbnail-system.svg')]
) . HtmlElement::create('span', [], $this->translate('System'))
],
'value' => isset($value) ? $value : '',
'disable' => isset($disabled) ? $disabled : [],
'disable' => $disabled,
'escape' => false,
'decorators' => array_merge(
array_slice(self::$defaultElementDecorators, 0, -1),
Expand Down
2 changes: 1 addition & 1 deletion application/forms/RepositoryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ protected function onDeleteRequest()
/**
* Apply the requested mode on the repository
*
* @return bool
* @return ?bool
*/
public function onSuccess()
{
Expand Down
4 changes: 2 additions & 2 deletions application/views/helpers/CreateTicketLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Zend_View_Helper_CreateTicketLinks extends Zend_View_Helper_Abstract
public function createTicketLinks($text)
{
$tickets = $this->view->tickets;
/** @var \Icinga\Application\Hook\TicketHook $tickets */
return isset($tickets) ? $tickets->createLinks($text) : $text;
/** @var \Icinga\Application\Hook\TicketHook|array|null $tickets */
return ! empty($tickets) ? $tickets->createLinks($text) : $text;
}
}
2 changes: 1 addition & 1 deletion library/Icinga/Application/ApplicationBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ protected function detectTimezone()
*/
final protected function setupTimezone()
{
$timezone = $this->detectTimeZone();
$timezone = $this->detectTimezone();
if ($timezone === null || @date_default_timezone_set($timezone) === false) {
date_default_timezone_set(@date_default_timezone_get());
}
Expand Down
13 changes: 7 additions & 6 deletions library/Icinga/Application/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public static function getStartTime()
* otherwise. Use Benchmark::TIME and Benchmark::MEMORY to choose whether
* you prefer to show either time or memory or both in your output
*
* @param int Whether to get time and/or memory summary
* @return string
* @param ?int $what Whether to get time and/or memory summary
*/
public static function dump($what = null)
{
Expand All @@ -95,7 +94,7 @@ public static function dump($what = null)
* Use Benchmark::TIME and Icinga::MEMORY to choose whether you prefer to
* show either time or memory or both in your output
*
* @param int Whether to get time and/or memory summary
* @param ?int $what Whether to get time and/or memory summary
* @return string
*/
public static function renderToText($what = null)
Expand Down Expand Up @@ -131,7 +130,8 @@ public static function renderToText($what = null)
* Use Benchmark::TIME and Benchmark::MEMORY to choose whether you prefer
* to show either time or memory or both in your output
*
* @param int Whether to get time and/or memory summary
* @param ?int $what Whether to get time and/or memory summary
*
* @return string
*/
public static function renderToHtml($what = null)
Expand Down Expand Up @@ -176,8 +176,9 @@ public static function renderToHtml($what = null)
* Use Benchmark::TIME and Benchmark::MEMORY to choose whether you prefer
* to have either time or memory or both in your output
*
* @param int Whether to get time and/or memory summary
* @return array
* @param ?int $what Whether to get time and/or memory summary
*
* @return object
*/
protected static function prepareDataForRendering($what = null)
{
Expand Down
3 changes: 2 additions & 1 deletion library/Icinga/Application/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Icinga\Application;

use Icinga\Exception\NotWritableError;
use Iterator;
use Countable;
use LogicException;
Expand Down Expand Up @@ -405,7 +406,7 @@ public static function app($configname = 'config', $fromDisk = false)
*
* @param string $modulename The name of the module where to look for the requested configuration
* @param string $configname The configuration name (without ini suffix) to read and return
* @param string $fromDisk When set true, the configuration will be read from disk, even
* @param bool $fromDisk When set true, the configuration will be read from disk, even
* if it already has been read
*
* @return Config The requested configuration
Expand Down
2 changes: 1 addition & 1 deletion library/Icinga/Application/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function createInstance($name, $key)
{
$name = self::normalizeHookName($name);

if (!self::has($name, $key)) {
if (!self::has($name)) {
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions library/Icinga/Application/Hook/ConfigFormEventsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function onSuccess(Form $form)
*/
final public static function getLastErrors()
{
return static::$lastErrors;
return self::$lastErrors;
}

/**
Expand Down Expand Up @@ -92,7 +92,7 @@ final public static function runOnSuccess(Form $form)

private static function runEventMethod($eventMethod, Form $form)
{
static::$lastErrors = [];
self::$lastErrors = [];

if (! Hook::has('ConfigFormEvents')) {
return true;
Expand All @@ -109,7 +109,7 @@ private static function runEventMethod($eventMethod, Form $form)
try {
$hook->$eventMethod($form);
} catch (\Exception $e) {
static::$lastErrors[] = $e->getMessage();
self::$lastErrors[] = $e->getMessage();

Logger::error("%s\n%s", $e, IcingaException::getConfidentialTraceAsString($e));

Expand Down
2 changes: 2 additions & 0 deletions library/Icinga/Application/LegacyWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
namespace Icinga\Application;

require_once dirname(__FILE__) . '/Web.php';

use Exception;
use Icinga\Exception\ProgrammingError;

class LegacyWeb extends Web
Expand Down
1 change: 1 addition & 0 deletions library/Icinga/Application/Logger/Writer/StderrWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected function screen()
*/
public function log($severity, $message)
{
$color = null;
switch ($severity) {
case Logger::ERROR:
$color = 'red';
Expand Down
9 changes: 8 additions & 1 deletion library/Icinga/Application/Modules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class Module
*/
private $libdir;

/**
* Config directory
*
* @var string
*/
private $configdir;

/**
* Directory containing translations
*
Expand Down Expand Up @@ -1308,7 +1315,7 @@ protected function registerRoutes()
$router = $this->app->getFrontController()->getRouter();

// TODO: We should not be required to do this. Please check dispatch()
$this->app->getfrontController()->addControllerDirectory(
$this->app->getFrontController()->addControllerDirectory(
$this->getControllerDir(),
$this->getName()
);
Expand Down
2 changes: 1 addition & 1 deletion library/Icinga/Application/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static function getPhpVersion()
/**
* Return the username PHP is running as
*
* @return string
* @return ?string
*/
public static function getPhpUser()
{
Expand Down
5 changes: 4 additions & 1 deletion library/Icinga/Application/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class Web extends EmbeddedWeb
*/
private $user;

/** @var array */
protected $accessibleMenuItems;

/**
* Identify web bootstrap
*
Expand Down Expand Up @@ -243,7 +246,7 @@ public function getSharedNavigation($type)
if ($type === 'dashboard-pane') {
$panes = array();
foreach ($config as $dashletName => $dashletConfig) {
if ($this->hasAccessToSharedNavigationItem($dashletConfig)) {
if ($this->hasAccessToSharedNavigationItem($dashletConfig, $config)) {
// TODO: Throw ConfigurationError if pane or url is missing
$panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url;
}
Expand Down
2 changes: 2 additions & 0 deletions library/Icinga/Authentication/User/LdapUserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
namespace Icinga\Authentication\User;

use DateTime;
use Exception;
use Icinga\Data\ConfigObject;
use Icinga\Data\Inspectable;
use Icinga\Data\Inspection;
use Icinga\Exception\AuthenticationException;
use Icinga\Exception\ProgrammingError;
use Icinga\Exception\QueryException;
use Icinga\Repository\LdapRepository;
use Icinga\Repository\RepositoryQuery;
use Icinga\Protocol\Ldap\LdapException;
Expand Down
2 changes: 2 additions & 0 deletions library/Icinga/Authentication/User/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public static function create($name, ConfigObject $backendConfig = null)
$name
);
}

if ($backendType === 'external') {
$backend = new ExternalBackend($backendConfig);
$backend->setName($name);
Expand Down Expand Up @@ -229,6 +230,7 @@ public static function create($name, ConfigObject $backendConfig = null)
}

$resource = ResourceFactory::createResource($resourceConfig);
$backend = null;
switch ($backendType) {
case 'db':
$backend = new DbUserBackend($resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ protected function joinGroupMembership(RepositoryQuery $query)
*/
protected function persistGroupId($groupName)
{
if (! $groupName || empty($groupName) || is_numeric($groupName)) {
if (empty($groupName) || is_numeric($groupName)) {
return $groupName;
}

Expand Down

0 comments on commit 6c68578

Please sign in to comment.