Skip to content

Commit

Permalink
Add PHPStan checks (level 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher authored and cedric-anne committed Nov 3, 2023
1 parent f20360c commit e75205e
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ jobs:
- name: "PHP_CodeSniffer"
run: |
vendor/bin/phpcs -q --report=checkstyle | vendor/bin/cs2pr
- name: "PHPStan checks"
run: |
vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress --error-format=checkstyle | vendor/bin/cs2pr
- name: "Check for missing/outdated headers"
run: |
vendor/bin/licence-headers-check --ansi --no-interaction
Expand Down
1 change: 1 addition & 0 deletions ajax/dropdownAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

Session::checkLoginUser();

/** @var \DBmysql $DB */
global $DB;

$iterator = $DB->request(
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"php": ">=7.4"
},
"require-dev": {
"glpi-project/tools": "^0.6",
"glpi-project/tools": "^0.7.1",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"squizlabs/php_codesniffer": "^3.6",
"staabm/annotate-pull-request-from-checkstyle": "^1.8"
},
Expand All @@ -16,6 +19,9 @@
"platform": {
"php": "7.4.0"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
172 changes: 165 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion front/application.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

include('../../../inc/includes.php');

/** @var array $_UPOST */
global $_UPOST;

$dropdown = new PluginOauthimapApplication();

if (isset($_POST['id']) && isset($_POST['request_authorization'])) {
Expand All @@ -38,7 +41,7 @@
} else {
Html::requireJs('clipboard');

if (array_key_exists('client_secret', $_POST)) {
if (array_key_exists('client_secret', $_POST) && array_key_exists('client_secret', $_UPOST)) {
// Client secret must not be altered.
$_POST['client_secret'] = $_UPOST['client_secret'];
}
Expand Down
6 changes: 4 additions & 2 deletions inc/application.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ private static function getSupportedProviders(): array
*/
public function getProvider(): ?AbstractProvider
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

if (!$this->areCredentialsValid()) {
Expand Down Expand Up @@ -619,7 +620,7 @@ public function cleanDBonPurge()
*/
public static function install(Migration $migration)
{

/** @var \DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down Expand Up @@ -650,7 +651,8 @@ public static function install(Migration $migration)
KEY `date_mod` (`date_mod`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;
SQL;
$DB->query($query) or die($DB->error());
$method = version_compare(GLPI_VERSION, '10.0.11', '>=') ? 'doQueryOrDie' : 'queryOrDie';
$DB->$method($query);
}

// Add display preferences
Expand Down
6 changes: 4 additions & 2 deletions inc/authorization.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
return;
}

/** @var \DBmysql $DB */
global $DB;

$iterator = $DB->request(
Expand Down Expand Up @@ -555,7 +556,7 @@ public function post_purgeItem()
*/
public static function install(Migration $migration)
{

/** @var \DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down Expand Up @@ -585,7 +586,8 @@ public static function install(Migration $migration)
UNIQUE KEY `unicity` (`$application_fkey`,`email`)
) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;
SQL;
$DB->query($query) or die($DB->error());
$method = version_compare(GLPI_VERSION, '10.0.11', '>=') ? 'doQueryOrDie' : 'queryOrDie';
$DB->$method($query);
} else {
if (!$DB->fieldExists($table, 'refresh_token')) {
// V1.3.1: add new refresh_token field
Expand Down
11 changes: 6 additions & 5 deletions inc/mailcollectorfeature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
}

return CommonGLPI::createTabEntry(MailCollector::getTypeName(Session::getPluralNumber()), $count);
break;
}

return '';
Expand All @@ -68,7 +67,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
{
switch ($item->getType()) {
case PluginOauthimapApplication::class:
MailCollectorFeature::showMailCollectorsForApplication($item, $tabnum);
MailCollectorFeature::showMailCollectorsForApplication($item);
break;
}

Expand Down Expand Up @@ -297,9 +296,10 @@ public static function updateMailCollectorOnAuthorizationCallback(
PluginOauthimapAuthorization $authorization,
array $params = []
): void {
$mailcollector = new MailCollector();
$redirect = $mailcollector->getSearchURL();
if ($success) {
// Store authorized email into MailCollector
$mailcollector = new MailCollector();
$mailcollector_id = $params[$mailcollector->getForeignKeyField()] ?? null;
if ($mailcollector_id !== null && $mailcollector->getFromDB($mailcollector_id)) {
$mailcollector->update(
Expand All @@ -308,10 +308,11 @@ public static function updateMailCollectorOnAuthorizationCallback(
'login' => $authorization->fields['email'],
]
);
$redirect = $mailcollector->getLinkURL();
}
}

Html::redirect($mailcollector->getLinkURL());
Html::redirect($redirect);
}

/**
Expand Down Expand Up @@ -412,7 +413,7 @@ private static function deactivateMailCollectors(string $protocol_type, ?string
* @param string $login
* @param bool $only_active
*
* @return void
* @return array
*/
private static function getAssociatedMailCollectors(
string $protocol_type,
Expand Down
Loading

0 comments on commit e75205e

Please sign in to comment.