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 2 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
9 changes: 8 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,15 @@ 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"}
- {glpi-version: "main", php-version: "8.2", db-image: "mysql:8.0"}
trasher marked this conversation as resolved.
Show resolved Hide resolved
services:
app:
image: "ghcr.io/glpi-project/githubactions-php:${{ matrix.php-version }}"
Expand Down Expand Up @@ -95,3 +100,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 }} cd plugins/oauthimap && php vendor/bin/phpstan analyze --ansi --memory-limit=1G --no-interaction --no-progress
cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"require-dev": {
"glpi-project/tools": "^0.6",
"php-parallel-lint/php-parallel-lint": "^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.

"squizlabs/php_codesniffer": "^3.6"
},
"provide": {
Expand Down
66 changes: 64 additions & 2 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
7 changes: 4 additions & 3 deletions inc/mailcollectorfeature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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 @@ -308,10 +308,11 @@ public static function updateMailCollectorOnAuthorizationCallback(
'login' => $authorization->fields['email'],
]
);
Html::redirect($mailcollector->getLinkURL());
Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to redirect to $mailcollector->getLinkURL() even if $success === false, and if we do not have a valid mailcollector ID (this is not an expected usecase), we should redirect to the mail collector list. Indeed Html::back() will probably redirect user on the last page of the external provider OAuth authorization page, and is may result in a redirection loop.

        $mailcollector = new MailCollector();
        $mailcollector_id = $params[$mailcollector->getForeignKeyField()] ?? null;
        if ($mailcollector_id !== null && $mailcollector->getFromDB($mailcollector_id)) {
            if ($success) {
                // Store authorized email into MailCollector
                $mailcollector->update(
                    [
                        'id'    => $mailcollector_id,
                        'login' => $authorization->fields['email'],
                    ]
                );
            }
            Html::redirect($mailcollector->getLinkURL());
        }

        Html::back($mailcollector->getSearchURL());

Copy link
Contributor Author

@trasher trasher Nov 3, 2023

Choose a reason for hiding this comment

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

I'm pretty sure getLinkURL will not work as expected if getFromDB fails; see 0fd143c

}
}

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

/**
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
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
Loading