From: Roland Häder Date: Thu, 16 Feb 2023 19:28:30 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3b028a8b0363f05d15940acaed89b958df916e6f;p=core.git Continued: - added more type-hints - added more checks on parameter - changed old array() to "new" [] style - added some debug lines --- diff --git a/framework/config/class_FrameworkConfiguration.php b/framework/config/class_FrameworkConfiguration.php index b4696e1b..f5d60c17 100644 --- a/framework/config/class_FrameworkConfiguration.php +++ b/framework/config/class_FrameworkConfiguration.php @@ -143,7 +143,7 @@ class FrameworkConfiguration implements Registerable { */ public final function setConfigEntry (string $configKey, $configValue) { // Is a valid configuration key key provided? - //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s,configValue[]=%s' . PHP_EOL, __METHOD__, __LINE__, $configKey, gettype($configValue)); + //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s,configValue[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $configKey, gettype($configValue)); if (empty($configKey)) { // Entry is empty throw new InvalidArgumentException('Parameter "configKey" is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY); @@ -156,7 +156,7 @@ class FrameworkConfiguration implements Registerable { $configKey = StringUtils::convertDashesToUnderscores($configKey); // Set the configuration value - //* NOISY-DEBUG: */ printf('[%s:%d]: configKey=%s,configValue[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, $configKey, gettype($configValue), $configValue); + //* NOISY-DEBUG: */ printf('[%s:%d]: Setting configKey=%s,configValue[%s]=%s - EXIT!' . PHP_EOL, __METHOD__, __LINE__, $configKey, gettype($configValue), $configValue); self::$configData[$configKey] = $configValue; } diff --git a/framework/loader/class_ClassLoader.php b/framework/loader/class_ClassLoader.php index ffb4c436..7764cb3d 100644 --- a/framework/loader/class_ClassLoader.php +++ b/framework/loader/class_ClassLoader.php @@ -377,6 +377,7 @@ final class ClassLoader { $classNameParts = explode("\\", $className); // At least 3 parts should be there + //* NOISY-DEBUG: */ printf('[%s:%d]: self::strictNamingConvention=%d,classNameParts()=%d' . PHP_EOL, __METHOD__, __LINE__, intval(self::$strictNamingConvention), count($classNameParts)); if ((self::$strictNamingConvention === true) && (count($classNameParts) < 5)) { // Namespace scheme is: Tld\Domain\Project\Package[\SubPackage...] throw new InvalidArgumentException(sprintf('Class name "%s" is not conform to naming-convention: Tld\Domain\Project\Package[\SubPackage...]\SomeFooBar', $className)); diff --git a/framework/main/classes/filter/validator/class_EmailValidatorFilter.php b/framework/main/classes/filter/validator/class_EmailValidatorFilter.php index b9202e8e..62b5647f 100644 --- a/framework/main/classes/filter/validator/class_EmailValidatorFilter.php +++ b/framework/main/classes/filter/validator/class_EmailValidatorFilter.php @@ -143,7 +143,7 @@ class EmailValidatorFilter extends BaseFilter implements Filterable { * @param $email Email to check for existence * @return $alreadyTaken Whether the email has been taken */ - private function ifEmailIsTaken ($email) { + private function ifEmailIsTaken (string $email) { // Default is already taken $alreadyTaken = true; diff --git a/framework/main/classes/filter/validator/class_UserNameValidatorFilter.php b/framework/main/classes/filter/validator/class_UserNameValidatorFilter.php index 5a581e8a..70ea0016 100644 --- a/framework/main/classes/filter/validator/class_UserNameValidatorFilter.php +++ b/framework/main/classes/filter/validator/class_UserNameValidatorFilter.php @@ -109,7 +109,7 @@ class UserNameValidatorFilter extends BaseFilter implements Filterable { * @param $userName Username to check for existence * @return $alreadyTaken Whether the username has been taken */ - private function ifUserNameIsTaken ($userName) { + private function ifUserNameIsTaken (string $userName) { // Default is already taken $alreadyTaken = true; diff --git a/framework/main/classes/filter/verifier/class_UserGuestVerifierFilter.php b/framework/main/classes/filter/verifier/class_UserGuestVerifierFilter.php index 6dc1b386..fecfce37 100644 --- a/framework/main/classes/filter/verifier/class_UserGuestVerifierFilter.php +++ b/framework/main/classes/filter/verifier/class_UserGuestVerifierFilter.php @@ -111,7 +111,7 @@ class UserGuestVerifierFilter extends BaseFilter implements Filterable { * @param $userName Username to check for existence * @return $alreadyTaken Whether the username has been taken */ - private function ifUserGuestIsTaken ($userName) { + private function ifUserGuestIsTaken (string $userName) { // Default is already taken $alreadyTaken = true; diff --git a/framework/main/classes/filter/verifier/class_UserNameVerifierFilter.php b/framework/main/classes/filter/verifier/class_UserNameVerifierFilter.php index 97e09715..a5856458 100644 --- a/framework/main/classes/filter/verifier/class_UserNameVerifierFilter.php +++ b/framework/main/classes/filter/verifier/class_UserNameVerifierFilter.php @@ -109,7 +109,7 @@ class UserNameVerifierFilter extends BaseFilter implements Filterable { * @param $userName Username to check for existence * @return $alreadyTaken Whether the username has been taken */ - private function ifUserNameIsTaken ($userName) { + private function ifUserNameIsTaken (string $userName) { // Default is already taken $alreadyTaken = true; diff --git a/framework/main/classes/user/guest/class_Guest.php b/framework/main/classes/user/guest/class_Guest.php index 41630078..3ac7c9ef 100644 --- a/framework/main/classes/user/guest/class_Guest.php +++ b/framework/main/classes/user/guest/class_Guest.php @@ -9,6 +9,9 @@ use Org\Mxchange\CoreFramework\Request\Requestable; use Org\Mxchange\CoreFramework\User\BaseUser; use Org\Mxchange\CoreFramework\User\UsernameMissingException; +// Import SPL stuff +use \InvalidArgumentException; + /** * A generic class for handling guests * @@ -84,7 +87,13 @@ class Guest extends BaseUser implements ManageableGuest, Registerable { * @throws UsernameMissingException If the username does not exist * @throws UserNoGuestException If the user is no guest account */ - public static final function createGuestByUsername ($userName) { + public static final function createGuestByUsername (string $userName) { + // Check parameter + if (empty($userName)) { + // Throw IAE + throw new InvalidArgumentException('Paramter "userName" is empty'); + } + // Get a new instance $userInstance = new Guest(); @@ -111,7 +120,13 @@ class Guest extends BaseUser implements ManageableGuest, Registerable { * @param $email Email address of the user * @return $userInstance An instance of this user class */ - public static final function createGuestByEmail ($email) { + public static final function createGuestByEmail (string $email) { + // Check parameter + if (empty($email)) { + // Throw IAE + throw new InvalidArgumentException('Paramter "email" is empty'); + } + // Get a new instance $userInstance = new Guest(); diff --git a/framework/main/classes/user/member/class_Member.php b/framework/main/classes/user/member/class_Member.php index 27baa42b..4c6ce760 100644 --- a/framework/main/classes/user/member/class_Member.php +++ b/framework/main/classes/user/member/class_Member.php @@ -11,6 +11,9 @@ use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\User\BaseUser; use Org\Mxchange\CoreFramework\User\UsernameMissingException; +// Import SPL stuff +use \InvalidArgumentException; + /** * A generic class for handling users * @@ -54,7 +57,13 @@ class Member extends BaseUser implements ManageableMember, Registerable { * @throws UsernameMissingException If the username does not exist * @throws UnexpectedGuestAccountException If the user status is 'guest' */ - public static final function createMemberByUsername ($userName) { + public static final function createMemberByUsername (string $userName) { + // Check parameter + if (empty($userName)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "userName" is empty'); + } + // Get a new instance $userInstance = new Member(); @@ -81,7 +90,13 @@ class Member extends BaseUser implements ManageableMember, Registerable { * @param $email Email address of the user * @return $userInstance An instance of this user class */ - public static final function createMemberByEmail ($email) { + public static final function createMemberByEmail (string $email) { + // Check parameter + if (empty($email)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "email" is empty'); + } + // Get a new instance $userInstance = new Member(); diff --git a/framework/main/middleware/io/class_FileIoHandler.php b/framework/main/middleware/io/class_FileIoHandler.php index a496f2e0..1f0e8a02 100644 --- a/framework/main/middleware/io/class_FileIoHandler.php +++ b/framework/main/middleware/io/class_FileIoHandler.php @@ -120,10 +120,10 @@ class FileIoHandler extends BaseMiddleware implements IoHandler { } // Prepare output array - $dataArray = array( + $dataArray = [ 0 => $className, 1 => $dataStream - ); + ]; // Send the infoInstance and dataArray to the output handler $this->getOutputStreamerInstance()->saveFile($infoInstance, $dataArray);