From 194d60f4753c8e2d2cd4bb020b146db5280acc48 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Tue, 22 Feb 2022 21:51:29 +0100 Subject: [PATCH] Auto-fix various Psalm-issues --- lib/SimpleSAML/SessionHandler.php | 4 ++-- lib/SimpleSAML/Stats.php | 1 + modules/core/lib/Auth/Process/PHP.php | 2 +- modules/saml/lib/IdP/SQLNameID.php | 4 ++-- tests/lib/SimpleSAML/Utils/TranslateTest.php | 2 +- .../SimpleSAML/XHTML/TemplateTranslationTest.php | 8 ++++---- .../core/lib/Auth/Process/TargetedIDTest.php | 14 +++++++------- tests/modules/unittest/hooks/hook_valid.php | 2 +- www/_include.php | 7 +++++-- 9 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/SimpleSAML/SessionHandler.php b/lib/SimpleSAML/SessionHandler.php index c69e8f233..324c4f521 100644 --- a/lib/SimpleSAML/SessionHandler.php +++ b/lib/SimpleSAML/SessionHandler.php @@ -34,11 +34,11 @@ abstract class SessionHandler * The session handler will be instantiated if this is the first call * to this function. * - * @return \SimpleSAML\SessionHandler The current session handler. + * @return null|self The current session handler. * * @throws \Exception If we cannot instantiate the session handler. */ - public static function getSessionHandler(): SessionHandler + public static function getSessionHandler(): ?self { if (self::$sessionHandler === null) { self::createSessionHandler(); diff --git a/lib/SimpleSAML/Stats.php b/lib/SimpleSAML/Stats.php index 6176cbe87..4b3d020ac 100644 --- a/lib/SimpleSAML/Stats.php +++ b/lib/SimpleSAML/Stats.php @@ -71,6 +71,7 @@ class Stats * @param string $event The event. * @param array $data Event data. Optional. * + * @return false|null */ public static function log(string $event, array $data = []) { diff --git a/modules/core/lib/Auth/Process/PHP.php b/modules/core/lib/Auth/Process/PHP.php index d2005eec3..b6706c4a0 100644 --- a/modules/core/lib/Auth/Process/PHP.php +++ b/modules/core/lib/Auth/Process/PHP.php @@ -59,7 +59,7 @@ class PHP extends Auth\ProcessingFilter $function = function ( /** @scrutinizer ignore-unused */ array &$attributes, /** @scrutinizer ignore-unused */ array &$state - ) { + ): void { eval($this->code); }; $function($state['Attributes'], $state); diff --git a/modules/saml/lib/IdP/SQLNameID.php b/modules/saml/lib/IdP/SQLNameID.php index 7a43e1016..b0dda950c 100644 --- a/modules/saml/lib/IdP/SQLNameID.php +++ b/modules/saml/lib/IdP/SQLNameID.php @@ -85,7 +85,7 @@ class SQLNameID /** * @param array $config */ - private static function create(array $config = []) + private static function create(array $config = []): void { $store = empty($config) ? self::getStore() : null; $table = self::tableName($config); @@ -134,7 +134,7 @@ class SQLNameID * @param string $table The table name. * @param array $config */ - private static function createTable(string $table, array $config = []) + private static function createTable(string $table, array $config = []): void { $query = 'CREATE TABLE ' . $table . ' ( _idp VARCHAR(256) NOT NULL, diff --git a/tests/lib/SimpleSAML/Utils/TranslateTest.php b/tests/lib/SimpleSAML/Utils/TranslateTest.php index f94c72cee..c4d042cdc 100644 --- a/tests/lib/SimpleSAML/Utils/TranslateTest.php +++ b/tests/lib/SimpleSAML/Utils/TranslateTest.php @@ -64,7 +64,7 @@ class TranslateTest extends TestCase $this->filesystem->remove($this->tempdir); } - protected function checkAllFilesAreCompiledTemplates(string $dir) + protected function checkAllFilesAreCompiledTemplates(string $dir): void { $finder = new Finder(); $finder->files()->in($dir); diff --git a/tests/lib/SimpleSAML/XHTML/TemplateTranslationTest.php b/tests/lib/SimpleSAML/XHTML/TemplateTranslationTest.php index 7d8df502d..3a5c6bf57 100644 --- a/tests/lib/SimpleSAML/XHTML/TemplateTranslationTest.php +++ b/tests/lib/SimpleSAML/XHTML/TemplateTranslationTest.php @@ -34,7 +34,7 @@ class TemplateTranslationTest extends TestCase 'test 2' => [1, 2], ]; - $getContent = function () { + $getContent = function (): string { /** @var \SimpleSAML\XHTML\Template $this */ return $this->getContents(); }; @@ -57,7 +57,7 @@ class TemplateTranslationTest extends TestCase $t->data['rememberMeEnabled'] = false; $t->data['stateparams'] = []; - $getContent = function () { + $getContent = function (): string { /** @var \SimpleSAML\XHTML\Template $this */ return $this->getContents(); }; @@ -91,7 +91,7 @@ class TemplateTranslationTest extends TestCase ], ]; - $getContent = function () { + $getContent = function (): string { /** @var \SimpleSAML\XHTML\Template $this */ return $this->getContents(); }; @@ -112,7 +112,7 @@ class TemplateTranslationTest extends TestCase $t->data['trackid'] = ''; $t->data['authData'] = false; - $getContent = function () { + $getContent = function (): string { /** @var \SimpleSAML\XHTML\Template $this */ return $this->getContents(); }; diff --git a/tests/modules/core/lib/Auth/Process/TargetedIDTest.php b/tests/modules/core/lib/Auth/Process/TargetedIDTest.php index 305445536..27387a74f 100644 --- a/tests/modules/core/lib/Auth/Process/TargetedIDTest.php +++ b/tests/modules/core/lib/Auth/Process/TargetedIDTest.php @@ -61,7 +61,7 @@ class TargetedIDTest extends TestCase /** * Test the most basic functionality */ - public function testBasic() + public function testBasic(): void { $config = ['identifyingAttribute' => 'uid']; $request = [ @@ -78,7 +78,7 @@ class TargetedIDTest extends TestCase * Test with src and dst entityIds. * Make sure to overwrite any present eduPersonTargetedId */ - public function testWithSrcDst() + public function testWithSrcDst(): void { $config = ['identifyingAttribute' => 'uid']; $request = [ @@ -107,7 +107,7 @@ class TargetedIDTest extends TestCase /** * Test with nameId config option set. */ - public function testNameIdGeneration() + public function testNameIdGeneration(): void { $nameid = new NameID(); $nameid->setFormat(Constants::NAMEID_PERSISTENT); @@ -151,7 +151,7 @@ class TargetedIDTest extends TestCase /** * Test the outcome to make sure the algorithm remains unchanged */ - public function testOutcome() + public function testOutcome(): void { $config = ['identifyingAttribute' => 'uid']; $request = [ @@ -167,7 +167,7 @@ class TargetedIDTest extends TestCase /** * Test the outcome when multiple values are given */ - public function testOutcomeMultipleValues() + public function testOutcomeMultipleValues(): void { $config = ['identifyingAttribute' => 'uid']; $request = [ @@ -183,7 +183,7 @@ class TargetedIDTest extends TestCase /** * Test that Id is the same for subsequent invocations with same input. */ - public function testIdIsPersistent() + public function testIdIsPersistent(): void { $config = ['identifyingAttribute' => 'uid']; $request = [ @@ -216,7 +216,7 @@ class TargetedIDTest extends TestCase /** * Test that Id is different for two different usernames and two different sp's */ - public function testIdIsUnique() + public function testIdIsUnique(): void { $config = ['identifyingAttribute' => 'uid']; $request = [ diff --git a/tests/modules/unittest/hooks/hook_valid.php b/tests/modules/unittest/hooks/hook_valid.php index b45dcd25e..d264360ae 100644 --- a/tests/modules/unittest/hooks/hook_valid.php +++ b/tests/modules/unittest/hooks/hook_valid.php @@ -8,7 +8,7 @@ use SimpleSAML\Auth; * * @param array &$data Some data */ -function unittest_hook_valid(array &$data) +function unittest_hook_valid(array &$data): void { $data['summary'][] = 'success'; } diff --git a/www/_include.php b/www/_include.php index fab854a12..c18e3a9da 100644 --- a/www/_include.php +++ b/www/_include.php @@ -4,7 +4,7 @@ require_once(dirname(dirname(__FILE__)) . '/lib/_autoload.php'); // show error page on unhandled exceptions -function SimpleSAML_exception_handler($exception) +function SimpleSAML_exception_handler($exception): void { \SimpleSAML\Module::callHooks('exception_handler', $exception); @@ -22,13 +22,16 @@ function SimpleSAML_exception_handler($exception) set_exception_handler('SimpleSAML_exception_handler'); // log full backtrace on errors and warnings +/** + * @return false + */ function SimpleSAML_error_handler( $errno, $errstr, $errfile = null, $errline = 0, /** @scrutinizer ignore-unused */ $errcontext = null -) { +): bool { if (\SimpleSAML\Logger::isErrorMasked($errno)) { // masked error return false; -- GitLab