From: Roland Häder Date: Tue, 24 Jun 2008 13:57:33 +0000 (+0000) Subject: Unneccessary sanity checks removed X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=dbcca4302701f2adb974660901d4b32c3f633eac;p=shipsimu.git Unneccessary sanity checks removed --- diff --git a/.gitattributes b/.gitattributes index d593455..09c7448 100644 --- a/.gitattributes +++ b/.gitattributes @@ -30,7 +30,7 @@ application/ship-simu/exceptions/class_InvalidContractPartnerException.php -text application/ship-simu/exceptions/class_InvalidIDFormatException.php -text application/ship-simu/exceptions/class_ItemNotInPriceListException.php -text application/ship-simu/exceptions/class_ItemNotTradeableException.php -text -application/ship-simu/exceptions/class_MissingSimulatorIDException.php -text +application/ship-simu/exceptions/class_MissingSimulatorIdException.php -text application/ship-simu/exceptions/class_MotorShipMismatchException.php -text application/ship-simu/exceptions/class_NoShipyardsConstructedException.php -text application/ship-simu/exceptions/class_PersonellListAlreadyCreatedException.php -text diff --git a/application/selector/class_ApplicationSelector.php b/application/selector/class_ApplicationSelector.php index be289bf..e974a3b 100644 --- a/application/selector/class_ApplicationSelector.php +++ b/application/selector/class_ApplicationSelector.php @@ -121,10 +121,6 @@ class ApplicationSelector extends BaseFrameworkSystem { * @param $initScript The FQFN of init.php * @param $appName The application's Uni* name * @return void - * @throws AppVarIsNotSetException If 'app' is not set - * @throws NullPointerException If 'app' is null - * @throws NoObjectException If 'app' is not an object - * @throws MissingMethodException If a required method is missing */ private function loadInitScript ($initScript, $appName) { // Is it a file and readable? @@ -132,21 +128,6 @@ class ApplicationSelector extends BaseFrameworkSystem { // Then include it include ($initScript); - // We now should have $app re-defined! - if (!isset($app)) { - // This application shall not be loaded - return; - } elseif (is_null($app)) { - // The class instance is null - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($app)) { - // Not an object - throw new NoObjectException($app, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($app, $this->getConfigInstance()->readConfig('entry_method'))) { - // Method not found! - throw new MissingMethodException(array($app, $this->getConfigInstance()->readConfig('entry_method')), self::EXCEPTION_MISSING_METHOD); - } - // Add the current instance to the list $this->foundApps->append($app); diff --git a/application/ship-simu/exceptions/class_MissingSimulatorIDException.php b/application/ship-simu/exceptions/class_MissingSimulatorIDException.php deleted file mode 100644 index 228b95c..0000000 --- a/application/ship-simu/exceptions/class_MissingSimulatorIDException.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.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 MissingSimulatorIDException extends FrameworkException { - public function __construct (array $classArray, $code) { - // Add a message around the missing class - $message = sprintf("[%s:] Die Simulator-ID %s scheint ungültig zu sein.", - $classArray[0]->__toString(), - $classArray[1] - ); - - // Call parent constructor - parent::__construct($message, $code); - } -} - -// [EOF] -?> diff --git a/application/ship-simu/exceptions/class_MissingSimulatorIdException.php b/application/ship-simu/exceptions/class_MissingSimulatorIdException.php new file mode 100644 index 0000000..ea3fb23 --- /dev/null +++ b/application/ship-simu/exceptions/class_MissingSimulatorIdException.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.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 MissingSimulatorIdException extends FrameworkException { + public function __construct (array $classArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:] Die Simulator-ID %s scheint ungültig zu sein.", + $classArray[0]->__toString(), + $classArray[1] + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/application/ship-simu/interfaces/class_Customer.php b/application/ship-simu/interfaces/class_Customer.php index c52ec8d..2814614 100644 --- a/application/ship-simu/interfaces/class_Customer.php +++ b/application/ship-simu/interfaces/class_Customer.php @@ -25,7 +25,7 @@ interface Customer extends FrameworkInterface { /** * Adds a contract to the customer's list * - * @param $contractInstance A valid instance to WorksContract + * @param $contractInstance A valid instance to WorksContract * @return void */ function addNewWorksContract (SignableContract $contractInstance); @@ -33,17 +33,10 @@ interface Customer extends FrameworkInterface { /** * Signs a works contract. * - * @param $contractInstance A valid instance to WorksContract - * @param $partnerInstance An instance the other - * contract partner + * @param $contractInstance A valid instance to WorksContract + * @param $partnerInstance An instance the other contract partner * @return void - * @throws NullPointerException If an instance variable - * is null - * @throws NoObjectException If an instance variable - * is not an object - * @throws MissingMethodException If a required method was - * not found in $contractInstance - * @throws InvalidContractPartnerException If the in $contractInstance + * @throws InvalidContractPartnerException If the in $contractInstance * set contract partner is * not the expected */ @@ -52,7 +45,7 @@ interface Customer extends FrameworkInterface { /** * Withdraw from a signed contract * - * @param $contractInstance A valid instance to WorksContract + * @param $contractInstance A valid instance to WorksContract * @return void */ function withdrawFromContract (SignableContract $contractInstance); diff --git a/application/ship-simu/main/class_WorksContract.php b/application/ship-simu/main/class_WorksContract.php index b776759..b25c8ee 100644 --- a/application/ship-simu/main/class_WorksContract.php +++ b/application/ship-simu/main/class_WorksContract.php @@ -314,7 +314,7 @@ class WorksContract extends BaseFrameworkSystem implements SignableContract { } elseif (!is_object($item)) { // Not an object! ;-( throw new NoObjectException($item, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($item, 'getPartInstance')) { + } elseif (!$item instanceof BaseSimulator) { // Does not have the required feature (method) throw new MissingMethodException(array($item, 'getPartInstance'), self::EXCEPTION_MISSING_METHOD); } diff --git a/application/ship-simu/main/personell/class_SimulatorPersonell.php b/application/ship-simu/main/personell/class_SimulatorPersonell.php index 9cc0adb..08d6938 100644 --- a/application/ship-simu/main/personell/class_SimulatorPersonell.php +++ b/application/ship-simu/main/personell/class_SimulatorPersonell.php @@ -122,16 +122,11 @@ class SimulatorPersonell extends BasePersonell { * Create a SimulatorPersonell object by loading the specified personell * list from an existing database backend * - * @param $idNumber The ID number (only right part) of the list - * @return $personellInstance An instance of - * @throws InvalidIDFormatException If the given id number - * $idNumber is invalid - * @throws NullPointerException If a null pointer (instance) - * has been returned. - * @throws NoObjectException If a non-object has been - * returned - * @throws MissingMethodException If a required method is missing - * @throws MissingSimulatorIDException If an ID number was not found + * @param $idNumber The ID number (only right part) of the list + * @return $personellInstance An instance of this class + * @throws InvalidIDFormatException If the given id number + * $idNumber is invalid + * @throws MissingSimulatorIdException If an ID number was not found */ public final static function createSimulatorPersonellByID ($idNumber) { // Add the class name if it was not found @@ -155,22 +150,10 @@ class SimulatorPersonell extends BasePersonell { // Get database instance $dbInstance = $personellInstance->getDatabaseInstance(); - // Is this a valid database instance? - if (is_null($dbInstance)) { - // No class returned - throw new NullPointerException($personellInstance, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($dbInstance)) { - // Not an object! ;-( - throw new NoObjectException($dbInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($dbInstance, 'isUniqueIdUsed')) { - // Required method not found - throw new MissingMethodException(array($dbInstance, 'isUniqueIdUsed'), self::EXCEPTION_MISSING_METHOD); - } - // Is the unique ID already used? Then it must be there! if (!$dbInstance->isUniqueIdUsed($tempID)) { // Entry not found! - throw new MissingSimulatorIDException(array($personellInstance, $idNumber), self::EXCEPTION_SIMULATOR_ID_INVALID); + throw new MissingSimulatorIdException(array($personellInstance, $idNumber), self::EXCEPTION_SIMULATOR_ID_INVALID); } // Load the personell list and add it to this object diff --git a/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php b/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php index 1966161..5b73d51 100644 --- a/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php +++ b/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php @@ -26,16 +26,12 @@ interface FrameworkDatabaseInterface extends FrameworkInterface { * Analyses if a unique ID has already been used or not. This method does * only pass the given ID through to the "real" database layer. * - * @param $uniqueID A unique ID number which shall be checked - * before it will be used - * @param $inConstructor If called from a constructor or from - * somewhere else - * @return $isUnused true = The unique ID was not found in the database, - * false = It is already in use by an other object - * @throws NullPointerException If $dbInstance is null - * @throws NoObjectException If $dbInstance is not an object - * @throws MissingMethodException If the required method - * isUniqueIdUsed() was not found + * @param $uniqueID A unique ID number which shall be checked + * before it will be used + * @param $inConstructor If called from a constructor or from + * somewhere else + * @return $isUnused true = The unique ID was not found in the database, + * false = It is already in use by an other object */ function isUniqueIdUsed ($uniqueID, $inConstructor = false); } diff --git a/inc/classes/interfaces/io/file/class_FileInputStreamer.php b/inc/classes/interfaces/io/file/class_FileInputStreamer.php index 5dc756b..19e81ef 100644 --- a/inc/classes/interfaces/io/file/class_FileInputStreamer.php +++ b/inc/classes/interfaces/io/file/class_FileInputStreamer.php @@ -25,12 +25,8 @@ interface FileInputStreamer extends Streamable { /** * Reads from a local or remote file * - * @param $fqfn The file's FQFN we shall load + * @param $fqfn The file's FQFN we shall load * @return $array An array containing all read lines - * @throws NullPointerException If an instance is null - * @throws NoObjectException If the instance is not an object - * instance - * @throws MissingMethodException If a required method is missing. * @throws InvalidArrayCountException If an array has not the * expected size * @throws InvalidMD5ChecksumException If two MD5 hashes did not match diff --git a/inc/classes/interfaces/io/file/class_FileOutputStreamer.php b/inc/classes/interfaces/io/file/class_FileOutputStreamer.php index 2862c54..1c8cd02 100644 --- a/inc/classes/interfaces/io/file/class_FileOutputStreamer.php +++ b/inc/classes/interfaces/io/file/class_FileOutputStreamer.php @@ -26,14 +26,10 @@ interface FileOutputStreamer extends Streamable { * Saves streamed (that are mostly serialized objects) data to files or * external servers. * - * @param $fileName The local file's name including full path - * @param $dataArray Array containing the compressor's extension + * @param $fileName The local file's name including full path + * @param $dataArray Array containing the compressor's extension * and streamed data * @return void - * @throws NullPointerException If an instance is null - * @throws NoObjectException If the instance is not an object - * instance - * @throws MissingMethodException If a required method is missing. */ function saveFile ($fileName, $dataArray); } diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index c0b8899..aa5b2ab 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -531,27 +531,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * * @param $fqfn The full-qualified file name for a template * @return void - * @throws NullPointerException If $inputInstance is null - * @throws NoObjectException If $inputInstance is not an object - * @throws MissingMethodException If $inputInstance is missing a - * required method */ private function loadRawTemplateData ($fqfn) { // Get a input/output instance from the middleware $ioInstance = $this->getFileIoInstance(); - // Validate the instance - if (is_null($ioInstance)) { - // Throw exception - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($ioInstance)) { - // Throw another exception - throw new NoObjectException($ioInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($ioInstance, 'loadFileContents')) { - // Throw yet another exception - throw new MissingMethodException(array($ioInstance, 'loadFileContents'), self::EXCEPTION_MISSING_METHOD); - } - // Some debug code to look on the file which is being loaded //* DEBUG: */ echo __METHOD__.": FQFN=".$fqfn."
\n"; diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index ed1f8d0..c67da37 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -110,18 +110,6 @@ class DebugMiddleware extends BaseMiddleware implements Registerable { * @return void */ public final function output ($outStream) { - // Check if the output instance is valid - if (is_null($this->outputInstance)) { - // Debug output instance was not set - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($this->outputInstance)) { - // The debug output instance is not an object - throw new NoObjectException($this->ouputInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!$this->outputInstance instanceof Debugger) { - // The required method outputStream() is missing - throw new MissingMethodException(array($this->outputInstance, 'outputStream'), self::EXCEPTION_MISSING_METHOD); - } - // Is the output stream set if (empty($outStream)) { // Initialization phase diff --git a/inc/classes/middleware/io/class_FileIoHandler.php b/inc/classes/middleware/io/class_FileIoHandler.php index 99cb434..e564810 100644 --- a/inc/classes/middleware/io/class_FileIoHandler.php +++ b/inc/classes/middleware/io/class_FileIoHandler.php @@ -61,7 +61,7 @@ class FileIoHandler extends BaseMiddleware { * Creates an instance of this class and prepares the IO system. This is * being done by setting the default file IO class * - * @return $ioInstance A prepared instance of FilIOHandler + * @return $ioInstance A prepared instance of FilIOHandler */ public final static function createFileIoHandler () { // Get instance @@ -87,7 +87,8 @@ class FileIoHandler extends BaseMiddleware { /** * Setter for the *real* file input instance * - * @param $inputStream The *real* file-input class + * @param $inputStream The *real* file-input class + * @return void */ public final function setInputStream (FileInputStreamer $inputStream) { $this->inputStream = $inputStream; @@ -105,7 +106,8 @@ class FileIoHandler extends BaseMiddleware { /** * Setter for the *real* file output instance * - * @param $outputStream The *real* file-output class + * @param $outputStream The *real* file-output class + * @return void */ public final function setOutputStream (FileOutputStreamer $outputStream) { $this->outputStream = $outputStream; @@ -123,51 +125,28 @@ class FileIoHandler extends BaseMiddleware { /** * Saves a file with data by using the current output stream * - * @see FileOutputStreamer + * @param $fileName Name of the file + * @param $dataArray Array with file contents + * @return void + * @see FileOutputStreamer */ public function saveFile ($fileName, $dataArray) { // Get output stream $outInstance = $this->getOutputStream(); - // Is it a valid stream? - if (is_null($outInstance)) { - // No class returned - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($outInstance)) { - // Not an object! ;-( - throw new NoObjectException($outInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($outInstance, 'saveFile')) { - // Nope, so throw exception - throw new MissingMethodException(array($outInstance, 'saveFile'), self::EXCEPTION_MISSING_METHOD); - } - // Send the fileName and dataArray to the output handler $outInstance->saveFile($fileName, $dataArray); } /** Loads data from a file over the input handler * - * @see FileInputStreamer + * @return $array Array with the file contents + * @see FileInputStreamer */ public function loadFileContents ($fqfn) { - // Initialize the array - $array = array(); - // Get output stream $inInstance = $this->getInputStream(); - // Is it a valid stream? - if (is_null($inInstance)) { - // No class returned - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!is_object($inInstance)) { - // Not an object! ;-( - throw new NoObjectException($inInstance, self::EXCEPTION_IS_NO_OBJECT); - } elseif (!method_exists($inInstance, 'loadFileContents')) { - // Nope, so throw exception - throw new MissingMethodException(array($inInstance, 'loadFileContents'), self::EXCEPTION_MISSING_METHOD); - } - // Read from the input handler return $inInstance->loadFileContents($fqfn); }