Skip to content

Commit 10ac9ac

Browse files
committed
Improve phpdoc. Escape strings printed with debug enabled. Remove error_reporting
1 parent 7971760 commit 10ac9ac

9 files changed

Lines changed: 64 additions & 61 deletions

File tree

demo2/consume.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* link where it will send a certified response via $_POST.
88
*/
99

10-
error_reporting(E_ALL);
11-
1210
require_once dirname(__DIR__).'/_toolkit_loader.php';
1311

1412
try {

demo2/metadata.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* or expose it on a URL so your IdP can check it periodically.
77
*/
88

9-
error_reporting(E_ALL);
10-
119
require_once dirname(__DIR__).'/_toolkit_loader.php';
1210

1311
header('Content-Type: text/xml');

lib/Saml2/Auth.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class OneLogin_Saml2_Auth
7575
* SessionNotOnOrAfter. When the user is logged, this stored it
7676
* from the AuthnStatement of the SAML Response
7777
*
78-
* @var DateTime
78+
* @var int|null
7979
*/
8080
private $_sessionExpiration;
8181

@@ -97,7 +97,7 @@ class OneLogin_Saml2_Auth
9797
* The NotOnOrAfter value of the valid SubjectConfirmationData
9898
* node (if any) of the last assertion processed
9999
*
100-
* @var DateTime
100+
* @var int
101101
*/
102102
private $_lastAssertionNotOnOrAfter;
103103

@@ -111,7 +111,7 @@ class OneLogin_Saml2_Auth
111111
/**
112112
* Reason of the last error.
113113
*
114-
* @var string
114+
* @var string|null
115115
*/
116116
private $_errorReason;
117117

@@ -164,7 +164,7 @@ public function getSettings()
164164
*
165165
* @param bool $value Strict parameter
166166
*
167-
* @return array The settings data.
167+
* @throws OneLogin_Saml2_Error
168168
*/
169169
public function setStrict($value)
170170
{
@@ -305,6 +305,8 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
305305
* @param string $url The target URL to redirect the user.
306306
* @param array $parameters Extra parameters to be passed as part of the url
307307
* @param bool $stay True if we want to stay (returns the url string) False to redirect
308+
*
309+
* @return string|null
308310
*/
309311
public function redirectTo($url = '', $parameters = array(), $stay = false)
310312
{
@@ -401,7 +403,7 @@ public function getErrors()
401403
/**
402404
* Returns the reason for the last error
403405
*
404-
* @return string Error reason
406+
* @return string|null Error reason
405407
*/
406408
public function getLastErrorReason()
407409
{
@@ -436,7 +438,7 @@ public function getAttribute($name)
436438
* @param bool $stay True if we want to stay (returns the url string) False to redirect
437439
* @param bool $setNameIdPolicy When true the AuthNReuqest will set a nameIdPolicy element
438440
*
439-
* @return If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
441+
* @return string|null If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
440442
*/
441443
public function login($returnTo = null, $parameters = array(), $forceAuthn = false, $isPassive = false, $stay = false, $setNameIdPolicy = true)
442444
{
@@ -662,7 +664,7 @@ public function getLastAssertionId()
662664
}
663665

664666
/**
665-
* @return The NotOnOrAfter value of the valid
667+
* @return int The NotOnOrAfter value of the valid
666668
* SubjectConfirmationData node (if any)
667669
* of the last assertion processed
668670
*/
@@ -675,7 +677,7 @@ public function getLastAssertionNotOnOrAfter()
675677
* Returns the most recently-constructed/processed
676678
* XML SAML request (AuthNRequest, LogoutRequest)
677679
*
678-
* @return string The Request XML
680+
* @return string|null The Request XML
679681
*/
680682
public function getLastRequestXML()
681683
{
@@ -688,7 +690,7 @@ public function getLastRequestXML()
688690
* If the SAMLResponse was encrypted, by default tries
689691
* to return the decrypted XML.
690692
*
691-
* @return string The Response XML
693+
* @return string|null The Response XML
692694
*/
693695
public function getLastResponseXML()
694696
{

lib/Saml2/IdPMetadataParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public static function parseFileXML($filepath, $entityId = null, $desiredNameIdF
9090
* @param string $desiredNameIdFormat If available on IdP metadata, use that nameIdFormat
9191
*
9292
* @return array metadata info in php-saml settings format
93+
* @throws \Exception
9394
*/
9495
public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = null)
9596
{
@@ -200,8 +201,8 @@ public static function parseXML($xml, $entityId = null, $desiredNameIdFormat = n
200201
/**
201202
* Inject metadata info into php-saml settings array
202203
*
203-
* @param string $settings php-saml settings array
204-
* @param string $metadataInfo array metadata info
204+
* @param array $settings php-saml settings array
205+
* @param array $metadataInfo array metadata info
205206
*
206207
* @return array settings
207208
*/

lib/Saml2/LogoutRequest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public function __construct(OneLogin_Saml2_Settings $settings, $request = null,
139139
$this->_logoutRequest = $logoutRequest;
140140
}
141141

142-
143142
/**
144143
* Returns the Logout Request defated, base64encoded, unsigned
145144
*
@@ -401,7 +400,7 @@ public function isValid($retrieveParametersFromServer = false)
401400
$this->_error = $e->getMessage();
402401
$debug = $this->_settings->isDebugActive();
403402
if ($debug) {
404-
echo $this->_error;
403+
echo htmlentities($this->_error);
405404
}
406405
return false;
407406
}

lib/Saml2/LogoutResponse.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OneLogin_Saml2_LogoutResponse
3535
/**
3636
* The decoded, unprocessed XML response provided to the constructor.
3737
*
38-
* @var string
38+
* @var string|null
3939
*/
4040
protected $_logoutResponse;
4141

@@ -49,7 +49,7 @@ class OneLogin_Saml2_LogoutResponse
4949
/**
5050
* After execute a validation process, if it fails, this var contains the cause
5151
*
52-
* @var string
52+
* @var string|null
5353
*/
5454
private $_error;
5555

@@ -104,7 +104,7 @@ public function getIssuer()
104104
/**
105105
* Gets the Status of the Logout Response.
106106
*
107-
* @return string The Status
107+
* @return string|null The Status
108108
*/
109109
public function getStatus()
110110
{
@@ -205,7 +205,7 @@ public function isValid($requestId = null, $retrieveParametersFromServer = false
205205
$this->_error = $e->getMessage();
206206
$debug = $this->_settings->isDebugActive();
207207
if ($debug) {
208-
echo $this->_error;
208+
echo htmlentities($this->_error);
209209
}
210210
return false;
211211
}
@@ -266,16 +266,16 @@ public function build($inResponseTo)
266266
*/
267267
public function getResponse($deflate = null)
268268
{
269-
$subject = $this->_logoutResponse;
269+
$logoutResponse = $this->_logoutResponse;
270270

271271
if (is_null($deflate)) {
272272
$deflate = $this->_settings->shouldCompressResponses();
273273
}
274274

275275
if ($deflate) {
276-
$subject = gzdeflate($this->_logoutResponse);
276+
$logoutResponse = gzdeflate($this->_logoutResponse);
277277
}
278-
return base64_encode($subject);
278+
return base64_encode($logoutResponse);
279279
}
280280

281281
/**
@@ -289,7 +289,7 @@ public function getError()
289289
}
290290

291291
/**
292-
* @return the ID of the Response
292+
* @return string the ID of the Response
293293
*/
294294
public function getId()
295295
{
@@ -300,7 +300,7 @@ public function getId()
300300
* Returns the XML that will be sent as part of the response
301301
* or that was received at the SP
302302
*
303-
* @return string
303+
* @return string|null
304304
*/
305305
public function getXML()
306306
{

lib/Saml2/Response.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class OneLogin_Saml2_Response
6767
/**
6868
* NotOnOrAfter value of a valid SubjectConfirmationData node
6969
*
70-
* @var DateTime
70+
* @var int
7171
*/
7272
private $_validSCDNotOnOrAfter;
7373

@@ -422,14 +422,14 @@ public function isValid($requestId = null)
422422
$this->_error = $e->getMessage();
423423
$debug = $this->_settings->isDebugActive();
424424
if ($debug) {
425-
echo $this->_error;
425+
echo htmlentities($this->_error);
426426
}
427427
return false;
428428
}
429429
}
430430

431431
/**
432-
* @return the ID of the Response
432+
* @return string|null the ID of the Response
433433
*/
434434
public function getId()
435435
{
@@ -441,12 +441,12 @@ public function getId()
441441
}
442442

443443
/**
444-
* @return the ID of the assertion in the Response
444+
* @return string|null the ID of the assertion in the Response
445445
*/
446446
public function getAssertionId()
447447
{
448448
if (!$this->validateNumAssertions()) {
449-
throw new IllegalArgumentException("SAML Response must contain 1 Assertion.");
449+
throw new InvalidArgumentException("SAML Response must contain 1 Assertion.");
450450
}
451451
$assertionNodes = $this->_queryAssertion("");
452452
$id = null;
@@ -459,7 +459,8 @@ public function getAssertionId()
459459
}
460460

461461
/**
462-
* @return the NotOnOrAfter value of the valid SubjectConfirmationData * node if any
462+
* @return int the NotOnOrAfter value of the valid SubjectConfirmationData
463+
* node if any
463464
*/
464465
public function getAssertionNotOnOrAfter()
465466
{
@@ -544,6 +545,7 @@ public function getAudiences()
544545
* Gets the Issuers (from Response and Assertion).
545546
*
546547
* @return array @issuers The issuers of the assertion/response
548+
* @throws OneLogin_Saml2_ValidationError
547549
*/
548550
public function getIssuers()
549551
{
@@ -641,7 +643,7 @@ public function getNameIdData()
641643
/**
642644
* Gets the NameID provided by the SAML response from the IdP.
643645
*
644-
* @return string Name ID Value
646+
* @return string|null Name ID Value
645647
*/
646648
public function getNameId()
647649
{
@@ -656,7 +658,7 @@ public function getNameId()
656658
/**
657659
* Gets the NameID Format provided by the SAML response from the IdP.
658660
*
659-
* @return string Name ID Format
661+
* @return string|null Name ID Format
660662
*/
661663
public function getNameIdFormat()
662664
{
@@ -671,7 +673,7 @@ public function getNameIdFormat()
671673
/**
672674
* Gets the NameID NameQualifier provided by the SAML response from the IdP.
673675
*
674-
* @return string Name ID NameQualifier
676+
* @return string|null Name ID NameQualifier
675677
*/
676678
public function getNameIdNameQualifier()
677679
{

lib/Saml2/Settings.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ class OneLogin_Saml2_Settings
100100
private $_errors = array();
101101

102102
/**
103-
* Setting errors.
103+
* Valitate SP data only flag
104104
*
105-
* @var array
105+
* @var bool
106106
*/
107107
private $_spValidationOnly = false;
108108

@@ -112,7 +112,7 @@ class OneLogin_Saml2_Settings
112112
* - Loads settings info from settings file or array/object provided
113113
*
114114
* @param array|object|null $settings SAML Toolkit Settings
115-
* @param boolean $spValidationOnly Validate or not the IdP data
115+
* @param bool $spValidationOnly Validate or not the IdP data
116116
*
117117
* @throws OneLogin_Saml2_Error If any settings parameter is invalid
118118
* @throws Exception If OneLogin_Saml2_Settings is incorrectly supplied
@@ -162,6 +162,7 @@ public function __construct($settings = null, $spValidationOnly = false)
162162

163163
/**
164164
* Sets the paths of the different folders
165+
* @suppress PhanUndeclaredConstant
165166
*/
166167
private function _loadPaths()
167168
{
@@ -289,6 +290,7 @@ private function _loadSettingsFromArray($settings)
289290
*
290291
* @return bool True if the settings info is valid
291292
* @throws OneLogin_Saml2_Error
293+
* @suppress PhanUndeclaredVariable
292294
*/
293295
private function _loadSettingsFromFile()
294296
{
@@ -302,13 +304,14 @@ private function _loadSettingsFromFile()
302304
);
303305
}
304306

307+
/** @var array $settings */
305308
include $filename;
306309

307310
// Add advance_settings if exists
308-
309311
$advancedFilename = $this->getConfigPath().'advanced_settings.php';
310312

311313
if (file_exists($advancedFilename)) {
314+
/** @var array $advancedSettings */
312315
include $advancedFilename;
313316
$settings = array_merge($settings, $advancedSettings);
314317
}
@@ -1000,6 +1003,7 @@ public function getErrors()
10001003
* Activates or deactivates the strict mode.
10011004
*
10021005
* @param bool $value Strict parameter
1006+
* @throws Exception
10031007
*/
10041008
public function setStrict($value)
10051009
{

0 commit comments

Comments
 (0)