From: Roland Häder Date: Sun, 6 Dec 2020 10:35:21 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5dfec1886bc8db372483aa4f710c948f4fdc8027;p=core.git Continued: - reduced over-usage of is_string() Signed-off-by: Roland Häder --- diff --git a/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php b/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php index 95fac58a..834765f1 100644 --- a/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php +++ b/framework/main/classes/commands/html/class_HtmlLoginAreaCommand.php @@ -185,10 +185,10 @@ class HtmlLoginAreaCommand extends BaseCommand implements Commandable { $actReq = $requestInstance->getRequestElement('action'); // Do we have a "action" parameter set? - if ((is_string($actReq)) && (!empty($actReq))) { + if (!empty($actReq)) { // Then use it with prefix $this->actionName = StringUtils::convertDashesToUnderscores($applicationInstance->getAppShortName()) . '_login_' . $actReq; - } // END - if + } // Get a resolver $actionResolver = HtmlActionResolver::createHtmlActionResolver($this->actionName); diff --git a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php index 6816e4e4..a39c83a9 100644 --- a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php +++ b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php @@ -12,6 +12,7 @@ use Org\Mxchange\CoreFramework\Deprecated\PathIsNoDirectoryException; // Import SPL stuff use \DirectoryIterator; +use \InvalidArgumentException; /** * A class for directory reading and getting its contents, no recursion! @@ -79,14 +80,11 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework * @throws PathIsNoDirectoryException If the provided path name is not valid * @throws PathReadProtectedException If the provided path name is read-protected */ - public static final function createFrameworkDirectoryPointer ($pathName) { + public static final function createFrameworkDirectoryPointer (string $pathName) { // Some pre-sanity checks... - if (is_null($pathName)) { - // No pathname given - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_string($pathName)) { - // Is not a string - throw new InvalidPathStringException(NULL, self::EXCEPTION_INVALID_STRING); + if (empty($pathName)) { + // Throw IAE + throw new InvalidArgumentException('Parameter "pathName" is empty'); } elseif (!is_dir($pathName)) { // Not a directory throw new PathIsNoDirectoryException($pathName, self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/console/class_ConsoleTemplateEngine.php b/framework/main/classes/template/console/class_ConsoleTemplateEngine.php index 85d61d6d..309822b4 100644 --- a/framework/main/classes/template/console/class_ConsoleTemplateEngine.php +++ b/framework/main/classes/template/console/class_ConsoleTemplateEngine.php @@ -71,9 +71,6 @@ class ConsoleTemplateEngine extends BaseTemplateEngine implements CompileableTem if (empty($templateBasePath)) { // Base path is empty throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($templateBasePath)) { - // Is not a string - throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/html/class_HtmlTemplateEngine.php b/framework/main/classes/template/html/class_HtmlTemplateEngine.php index 76dac48c..30644521 100644 --- a/framework/main/classes/template/html/class_HtmlTemplateEngine.php +++ b/framework/main/classes/template/html/class_HtmlTemplateEngine.php @@ -71,9 +71,6 @@ class HtmlTemplateEngine extends BaseTemplateEngine implements CompileableTempla if (empty($templateBasePath)) { // Base path is empty throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($templateBasePath)) { - // Is not a string - throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/image/class_ImageTemplateEngine.php b/framework/main/classes/template/image/class_ImageTemplateEngine.php index da1faf41..33878f8b 100644 --- a/framework/main/classes/template/image/class_ImageTemplateEngine.php +++ b/framework/main/classes/template/image/class_ImageTemplateEngine.php @@ -115,9 +115,6 @@ class ImageTemplateEngine extends BaseTemplateEngine implements CompileableTempl if (empty($templateBasePath)) { // Base path is empty throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($templateBasePath)) { - // Is not a string - throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/mail/class_MailTemplateEngine.php b/framework/main/classes/template/mail/class_MailTemplateEngine.php index 338fd743..b8b97359 100644 --- a/framework/main/classes/template/mail/class_MailTemplateEngine.php +++ b/framework/main/classes/template/mail/class_MailTemplateEngine.php @@ -105,9 +105,6 @@ class MailTemplateEngine extends BaseTemplateEngine implements CompileableTempla if (empty($templateBasePath)) { // Base path is empty throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($templateBasePath)) { - // Is not a string - throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/menu/class_MenuTemplateEngine.php b/framework/main/classes/template/menu/class_MenuTemplateEngine.php index ed9468ef..e9eb5d0b 100644 --- a/framework/main/classes/template/menu/class_MenuTemplateEngine.php +++ b/framework/main/classes/template/menu/class_MenuTemplateEngine.php @@ -167,9 +167,6 @@ class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTempla if (empty($templateBasePath)) { // Base path is empty throw new UnexpectedValueException(sprintf('[%s:%d] Variable templateBasePath is empty.', $templateInstance->__toString(), __LINE__), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($templateBasePath)) { - // Is not a string - throw new UnexpectedValueException(sprintf('[%s:%d] %s is not a string with a base path.', $templateInstance->__toString(), __LINE__, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new InvalidDirectoryException(array($templateInstance, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php index 39026824..892bb09d 100644 --- a/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php +++ b/framework/main/classes/template/xml/class_BaseXmlTemplateEngine.php @@ -125,9 +125,6 @@ abstract class BaseXmlTemplateEngine extends BaseTemplateEngine implements Compi if (empty($templateBasePath)) { // Base path is empty throw new BasePathIsEmptyException($this, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!is_string($templateBasePath)) { - // Is not a string - throw new InvalidBasePathStringException(array($this, $templateBasePath), self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($templateBasePath)) { // Is not a path throw new BasePathIsNoDirectoryException(array($this, $templateBasePath), self::EXCEPTION_INVALID_PATH_NAME); diff --git a/framework/main/classes/utils/string/class_StringUtils.php b/framework/main/classes/utils/string/class_StringUtils.php index e6c4c738..b114566a 100644 --- a/framework/main/classes/utils/string/class_StringUtils.php +++ b/framework/main/classes/utils/string/class_StringUtils.php @@ -144,17 +144,11 @@ final class StringUtils extends BaseFrameworkSystem { * @throws NullPointerException If $str is null * @throws InvalidArgumentException If $str is empty */ - public static function convertDashesToUnderscores ($str) { - // Is it null? - if (is_null($str)) { - // Throw NPE - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_string($str)) { + public static function convertDashesToUnderscores (string $str) { + // Validate parameter + if (empty($str)) { // Entry is empty - throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY); - } elseif ((is_string($str)) && (empty($str))) { - // Entry is empty - throw new InvalidArgumentException('str is empty', FrameworkConfiguration::EXCEPTION_CONFIG_KEY_IS_EMPTY); + throw new InvalidArgumentException('Parameter "str" is empty'); } // Convert them all diff --git a/framework/main/middleware/debug/class_DebugMiddleware.php b/framework/main/middleware/debug/class_DebugMiddleware.php index 0d913754..6a951abb 100644 --- a/framework/main/middleware/debug/class_DebugMiddleware.php +++ b/framework/main/middleware/debug/class_DebugMiddleware.php @@ -80,7 +80,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { // All fine $isInitialized = true; - } elseif ((!is_null($outputClass)) && (is_string($outputClass)) && (class_exists($outputClass))) { + } elseif (class_exists($outputClass)) { // A name for a debug output class has been provided so we try to get it $outputInstance = ObjectFactory::createObjectByName($outputClass); diff --git a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php index 1dd97665..1ca262eb 100644 --- a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php +++ b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php @@ -85,9 +85,9 @@ class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements // This may throw exceptions try { // Is the config entry valid and class is there? - if (!is_string($configKey)) { + if (!is_string($configValue)) { // Is not a string - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('configKey=%s has unexpected type "%s". FAILED', $configKey, gettype($configKey))); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('configValue=%s has unexpected type "%s". FAILED', $configValue, gettype($configValue))); // Skip further tests $failed++;