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

phpstan lvl 1 #37

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
matrix:
include:
- {php-version: "7.4"}
- {php-version: "8.1"}
- {php-version: "8.2"}
- {php-version: "8.3-rc"}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
Expand Down Expand Up @@ -51,13 +54,14 @@ jobs:
vendor/bin/licence-headers-check --ansi --no-interaction

tests:
name: "Test on GLPI ${{ matrix.glpi-version }}"
name: "Test on GLPI ${{ matrix.glpi-version }} with PHP ${{ matrix.php-version }}"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
include:
- {glpi-version: "10.0", php-version: "7.4", db-image: "mysql:8.0"}
- {glpi-version: "10.0", php-version: "8.2", db-image: "mysql:8.0"}
services:
app:
image: "ghcr.io/glpi-project/githubactions-php:${{ matrix.php-version }}"
Expand Down Expand Up @@ -95,3 +99,5 @@ jobs:
docker exec ${{ job.services.app.id }} bin/console glpi:database:install --ansi --no-interaction --db-name=glpi --db-host=db --db-user=root --strict-configuration
docker exec ${{ job.services.app.id }} bin/console glpi:plugin:install --ansi --no-interaction --username=glpi oauthimap
docker exec ${{ job.services.app.id }} bin/console glpi:plugin:activate --ansi --no-interaction oauthimap
- name: "PHPStan checks"
run: docker exec ${{ job.services.app.id }} bash -c "cd plugins/oauthimap && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress"
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add phpstan/extension-installer and phpstan/phpstan-deprecation-rules, to be able to trigger errors when a deprecated method is used.

"phpstan/phpstan-deprecation-rules": "^1.1",
"squizlabs/php_codesniffer": "^3.6"
},
"provide": {
Expand All @@ -15,6 +18,9 @@
"platform": {
"php": "7.4.0"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}
174 changes: 166 additions & 8 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 */
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
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
19 changes: 19 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
level: 1
bootstrapFiles:
- ../../inc/based_config.php
- setup.php
paths:
- inc
- front
- ajax
- hook.php
scanDirectories:
- ../../inc
- ../../src
stubFiles:
- ../../stubs/glpi_constants.php
trasher marked this conversation as resolved.
Show resolved Hide resolved
rules:
- GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule
Loading