From 63f5632b0c5d2cebf8dd0940fdab561f86470f80 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 13 Aug 2017 20:51:58 +0200 Subject: [PATCH] Rewrites: - *IsEmptyException are all superflous as also NPE and IAE can do the same and much more generic - closed TODO to remove inConstructor, was bad code style anyway MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../classes/class_BaseFrameworkSystem.php | 1 + .../class_FrameworkDirectoryPointer.php | 31 +++-------- .../class_FrameworkTextFileInputPointer.php | 1 - .../class_FrameworkRawFileOutputPointer.php | 9 ++-- .../class_FrameworkTextFileOutputPointer.php | 11 ++-- .../classes/language/class_LanguageSystem.php | 7 ++- .../class_ConfigEntryIsEmptyException.php | 49 +----------------- .../class_SavePathIsEmptyException.php | 51 +------------------ .../class_FileIsEmptyException.php | 47 +---------------- .../class_PathIsEmptyException.php | 50 +----------------- .../class_LanguagePathIsEmptyException.php | 50 +----------------- 11 files changed, 30 insertions(+), 277 deletions(-) diff --git a/framework/main/classes/class_BaseFrameworkSystem.php b/framework/main/classes/class_BaseFrameworkSystem.php index f88b8d36..721e4ec5 100644 --- a/framework/main/classes/class_BaseFrameworkSystem.php +++ b/framework/main/classes/class_BaseFrameworkSystem.php @@ -50,6 +50,7 @@ use CoreFramework\Visitor\Visitor; // Import SPL stuff use \stdClass; +use \InvalidArgumentException; use \Iterator; use \ReflectionClass; use \SplFileInfo; diff --git a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php index 64688af7..5dfb15cb 100644 --- a/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php +++ b/framework/main/classes/file_directories/directory/class_FrameworkDirectoryPointer.php @@ -4,6 +4,7 @@ namespace CoreFramework\Filesytem\Pointer; // Import framework stuff use CoreFramework\Filesystem\FrameworkDirectory; +use CoreFramework\Generic\NullPointerException; use CoreFramework\Object\BaseFrameworkSystem; // Import SPL stuff @@ -69,44 +70,26 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework * be verified here. * * @param $pathName The path name we shall pass to opendir() - * @param $inConstructor If we are in de/con-structor or from somewhere else * @return $pointerInstance A prepared instance of FrameworkDirectoryPointer - * @throws PathIsEmptyException If the provided path name is empty + * @throws NullPointerException If the provided path name is null * @throws InvalidPathStringException If the provided path name is not a string * @throws PathIsNoDirectoryException If the provided path name is not valid * @throws PathReadProtectedException If the provided path name is read-protected - * @todo Get rid of inConstructor, could be old-lost code. */ - public static final function createFrameworkDirectoryPointer ($pathName, $inConstructor = false) { + public static final function createFrameworkDirectoryPointer ($pathName) { // Some pre-sanity checks... if (is_null($pathName)) { // No pathname given - if ($inConstructor) { - return NULL; - } else { - throw new PathIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } elseif (!is_string($pathName)) { // Is not a string - if ($inConstructor) { - return NULL; - } else { - throw new InvalidPathStringException(NULL, self::EXCEPTION_INVALID_STRING); - } + throw new InvalidPathStringException(NULL, self::EXCEPTION_INVALID_STRING); } elseif (!is_dir($pathName)) { // Not a directory - if ($inConstructor) { - return NULL; - } else { - throw new PathIsNoDirectoryException($pathName, self::EXCEPTION_INVALID_PATH_NAME); - } + throw new PathIsNoDirectoryException($pathName, self::EXCEPTION_INVALID_PATH_NAME); } elseif (!is_readable($pathName)) { // Not readable - if ($inConstructor) { - return NULL; - } else { - throw new PathReadProtectedException($pathName, self::EXCEPTION_READ_PROTECED_PATH); - } + throw new PathReadProtectedException($pathName, self::EXCEPTION_READ_PROTECED_PATH); } // Create new instance diff --git a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php index 0fdd4398..50c21f6c 100644 --- a/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php +++ b/framework/main/classes/file_directories/input/text/class_FrameworkTextFileInputPointer.php @@ -50,7 +50,6 @@ class FrameworkTextFileInputPointer extends BaseFileIo implements InputPointer { * be verified here. * * @param $fileName The file name we shall pass to fopen() - * @throws FileIsEmptyException If the provided file name is empty. * @throws FileIoException If the file is not reachable * @throws FileReadProtectedException If the file cannot be read from * @return void diff --git a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php index a63535c6..30189ba7 100644 --- a/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/raw/class_FrameworkRawFileOutputPointer.php @@ -8,6 +8,7 @@ use CoreFramework\Filesystem\Pointer\OutputPointer; use CoreFramework\Generic\NullPointerException; // Import SPL stuff +use \InvalidArgumentException; use \SplFileInfo; /** @@ -49,22 +50,22 @@ class FrameworkRawFileOutputPointer extends BaseFileIo implements OutputPointer * * @param $infoInstance An instance of a SplFileInfo class * @param $mode The output mode ('w', 'a' are valid) - * @throws FileIsEmptyException If the provided file name is empty. + * @throws InvalidArgumentException If parameter mode is empty * @throws FileIoException If fopen() returns not a file resource * @return void */ public static final function createFrameworkRawFileOutputPointer (SplFileInfo $infoInstance, $mode) { // Some pre-sanity checks... - if (is_null($infoInstance)) { + if (is_null($mode)) { // No infoInstance given - throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new InvalidArgumentException('Parameter "mode" is empty'); } // END - if // Try to open a handler $fileObject = $infoInstance->openFile($mode); if ((is_null($fileObject)) || ($fileObject === false)) { // Something bad happend - throw new FileIoException ($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); + throw new FileIoException($infoInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // END - if // Create new instance diff --git a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php index 425c57d9..dde389fb 100644 --- a/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php +++ b/framework/main/classes/file_directories/output/text/class_FrameworkTextFileOutputPointer.php @@ -9,6 +9,7 @@ use CoreFramework\Generic\NullPointerException; use CoreFramework\Generic\UnsupportedOperationException; // Import SPL stuff +use \InvalidArgumentException; use \SplFileInfo; /** @@ -50,22 +51,24 @@ class FrameworkTextFileOutputPointer extends BaseFileIo implements OutputPointer * * @param $fileInstance An instance of a SplFileInfo class * @param $mode The output mode ('w', 'a' are valid) - * @throws FileIsEmptyException If the provided file name is empty. + * @throws InvalidArgumentException If mode is empty * @throws FileIoException If fopen() returns not a file resource * @return void */ public static final function createFrameworkTextFileOutputPointer (SplFileInfo $fileInstance, $mode) { // Some pre-sanity checks... - if (is_null($fileInstance)) { + if (empty($mode)) { // No filename given - throw new FileIsEmptyException(NULL, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new InvalidArgumentException('Parameter "mode" is empty'); } // END - if // Try to open a handler $fileObject = $fileInstance->openFile($mode); + + // Is it valid? if ((is_null($fileObject)) || ($fileObject === false)) { // Something bad happend - throw new FileIoException ($fileName, self::EXCEPTION_FILE_POINTER_INVALID); + throw new FileIoException($fileInstance, self::EXCEPTION_FILE_POINTER_INVALID); } // END - if // Create new instance diff --git a/framework/main/classes/language/class_LanguageSystem.php b/framework/main/classes/language/class_LanguageSystem.php index 657c1137..89e29917 100644 --- a/framework/main/classes/language/class_LanguageSystem.php +++ b/framework/main/classes/language/class_LanguageSystem.php @@ -8,6 +8,9 @@ use CoreFramework\Object\BaseFrameworkSystem; use CoreFramework\Registry\Registerable; use CoreFramework\Registry\Registry; +// Import SPL stuff +use \InvalidArgumentException; + /** * The language sub-system for handling language strings being used in the * application and whole framework @@ -67,7 +70,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, * * @param $languageBasePath The local base path for all language strings or emty for auto-detection * @return $langInstance An instance of LanguageSystem - * @throws LanguagePathIsEmptyException If the provided $languageBasePath is empty + * @throws InvalidArgumentException If languageBasePath remains empty (@TODO Get rid of that old-lost code) * @throws InvalidLanguagePathStringException If $languageBasePath is no string * @throws LanguagePathIsNoDirectoryException If $languageBasePath is no * directory or not found @@ -94,7 +97,7 @@ class LanguageSystem extends BaseFrameworkSystem implements ManageableLanguage, // Is the base path valid? if (empty($languageBasePath)) { // Language path is empty - throw new LanguagePathIsEmptyException($langInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new InvalidArgumentException('languageBasePath is still empty'); } elseif (!is_string($languageBasePath)) { // Is not a string throw new InvalidLanguagePathStringException(array($langInstance, $languageBasePath), self::EXCEPTION_INVALID_STRING); diff --git a/framework/main/exceptions/config/class_ConfigEntryIsEmptyException.php b/framework/main/exceptions/config/class_ConfigEntryIsEmptyException.php index fc21d8ef..7d6dceec 100644 --- a/framework/main/exceptions/config/class_ConfigEntryIsEmptyException.php +++ b/framework/main/exceptions/config/class_ConfigEntryIsEmptyException.php @@ -1,49 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class ConfigEntryIsEmptyException extends FrameworkException { - /** - * The constructor - * - * @param $class Class throwing this exception - * @param $code Code number for the exception - * @return void - */ - public function __construct (FrameworkConfiguration $class, $code) { - // Add a message around the missing class - $message = sprintf('[%s:%d] Empty configuration entry provided.', - $class->__toString(), - $this->getLine() - ); - - // Call parent constructor - parent::__construct($message, $code); - } - -} +// @DEPRECATED diff --git a/framework/main/exceptions/database/local_file/class_SavePathIsEmptyException.php b/framework/main/exceptions/database/local_file/class_SavePathIsEmptyException.php index 454558f1..7d6dceec 100644 --- a/framework/main/exceptions/database/local_file/class_SavePathIsEmptyException.php +++ b/framework/main/exceptions/database/local_file/class_SavePathIsEmptyException.php @@ -1,51 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * @deprecated Please don't use this anymore. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class SavePathIsEmptyException extends DatabaseException { - /** - * The constructor - * - * @param $class Class throwing this exception - * @param $code Code number for the exception - * @return void - */ - public function __construct (FrameworkInterface $class, $code) { - // Add a message around the missing class - $message = sprintf('[%s:%d] Save path is empty.', - $class->__toString(), - $this->getLine() - ); - - // Call parent constructor - parent::__construct($message, $code); - } - -} +// @DEPRECATED diff --git a/framework/main/exceptions/file_directory/class_FileIsEmptyException.php b/framework/main/exceptions/file_directory/class_FileIsEmptyException.php index 55fe201e..7d6dceec 100644 --- a/framework/main/exceptions/file_directory/class_FileIsEmptyException.php +++ b/framework/main/exceptions/file_directory/class_FileIsEmptyException.php @@ -1,47 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * @deprecated Don't use this anymore - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class FileIsEmptyException extends FrameworkException { - /** - * The constructor - * - * @param $infoInstance An instance of a SplFileInfo class (ignored) - * @param $code Code number for the exception - * @return void - */ - public function __construct (SplFileInfo $infoInstance, $code) { - // Call parent constructor - parent::__construct('No file name provided.', $code); - } - -} +// @DEPRECATED diff --git a/framework/main/exceptions/file_directory/class_PathIsEmptyException.php b/framework/main/exceptions/file_directory/class_PathIsEmptyException.php index 4dcd3f14..7d6dceec 100644 --- a/framework/main/exceptions/file_directory/class_PathIsEmptyException.php +++ b/framework/main/exceptions/file_directory/class_PathIsEmptyException.php @@ -1,50 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class PathIsEmptyException extends FrameworkException { - /** - * The constructor - * - * @param $class Class throwing this exception - * @param $code Code number for the exception - * @return void - */ - public function __construct (FrameworkInterface $class, $code) { - // Add a message around the missing class - $message = sprintf('[%s:%d] Directory path is empty.', - $class->__toString(), - $this->getLine() - ); - - // Call parent constructor - parent::__construct($message, $code); - } - -} +// @DEPRECATED diff --git a/framework/main/exceptions/language/class_LanguagePathIsEmptyException.php b/framework/main/exceptions/language/class_LanguagePathIsEmptyException.php index 53e6aec5..7d6dceec 100644 --- a/framework/main/exceptions/language/class_LanguagePathIsEmptyException.php +++ b/framework/main/exceptions/language/class_LanguagePathIsEmptyException.php @@ -1,50 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class LanguagePathIsEmptyException extends FrameworkException { - /** - * The constructor - * - * @param $class Class throwing this exception - * @param $code Code number for the exception - * @return void - */ - public function __construct (FrameworkInterface $class, $code) { - // Add a message around the missing class - $message = sprintf('[%s:%d] Language base path is empty.', - $class->__toString(), - $this->getLine() - ); - - // Call parent constructor - parent::__construct($message, $code); - } - -} +// @DEPRECATED -- 2.39.5