From b9bdbbeccd9cee73681f71ba90b7a033bb951d01 Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Sun, 30 Aug 2020 16:23:20 +0200 Subject: [PATCH] Psalm fixes --- lib/SimpleSAML/Auth/Simple.php | 1 + lib/SimpleSAML/Error/Exception.php | 4 ++-- lib/SimpleSAML/Error/UnserializableException.php | 4 ++-- lib/SimpleSAML/Locale/Translate.php | 1 + lib/SimpleSAML/Metadata/SAMLBuilder.php | 2 ++ lib/SimpleSAML/Metadata/Sources/MDQ.php | 4 +--- lib/SimpleSAML/Module.php | 6 ++++-- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/SimpleSAML/Auth/Simple.php b/lib/SimpleSAML/Auth/Simple.php index ac9e5afe8..2be23efc9 100644 --- a/lib/SimpleSAML/Auth/Simple.php +++ b/lib/SimpleSAML/Auth/Simple.php @@ -391,6 +391,7 @@ class Simple $port = ''; } + /** @psalm-var \SimpleSAML\Configuration $this->app_config */ $base = trim($this->app_config->getString( 'baseURL', $scheme . '://' . $host . $port diff --git a/lib/SimpleSAML/Error/Exception.php b/lib/SimpleSAML/Error/Exception.php index 5177fd64d..9af638d9e 100644 --- a/lib/SimpleSAML/Error/Exception.php +++ b/lib/SimpleSAML/Error/Exception.php @@ -33,7 +33,7 @@ class Exception extends \Exception /** * The cause of this exception. * - * @var Exception|null + * @var \SimpleSAML\Error\Exception|null */ private $cause = null; @@ -68,7 +68,7 @@ class Exception extends \Exception * * @param \Throwable $e The exception. * - * @return Exception The new exception. + * @return \SimpleSAML\Error\Exception The new exception. */ public static function fromException(Throwable $e): Exception { diff --git a/lib/SimpleSAML/Error/UnserializableException.php b/lib/SimpleSAML/Error/UnserializableException.php index 287475590..5c7d21206 100644 --- a/lib/SimpleSAML/Error/UnserializableException.php +++ b/lib/SimpleSAML/Error/UnserializableException.php @@ -42,8 +42,8 @@ class UnserializableException extends Exception $msg = $original->getMessage(); $code = $original->getCode(); - if (is_string($code)) { - // PDOException uses a string as the code. Filter it out here. + if (!is_int($code)) { + // PDOException and possibly others use a string for the code. Filter it out here. $code = -1; } diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php index abec8afea..5db3acc1e 100644 --- a/lib/SimpleSAML/Locale/Translate.php +++ b/lib/SimpleSAML/Locale/Translate.php @@ -526,6 +526,7 @@ class Translate // we don't have a translation for the current language, load alternative priorities $sspcfg = Configuration::getInstance(); + /** @psalm-var \SimpleSAML\Configuration $langcfg */ $langcfg = $sspcfg->getConfigItem('language'); $priorities = $langcfg->getArray('priorities', []); diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php index 04a1b5d33..60adb3003 100644 --- a/lib/SimpleSAML/Metadata/SAMLBuilder.php +++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php @@ -155,6 +155,8 @@ class SAMLBuilder $metadata = Configuration::loadFromArray($metadata, $metadata['entityid']); $defaultEndpoint = $metadata->getDefaultEndpoint('SingleSignOnService'); + + /** @psalm-suppress UndefinedClass */ $e = new SecurityTokenServiceType(); $e->setLocation($defaultEndpoint['Location']); diff --git a/lib/SimpleSAML/Metadata/Sources/MDQ.php b/lib/SimpleSAML/Metadata/Sources/MDQ.php index e98bcf212..833ae7608 100644 --- a/lib/SimpleSAML/Metadata/Sources/MDQ.php +++ b/lib/SimpleSAML/Metadata/Sources/MDQ.php @@ -247,9 +247,7 @@ class MDQ extends \SimpleSAML\Metadata\MetaDataStorageSource case 'shib13-sp-remote': return $entity->getMetadata1xSP(); case 'attributeauthority-remote': - $ret = $entity->getAttributeAuthorities(); - return $ret[0]; - + return $entity->getAttributeAuthorities(); default: Logger::warning(__CLASS__ . ': unknown metadata set: \'' . $set . '\'.'); } diff --git a/lib/SimpleSAML/Module.php b/lib/SimpleSAML/Module.php index 861452149..c68cf5e36 100644 --- a/lib/SimpleSAML/Module.php +++ b/lib/SimpleSAML/Module.php @@ -187,7 +187,7 @@ class Module $request->request->all(), $request->attributes->all(), $request->cookies->all(), - $request_files ?? [], + $request_files, $request->server->all(), $request->getContent() ); @@ -291,14 +291,16 @@ class Module } } + /** @psalm-var \SimpleSAML\Configuration $assetConfig */ $assetConfig = $config->getConfigItem('assets'); + /** @psalm-var \SimpleSAML\Configuration $cacheConfig */ $cacheConfig = $assetConfig->getConfigItem('caching'); $response = new BinaryFileResponse($path); $response->setCache([ // "public" allows response caching even if the request was authenticated, // which is exactly what we want for static resources 'public' => true, - 'max_age' => (string)$cacheConfig->getInteger('max_age', 86400) + 'max_age' => strval($cacheConfig->getInteger('max_age', 86400)) ]); $response->setAutoLastModified(); if ($cacheConfig->getBoolean('etag', false)) { -- GitLab