From 34cbd823eae588a022b0fb0a5b7cb38c17e9abc4 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Sun, 3 Feb 2019 00:11:57 +0100
Subject: [PATCH] Fixes for lib/SimpleSAML/Utils

---
 lib/SimpleSAML/Utils/Arrays.php          |  2 +-
 lib/SimpleSAML/Utils/Auth.php            |  1 +
 lib/SimpleSAML/Utils/Config.php          |  1 +
 lib/SimpleSAML/Utils/Config/Metadata.php |  5 ++
 lib/SimpleSAML/Utils/HTTP.php            |  3 ++
 lib/SimpleSAML/Utils/HttpAdapter.php     | 61 ++++++++++++++++++++++++
 lib/SimpleSAML/Utils/Net.php             |  2 +-
 lib/SimpleSAML/Utils/Random.php          |  2 +-
 lib/SimpleSAML/Utils/XML.php             |  6 +--
 9 files changed, 77 insertions(+), 6 deletions(-)

diff --git a/lib/SimpleSAML/Utils/Arrays.php b/lib/SimpleSAML/Utils/Arrays.php
index c27b198eb..b38d0ca5c 100644
--- a/lib/SimpleSAML/Utils/Arrays.php
+++ b/lib/SimpleSAML/Utils/Arrays.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils;
 
 /**
@@ -8,7 +9,6 @@ namespace SimpleSAML\Utils;
  */
 class Arrays
 {
-
     /**
      * Put a non-array variable into an array.
      *
diff --git a/lib/SimpleSAML/Utils/Auth.php b/lib/SimpleSAML/Utils/Auth.php
index 7cff78b27..61d49b6e9 100644
--- a/lib/SimpleSAML/Utils/Auth.php
+++ b/lib/SimpleSAML/Utils/Auth.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils;
 
 use SimpleSAML\Module;
diff --git a/lib/SimpleSAML/Utils/Config.php b/lib/SimpleSAML/Utils/Config.php
index 5f25f8a0d..663073e00 100644
--- a/lib/SimpleSAML/Utils/Config.php
+++ b/lib/SimpleSAML/Utils/Config.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils;
 
 /**
diff --git a/lib/SimpleSAML/Utils/Config/Metadata.php b/lib/SimpleSAML/Utils/Config/Metadata.php
index 7c66f290c..f20a06c2f 100644
--- a/lib/SimpleSAML/Utils/Config/Metadata.php
+++ b/lib/SimpleSAML/Utils/Config/Metadata.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils\Config;
 
 /**
@@ -106,6 +107,10 @@ class Metadata
         // check the type
         if (!isset($contact['contactType']) || !in_array($contact['contactType'], self::$VALID_CONTACT_TYPES, true)) {
             $types = join(', ', array_map(
+                 /**
+                  * @param string $t
+                  * @return string
+                  */
                 function ($t) {
                     return '"'.$t.'"';
                 },
diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index da6ec639d..4600821ba 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils;
 
 use SimpleSAML\Configuration;
@@ -462,8 +463,10 @@ class HTTP
 
         // data and headers
         if ($getHeaders) {
+            /** @psalm-suppress UndefinedVariable */
             if (isset($http_response_header)) {
                 $headers = [];
+                /** @psalm-suppress UndefinedVariable */
                 foreach ($http_response_header as $h) {
                     if (preg_match('@^HTTP/1\.[01]\s+\d{3}\s+@', $h)) {
                         $headers = []; // reset
diff --git a/lib/SimpleSAML/Utils/HttpAdapter.php b/lib/SimpleSAML/Utils/HttpAdapter.php
index b82392076..53e78f264 100644
--- a/lib/SimpleSAML/Utils/HttpAdapter.php
+++ b/lib/SimpleSAML/Utils/HttpAdapter.php
@@ -11,6 +11,7 @@ class HttpAdapter
 {
     /**
      * @see HTTP::getServerHTTPS()
+     * @return bool
      */
     public function getServerHTTPS()
     {
@@ -19,6 +20,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getServerPort()
+     * @return int
      */
     public function getServerPort()
     {
@@ -27,6 +29,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::addURLParameters()
+     *
+     * @param string $url
+     * @param array $parameters
+     * @return string
      */
     public function addURLParameters($url, $parameters)
     {
@@ -35,6 +41,9 @@ class HttpAdapter
 
     /**
      * @see HTTP::checkSessionCookie()
+     *
+     * @param string|null $retryURL
+     * @return void
      */
     public function checkSessionCookie($retryURL = null)
     {
@@ -43,6 +52,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::checkURLAllowed()
+     *
+     * @param string $url
+     * @param array|null $trustedSites
+     * @return bool
      */
     public function checkURLAllowed($url, array $trustedSites = null)
     {
@@ -51,6 +64,11 @@ class HttpAdapter
 
     /**
      * @see HTTP::fetch()
+     *
+     * @param string $url
+     * @param array $context
+     * @param bool $getHeaders
+     * @return array|string
      */
     public function fetch($url, $context = [], $getHeaders = false)
     {
@@ -59,6 +77,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getAcceptLanguage()
+     * @return string
      */
     public function getAcceptLanguage()
     {
@@ -67,6 +86,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::guessBasePath()
+     * @return string
      */
     public function guessBasePath()
     {
@@ -75,6 +95,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getBaseURL()
+     * @return string
      */
     public function getBaseURL()
     {
@@ -83,6 +104,9 @@ class HttpAdapter
 
     /**
      * @see HTTP::getFirstPathElement()
+     *
+     * @param $bool $trailingslash
+     * @return string
      */
     public function getFirstPathElement($trailingslash = true)
     {
@@ -91,6 +115,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::getPOSTRedirectURL()
+     *
+     * @param $string $destination
+     * @param array $data
+     * @return string
      */
     public function getPOSTRedirectURL($destination, $data)
     {
@@ -99,6 +127,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getSelfHost()
+     * @return string
      */
     public function getSelfHost()
     {
@@ -107,6 +136,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getSelfHostWithNonStandardPort()
+     * @return string
      */
     public function getSelfHostWithNonStandardPort()
     {
@@ -115,6 +145,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getSelfHostWithPath()
+     * @return string
      */
     public function getSelfHostWithPath()
     {
@@ -123,6 +154,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getSelfURL()
+     * @return string
      */
     public function getSelfURL()
     {
@@ -131,6 +163,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getSelfURLHost()
+     * @return string
      */
     public function getSelfURLHost()
     {
@@ -139,6 +172,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::getSelfURLNoQuery()
+     * @return string
      */
     public function getSelfURLNoQuery()
     {
@@ -147,6 +181,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::isHTTPS()
+     * @return bool
      */
     public function isHTTPS()
     {
@@ -155,6 +190,7 @@ class HttpAdapter
 
     /**
      * @see HTTP::normalizeURL()
+     * @return string
      */
     public function normalizeURL($url)
     {
@@ -163,6 +199,9 @@ class HttpAdapter
 
     /**
      * @see HTTP::parseQueryString()
+     *
+     * @param string
+     * @return string
      */
     public function parseQueryString($query_string)
     {
@@ -171,6 +210,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::redirectTrustedURL()
+     *
+     * @param string $url
+     * @param array $parameters
+     * @return string
      */
     public function redirectTrustedURL($url, $parameters = [])
     {
@@ -179,6 +222,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::redirectUntrustedURL()
+     *
+     * @param string $url
+     * @param array $parameters
+     * @return string
      */
     public function redirectUntrustedURL($url, $parameters = [])
     {
@@ -187,6 +234,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::resolveURL()
+     *
+     * @param string $url
+     * @param string|null $base
+     * @return string
      */
     public function resolveURL($url, $base = null)
     {
@@ -195,6 +246,12 @@ class HttpAdapter
 
     /**
      * @see HTTP::setCookie()
+     *
+     * @param string $name
+     * @param string $value
+     * @param array|null $params
+     * @param bool $throw
+     * @return void
      */
     public function setCookie($name, $value, $params = null, $throw = true)
     {
@@ -203,6 +260,10 @@ class HttpAdapter
 
     /**
      * @see HTTP::submitPOSTData()
+     *
+     * @param string $destination
+     * @param array $data
+     * @return void
      */
     public function submitPOSTData($destination, $data)
     {
diff --git a/lib/SimpleSAML/Utils/Net.php b/lib/SimpleSAML/Utils/Net.php
index 02619d221..351a7cf6e 100644
--- a/lib/SimpleSAML/Utils/Net.php
+++ b/lib/SimpleSAML/Utils/Net.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils;
 
 /**
@@ -8,7 +9,6 @@ namespace SimpleSAML\Utils;
  */
 class Net
 {
-
     /**
      * Check whether an IP address is part of a CIDR.
      *
diff --git a/lib/SimpleSAML/Utils/Random.php b/lib/SimpleSAML/Utils/Random.php
index f3db05154..6ed304e45 100644
--- a/lib/SimpleSAML/Utils/Random.php
+++ b/lib/SimpleSAML/Utils/Random.php
@@ -1,4 +1,5 @@
 <?php
+
 namespace SimpleSAML\Utils;
 
 /**
@@ -8,7 +9,6 @@ namespace SimpleSAML\Utils;
  */
 class Random
 {
-
     /**
      * The fixed length of random identifiers.
      */
diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php
index 9b1f37766..b58339538 100644
--- a/lib/SimpleSAML/Utils/XML.php
+++ b/lib/SimpleSAML/Utils/XML.php
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Utility class for XML and DOM manipulation.
  *
@@ -12,7 +13,6 @@ use SimpleSAML\XML\Errors;
 
 class XML
 {
-
     /**
      * This function performs some sanity checks on XML documents, and optionally validates them against their schema
      * if the 'validatexml' debugging option is enabled. A warning will be printed to the log if validation fails.
@@ -166,7 +166,7 @@ class XML
         $textNodes = []; // text nodes which should be deleted
         $childNodes = []; // other child nodes
         for ($i = 0; $i < $root->childNodes->length; $i++) {
-            /** @var \DOMElement $child */
+            /** @var \DOMNode $child */
             $child = $root->childNodes->item($i);
 
             if ($child instanceof \DOMText) {
@@ -288,7 +288,7 @@ class XML
         $ret = [];
 
         for ($i = 0; $i < $element->childNodes->length; $i++) {
-            /** @var \DOMElement $child */
+            /** @var \DOMNode $child */
             $child = $element->childNodes->item($i);
 
             // skip text nodes and comment elements
-- 
GitLab