Skip to content

Commit 5af8bc9

Browse files
authored
Merge pull request #228 from morozov/php72-assert
Make assertions compatible with PHP 7.2
2 parents 0e7186c + cafaee6 commit 5af8bc9

4 files changed

Lines changed: 29 additions & 27 deletions

File tree

lib/Saml2/Auth.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
288288
*/
289289
public function redirectTo($url = '', $parameters = array(), $stay = false)
290290
{
291-
assert('is_string($url)');
292-
assert('is_array($parameters)');
291+
assert(is_string($url));
292+
assert(is_array($parameters));
293293

294294
if (empty($url) && isset($_REQUEST['RelayState'])) {
295295
$url = $_REQUEST['RelayState'];
@@ -387,7 +387,7 @@ public function getLastErrorReason()
387387
*/
388388
public function getAttribute($name)
389389
{
390-
assert('is_string($name)');
390+
assert(is_string($name));
391391

392392
$value = null;
393393
if (isset($this->_attributes[$name])) {
@@ -410,7 +410,7 @@ public function getAttribute($name)
410410
*/
411411
public function login($returnTo = null, $parameters = array(), $forceAuthn = false, $isPassive = false, $stay = false, $setNameIdPolicy = true)
412412
{
413-
assert('is_array($parameters)');
413+
assert(is_array($parameters));
414414

415415
$authnRequest = new OneLogin_Saml2_AuthnRequest($this->_settings, $forceAuthn, $isPassive, $setNameIdPolicy);
416416

@@ -451,7 +451,7 @@ public function login($returnTo = null, $parameters = array(), $forceAuthn = fal
451451
*/
452452
public function logout($returnTo = null, $parameters = array(), $nameId = null, $sessionIndex = null, $stay = false, $nameIdFormat = null)
453453
{
454-
assert('is_array($parameters)');
454+
assert(is_array($parameters));
455455

456456
$sloUrl = $this->getSLOurl();
457457
if (empty($sloUrl)) {

lib/Saml2/Error.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class OneLogin_Saml2_Error extends Exception
3535
*/
3636
public function __construct($msg, $code = 0, $args = null)
3737
{
38-
assert('is_string($msg)');
39-
assert('is_int($code)');
38+
assert(is_string($msg));
39+
assert(is_int($code));
4040

4141
$message = OneLogin_Saml2_Utils::t($msg, $args);
4242

@@ -111,8 +111,8 @@ class OneLogin_Saml2_ValidationError extends Exception
111111
*/
112112
public function __construct($msg, $code = 0, $args = null)
113113
{
114-
assert('is_string($msg)');
115-
assert('is_int($code)');
114+
assert(is_string($msg));
115+
assert(is_int($code));
116116

117117
$message = OneLogin_Saml2_Utils::t($msg, $args);
118118

lib/Saml2/Settings.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private function _addDefaultValues()
422422
*/
423423
public function checkSettings($settings)
424424
{
425-
assert('is_array($settings)');
425+
assert(is_array($settings));
426426

427427
if (!is_array($settings) || empty($settings)) {
428428
$errors = array('invalid_syntax');
@@ -480,7 +480,7 @@ public function checkCompressionSettings($settings)
480480
*/
481481
public function checkIdPSettings($settings)
482482
{
483-
assert('is_array($settings)');
483+
assert(is_array($settings));
484484

485485
if (!is_array($settings) || empty($settings)) {
486486
return array('invalid_syntax');
@@ -545,7 +545,7 @@ public function checkIdPSettings($settings)
545545
*/
546546
public function checkSPSettings($settings)
547547
{
548-
assert('is_array($settings)');
548+
assert(is_array($settings));
549549

550550
if (!is_array($settings) || empty($settings)) {
551551
return array('invalid_syntax');
@@ -880,7 +880,7 @@ public function getSPMetadata()
880880
*/
881881
public function validateMetadata($xml)
882882
{
883-
assert('is_string($xml)');
883+
assert(is_string($xml));
884884

885885
$errors = array();
886886
$res = OneLogin_Saml2_Utils::validateXML($xml, 'saml-schema-metadata-2.0.xsd', $this->_debug);

lib/Saml2/Utils.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class OneLogin_Saml2_Utils
5151
*/
5252
public static function t($msg, $args = array())
5353
{
54-
assert('is_string($msg)');
54+
assert(is_string($msg));
55+
5556
if (extension_loaded('gettext')) {
5657
bindtextdomain("phptoolkit", dirname(dirname(dirname(__FILE__))).'/locale');
5758
textdomain('phptoolkit');
@@ -80,8 +81,8 @@ public static function t($msg, $args = array())
8081
*/
8182
public static function loadXML($dom, $xml)
8283
{
83-
assert('$dom instanceof DOMDocument');
84-
assert('is_string($xml)');
84+
assert($dom instanceof DOMDocument);
85+
assert(is_string($xml));
8586

8687
if (strpos($xml, '<!ENTITY') !== false) {
8788
throw new Exception('Detected use of ENTITY in XML, disabled to prevent XXE/XEE attacks');
@@ -111,8 +112,8 @@ public static function loadXML($dom, $xml)
111112
*/
112113
public static function validateXML($xml, $schema, $debug = false)
113114
{
114-
assert('is_string($xml) || $xml instanceof DOMDocument');
115-
assert('is_string($schema)');
115+
assert(is_string($xml) || $xml instanceof DOMDocument);
116+
assert(is_string($schema));
116117

117118
libxml_clear_errors();
118119
libxml_use_internal_errors(true);
@@ -248,8 +249,8 @@ public static function getStringBetween($str, $start, $end)
248249
*/
249250
public static function redirect($url, $parameters = array(), $stay = false)
250251
{
251-
assert('is_string($url)');
252-
assert('is_array($parameters)');
252+
assert(is_string($url));
253+
assert(is_array($parameters));
253254

254255
if (substr($url, 0, 1) === '/') {
255256
$url = self::getSelfURLhost() . $url;
@@ -263,7 +264,7 @@ public static function redirect($url, $parameters = array(), $stay = false)
263264
);
264265
}
265266

266-
267+
267268
/* Add encoded parameters */
268269
if (strpos($url, '?') === false) {
269270
$paramPrefix = '?';
@@ -726,8 +727,8 @@ public static function parseSAML2Time($time)
726727
*/
727728
public static function parseDuration($duration, $timestamp = null)
728729
{
729-
assert('is_string($duration)');
730-
assert('is_null($timestamp) || is_int($timestamp)');
730+
assert(is_string($duration));
731+
assert(is_null($timestamp) || is_int($timestamp));
731732

732733
/* Parse the duration. We use a very strict pattern. */
733734
$durationRegEx = '#^(-?)P(?:(?:(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?)?)|(?:(\\d+)W))$#D';
@@ -894,7 +895,7 @@ public static function deleteLocalSession()
894895
*/
895896
public static function calculateX509Fingerprint($x509cert, $alg = 'sha1')
896897
{
897-
assert('is_string($x509cert)');
898+
assert(is_string($x509cert));
898899

899900
$lines = explode("\n", $x509cert);
900901

@@ -1150,7 +1151,7 @@ public static function decryptElement(DOMElement $encryptedData, XMLSecurityKey
11501151
OneLogin_Saml2_ValidationError::INVALID_XML_FORMAT
11511152
);
11521153
}
1153-
1154+
11541155
$decryptedElement = $newDoc->firstChild->firstChild;
11551156
if ($decryptedElement === null) {
11561157
throw new OneLogin_Saml2_ValidationError(
@@ -1175,8 +1176,9 @@ public static function decryptElement(DOMElement $encryptedData, XMLSecurityKey
11751176
*/
11761177
public static function castKey(XMLSecurityKey $key, $algorithm, $type = 'public')
11771178
{
1178-
assert('is_string($algorithm)');
1179-
assert('$type === "public" || $type === "private"');
1179+
assert(is_string($algorithm));
1180+
assert($type === 'public' || $type === 'private');
1181+
11801182
// do nothing if algorithm is already the type of the key
11811183
if ($key->type === $algorithm) {
11821184
return $key;

0 commit comments

Comments
 (0)