From d34d5a820a52ad5669952800fc5a955e2142c234 Mon Sep 17 00:00:00 2001 From: Dominique FOURNIER Date: Mon, 3 Apr 2023 21:15:54 +0200 Subject: [PATCH] PHP 8.2 Deprecated cleaning --- Tests/AuthjwtTest.php | 105 ++++++++++++++++----------------- Tests/XdiffTest.php | 4 +- src/Authzgroups.php | 13 ++-- src/Certificationauthority.php | 3 + src/Dblayeroo.php | 2 +- src/Mail.php | 2 +- 6 files changed, 65 insertions(+), 64 deletions(-) diff --git a/Tests/AuthjwtTest.php b/Tests/AuthjwtTest.php index 316752c..2fc0b36 100644 --- a/Tests/AuthjwtTest.php +++ b/Tests/AuthjwtTest.php @@ -13,6 +13,15 @@ use Domframework\Authjwt; /** Test the Authjwt.php file */ class AuthjwtTest extends \PHPUnit_Framework_TestCase { + /** @var string */ + private $cacheDir; + /** @var string */ + private $serverKey; + /** @var string */ + private $cipherKey; + /** @var string */ + private $token; + public function __construct() { $this->cacheDir = "/tmp/testDFWJWT-" . time(); @@ -26,11 +35,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase exec("rm -rf $this->cacheDir"); } - /** Create a valid token as email is provided + /** + * Create a valid token as email is provided * payload = ["email" => "toto@example.com", "password" => "ToTo"]; */ public function testJWT1() - // {{{ { $authjwt = new Authjwt(); $authjwt->cacheDir = $this->cacheDir; @@ -40,12 +49,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $this->token = $authjwt->createJwtToken($auth); $this->assertSame(strlen($this->token), 145); } - // }}} - /** Check if the authentication work - */ + /** + * Check if the authentication work + */ public function testAuthValid1() - // {{{ { $authjwt = new Authjwt(); $_SERVER["HTTP_AUTHENTICATION"] = "Bearer " . $this->token; @@ -59,12 +67,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase ["email" => "toto@example.com", "password" => "ToTo"] ); } - // }}} - /** Invalid Token : reject with invalid signature - */ + /** + * Invalid Token : reject with invalid signature + */ public function testInvalidToken1() - // {{{ { $this->expectException("Exception", "JWT Signature not readable", 403); $authjwt = new Authjwt(); @@ -75,12 +82,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt->authentication("unused", "unused"); $res = $authjwt->getdetails(); } - // }}} - /** Invalid Token : reject with bad algorithm - */ + /** + * Invalid Token : reject with bad algorithm + */ public function testInvalidToken2() - // {{{ { $this->expectException("Exception", "JWT with Empty algorithm", 403); $authjwt = new Authjwt(); @@ -91,12 +97,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt->authentication("unused", "unused"); $res = $authjwt->getdetails(); } - // }}} - /** Invalid Token : No token provided - */ + /** + * Invalid Token : No token provided + */ public function testInvalidToken3() - // {{{ { $this->expectException("Exception", "No Authentication available", 401); $authjwt = new Authjwt(); @@ -107,12 +112,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt->authentication("unused", "unused"); $res = $authjwt->getdetails(); } - // }}} - /** Invalid Token : No Bearer authentication - */ + /** + * Invalid Token : No Bearer authentication + */ public function testInvalidToken4() - // {{{ { $this->expectException( "Exception", @@ -127,12 +131,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt->authentication("unused", "unused"); $res = $authjwt->getdetails(); } - // }}} - /** Invalid Token : no email in it - */ + /** + * Invalid Token : no email in it + */ public function testInvalidToken5() - // {{{ { $this->expectException( "Exception", @@ -149,12 +152,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt->authentication("unused", "unused"); $res = $authjwt->getdetails(); } - // }}} - /** Anonymous payload - */ + /** + * Anonymous payload + */ public function testAnonymous1() - // {{{ { $this->expectException( "Exception", @@ -171,12 +173,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt->authentication("unused", "unused"); $res = $authjwt->getdetails(); } - // }}} - /** Logout - */ + /** + * Logout + */ public function testLogout1() - // {{{ { $authjwt = new Authjwt(); $authjwt->cacheDir = $this->cacheDir; @@ -186,12 +187,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $res = $authjwt->logout(); $this->assertSame($res, true); } - // }}} - /** Logout : No Auth provided - */ + /** + * Logout : No Auth provided + */ public function testLogout2() - // {{{ { $this->expectException("Exception", "No Authentication available", 401); $authjwt = new Authjwt(); @@ -201,12 +201,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase unset($_SERVER["HTTP_AUTHENTICATION"]); $res = $authjwt->logout(); } - // }}} - /** Logout : No Bearer available - */ + /** + * Logout : No Bearer available + */ public function testLogout3() - // {{{ { $this->expectException( "Exception", @@ -220,24 +219,22 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $_SERVER["HTTP_AUTHENTICATION"] = "Another auth"; $res = $authjwt->logout(); } - // }}} - /** Not needed function connect - */ + /** + * Not needed function connect + */ public function testUnusedFunctions1() - // {{{ { $authjwt = new Authjwt(); $res = $authjwt->connect(); $this->assertSame($res, true); } - // }}} - /** Not needed function changepassword - */ + /** + * Not needed function changepassword + */ public function testUnusedFunctions2() - // {{{ { $this->expectException( "Exception", @@ -247,12 +244,11 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt = new Authjwt(); $res = $authjwt->changepassword("unused", "unused"); } - // }}} - /** Not needed function overwritepassword - */ + /** + * Not needed function overwritepassword + */ public function testUnusedFunctions3() - // {{{ { $this->expectException( "Exception", @@ -262,5 +258,4 @@ class AuthjwtTest extends \PHPUnit_Framework_TestCase $authjwt = new Authjwt(); $res = $authjwt->overwritepassword("unused", "unused"); } - // }}} } diff --git a/Tests/XdiffTest.php b/Tests/XdiffTest.php index 1e5f9cc..f7b09be 100644 --- a/Tests/XdiffTest.php +++ b/Tests/XdiffTest.php @@ -189,8 +189,8 @@ to this document. $date = date("Y-m-d H:i:s.u00"); // DST must answer +0200 in winter and +0100 in summer $dst = date("O"); - $this->assertSame($res, "--- Original ${date}0 $dst -+++ New ${date}1 $dst + $this->assertSame($res, "--- Original {$date}0 $dst ++++ New {$date}1 $dst @@ -0,0 +1,6 @@ +This is an important +notice! It should diff --git a/src/Authzgroups.php b/src/Authzgroups.php index ad0a6bf..009d377 100644 --- a/src/Authzgroups.php +++ b/src/Authzgroups.php @@ -12,7 +12,10 @@ namespace Domframework; user by its groups membership */ class Authzgroups { - /** The table prefix to use */ + /** + * The table prefix to use + * @var string + */ public $tableprefix = ""; /** The dblayer object use to manage the Object table */ private $dbObject = null; @@ -334,7 +337,7 @@ class Authzgroups $this->dbObject = new Dblayer($dsn, $username, $password, $driver_options); $this->dbObject->debug = $this->debug; $this->dbObject->table = "authzobject"; - $this->dbObject->prefix = $this->tableprefix; + $this->dbObject->tableprefix = $this->tableprefix; $this->dbObject->fields = array( "idobject" => array("integer", "not null", "autoincrement"), "module" => array("varchar", "255", "not null"), @@ -351,7 +354,7 @@ class Authzgroups $this->dbGroup = new Dblayer($dsn, $username, $password, $driver_options); $this->dbGroup->debug = $this->debug; $this->dbGroup->table = "authzgroup"; - $this->dbGroup->prefix = $this->tableprefix; + $this->dbGroup->tableprefix = $this->tableprefix; $this->dbGroup->fields = array( "idgroup" => array("integer", "not null", "autoincrement"), "module" => array("varchar", "255", "not null"), @@ -373,7 +376,7 @@ class Authzgroups ); $this->dbGroupMember->debug = $this->debug; $this->dbGroupMember->table = "authzgroupmember"; - $this->dbGroupMember->prefix = $this->tableprefix; + $this->dbGroupMember->tableprefix = $this->tableprefix; $this->dbGroupMember->fields = array( "idgroupmember" => array("integer", "not null", "autoincrement"), "user" => array("varchar", "255", "not null"), @@ -394,7 +397,7 @@ class Authzgroups $this->dbRight = new Dblayer($dsn, $username, $password, $driver_options); $this->dbRight->debug = $this->debug; $this->dbRight->table = "authzright"; - $this->dbRight->prefix = $this->tableprefix; + $this->dbRight->tableprefix = $this->tableprefix; $this->dbRight->fields = array( "idright" => array("integer", "not null", "autoincrement"), "idgroup" => array("integer", "not null"), diff --git a/src/Certificationauthority.php b/src/Certificationauthority.php index e585afd..83d1bd3 100644 --- a/src/Certificationauthority.php +++ b/src/Certificationauthority.php @@ -234,6 +234,9 @@ extendedKeyUsage = serverAuth, clientAuth $days = 365, $altNames = array() ) { + if ($days === null) { + $days = 365; + } $conf = $this->opensslConf; if (! empty($altNames)) { // Copy the commonName from CSR request into subjectAltName diff --git a/src/Dblayeroo.php b/src/Dblayeroo.php index 6b81c0f..765591b 100644 --- a/src/Dblayeroo.php +++ b/src/Dblayeroo.php @@ -1044,7 +1044,7 @@ class Dblayeroo if ($col["is_nullable"] === "NO") { $tmp[] = "not null"; } - if (substr($col["column_default"], 0, 7) === "nextval") { + if (is_string($col["column_default"]) && substr($col["column_default"], 0, 7) === "nextval") { $tmp[] = "autoincrement"; $primary = $col["column_name"]; } diff --git a/src/Mail.php b/src/Mail.php index 2f36dfd..0528b7b 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -362,7 +362,7 @@ class Mail $headersSplit = preg_split( "#([\r\n]+)#", $headersEML, - null, + -1, PREG_SPLIT_DELIM_CAPTURE ); for ($i = 0; $i < count($headersSplit); $i = $i + 2) {