diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php index e81e8062f..f794d46a0 100644 --- a/library/Icinga/Application/Config.php +++ b/library/Icinga/Application/Config.php @@ -61,7 +61,10 @@ class Config extends Zend_Config $this->configFile = $filepath; $this->merge(new Zend_Config_Ini($filepath)); } else { - throw new NotReadableError('Cannot read config file "' . $filename . '". Permission denied'); + throw new NotReadableError( + 'Cannot read config file "%s". Permission denied', + $filename + ); } } diff --git a/library/Icinga/Application/Loader.php b/library/Icinga/Application/Loader.php index 56e59f4b2..15c3a9316 100644 --- a/library/Icinga/Application/Loader.php +++ b/library/Icinga/Application/Loader.php @@ -39,11 +39,11 @@ class Loader public function registerNamespace($namespace, $directory) { if (!is_dir($directory)) { - throw new ProgrammingError(sprintf( + throw new ProgrammingError( 'Directory "%s" for namespace "%s" does not exist', $directory, $namespace - )); + ); } $this->namespaces[$namespace] = $directory; diff --git a/library/Icinga/Application/Modules/Manager.php b/library/Icinga/Application/Modules/Manager.php index 28241adc3..60c2ee85b 100644 --- a/library/Icinga/Application/Modules/Manager.php +++ b/library/Icinga/Application/Modules/Manager.php @@ -110,12 +110,14 @@ class Manager } if (!is_dir($this->enableDir)) { throw new NotReadableError( - 'Cannot read enabled modules. Module directory "' . $this->enableDir . '" is not a directory' + 'Cannot read enabled modules. Module directory "%s" is not a directory', + $this->enableDir ); } if (!is_readable($this->enableDir)) { throw new NotReadableError( - 'Cannot read enabled modules. Module directory "' . $this->enableDir . '" is not readable' + 'Cannot read enabled modules. Module directory "%s" is not readable', + $this->enableDir ); } if (($dh = opendir($canonical)) !== false) { @@ -206,10 +208,8 @@ class Manager { if (!$this->hasInstalled($name)) { throw new ConfigurationError( - sprintf( - 'Cannot enable module "%s". Module is not installed.', - $name - ) + 'Cannot enable module "%s". Module is not installed.', + $name ); } @@ -219,8 +219,8 @@ class Manager if (!is_writable($this->enableDir)) { throw new SystemPermissionException( - 'Can not enable module "' . $name . '". ' - . 'Insufficient system permissions for enabling modules.' + 'Can not enable module "%s". Insufficient system permissions for enabling modules.', + $name ); } @@ -232,9 +232,11 @@ class Manager $error = error_get_last(); if (strstr($error["message"], "File exists") === false) { throw new SystemPermissionException( - 'Could not enable module "' . $name . '" due to file system errors. ' + 'Could not enable module "%s" due to file system errors. ' . 'Please check path and mounting points because this is not a permission error. ' - . 'Primary error was: ' . $error['message'] + . 'Primary error was: %s', + $name, + $error['message'] ); } } @@ -268,14 +270,18 @@ class Manager } $link = $this->enableDir . '/' . $name; if (!file_exists($link)) { - throw new ConfigurationError('Could not disable module. The module ' . $name . ' was not found.'); + throw new ConfigurationError( + 'Could not disable module. The module %s was not found.', + $name + ); } if (!is_link($link)) { throw new ConfigurationError( - 'Could not disable module. The module "' . $name . '" is not a symlink. ' + 'Could not disable module. The module "%s" is not a symlink. ' . 'It looks like you have installed this module manually and moved it to your module folder. ' . 'In order to dynamically enable and disable modules, you have to create a symlink to ' - . 'the enabled_modules folder.' + . 'the enabled_modules folder.', + $name ); } @@ -283,9 +289,11 @@ class Manager if (!@unlink($link)) { $error = error_get_last(); throw new SystemPermissionException( - 'Could not disable module "' . $name . '" due to file system errors. ' + 'Could not disable module "%s" due to file system errors. ' . 'Please check path and mounting points because this is not a permission error. ' - . 'Primary error was: ' . $error['message'] + . 'Primary error was: %s', + $name, + $error['message'] ); } } @@ -319,10 +327,8 @@ class Manager } throw new ProgrammingError( - sprintf( - 'Trying to access uninstalled module dir: %s', - $name - ) + 'Trying to access uninstalled module dir: %s', + $name ); } @@ -388,10 +394,8 @@ class Manager { if (!$this->hasLoaded($name)) { throw new ProgrammingError( - sprintf( - 'Cannot access module %s as it hasn\'t been loaded', - $name - ) + 'Cannot access module %s as it hasn\'t been loaded', + $name ); } return $this->loadedModules[$name]; diff --git a/library/Icinga/Authentication/AuthChain.php b/library/Icinga/Authentication/AuthChain.php index 216344735..4ab87f7ae 100644 --- a/library/Icinga/Authentication/AuthChain.php +++ b/library/Icinga/Authentication/AuthChain.php @@ -97,7 +97,9 @@ class AuthChain implements Iterator } catch (ConfigurationError $e) { Logger::error( new ConfigurationError( - 'Cannot create authentication backend "' . $name . '". An exception was thrown:', 0, $e + 'Cannot create authentication backend "%s". An exception was thrown:', + $name, + $e ) ); $this->next(); diff --git a/library/Icinga/Authentication/Backend/DbUserBackend.php b/library/Icinga/Authentication/Backend/DbUserBackend.php index 5961028b3..95c99c346 100644 --- a/library/Icinga/Authentication/Backend/DbUserBackend.php +++ b/library/Icinga/Authentication/Backend/DbUserBackend.php @@ -73,12 +73,9 @@ class DbUserBackend extends UserBackend return ($row !== false) ? true : false; } catch (Exception $e) { throw new AuthenticationException( - sprintf( - 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', - $user->getUsername(), - $this->getName() - ), - 0, + 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', + $user->getUsername(), + $this->getName(), $e ); } @@ -125,4 +122,4 @@ class DbUserBackend extends UserBackend return ($row !== false) ? $row->count : 0; } -} \ No newline at end of file +} diff --git a/library/Icinga/Authentication/Backend/LdapUserBackend.php b/library/Icinga/Authentication/Backend/LdapUserBackend.php index fe80e900a..23a79781d 100644 --- a/library/Icinga/Authentication/Backend/LdapUserBackend.php +++ b/library/Icinga/Authentication/Backend/LdapUserBackend.php @@ -68,21 +68,17 @@ class LdapUserBackend extends UserBackend $result = $q->fetchRow(); if (! isset($result)) { throw new AuthenticationException( - sprintf( - 'No objects with objectClass="%s" in DN="%s" found.', - $this->userClass, - $this->conn->getDN() - ) + 'No objects with objectClass="%s" in DN="%s" found.', + $this->userClass, + $this->conn->getDN() ); } if (! isset($result->{$this->userNameAttribute})) { throw new AuthenticationException( - sprintf( - 'UserNameAttribute "%s" not existing in objectClass="%s"', - $this->userNameAttribute, - $this->userClass - ) + 'UserNameAttribute "%s" not existing in objectClass="%s"', + $this->userNameAttribute, + $this->userClass ); } } @@ -121,11 +117,8 @@ class LdapUserBackend extends UserBackend } catch (AuthenticationException $e) { // Authentication not possible throw new AuthenticationException( - sprintf( - 'Authentication against backend "%s" not possible: ', - $this->getName() - ), - 0, + 'Authentication against backend "%s" not possible: ', + $this->getName(), $e ); } @@ -141,12 +134,9 @@ class LdapUserBackend extends UserBackend } catch (LdapException $e) { // Error during authentication of this specific user throw new AuthenticationException( - sprintf( - 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', - $user->getUsername(), - $this->getName() - ), - 0, + 'Failed to authenticate user "%s" against backend "%s". An exception was thrown:', + $user->getUsername(), + $this->getName(), $e ); } diff --git a/library/Icinga/Authentication/UserBackend.php b/library/Icinga/Authentication/UserBackend.php index f90eef1c7..9e7abd62a 100644 --- a/library/Icinga/Authentication/UserBackend.php +++ b/library/Icinga/Authentication/UserBackend.php @@ -54,16 +54,18 @@ abstract class UserBackend implements Countable // Use a custom backend class, this is only useful for testing if (!class_exists($backendConfig->class)) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name . '" defines an invalid backend' - . ' class. Backend class "' . $backendConfig->class. '" not found' + 'Authentication configuration for backend "%s" defines an invalid backend class.' + . ' Backend class "%s" not found', + $name, + $backendConfig->class ); } return new $backendConfig->class($backendConfig); } if (($backendType = $backendConfig->backend) === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the backend directive' + 'Authentication configuration for backend "%s" is missing the backend directive', + $name ); } $backendType = strtolower($backendType); @@ -74,8 +76,8 @@ abstract class UserBackend implements Countable } if ($backendConfig->resource === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the resource directive' + 'Authentication configuration for backend "%s" is missing the resource directive', + $name ); } try { @@ -100,22 +102,24 @@ abstract class UserBackend implements Countable case 'ldap': if (($userClass = $backendConfig->user_class) === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the user_class directive' + 'Authentication configuration for backend "%s" is missing the user_class directive', + $name ); } if (($userNameAttribute = $backendConfig->user_name_attribute) === null) { throw new ConfigurationError( - 'Authentication configuration for backend "' . $name - . '" is missing the user_name_attribute directive' + 'Authentication configuration for backend "%s" is missing the user_name_attribute directive', + $name ); } $backend = new LdapUserBackend($resource, $userClass, $userNameAttribute); break; default: throw new ConfigurationError( - 'Authentication configuration for backend "' . $name. '" defines an invalid backend' - . ' type. Backend type "' . $backendType . '" is not supported' + 'Authentication configuration for backend "%s" defines an invalid backend type.' + . ' Backend type "%s" is not supported', + $name, + $backendType ); } $backend->setName($name); diff --git a/library/Icinga/Cli/Loader.php b/library/Icinga/Cli/Loader.php index ab8064370..11ca2b70b 100644 --- a/library/Icinga/Cli/Loader.php +++ b/library/Icinga/Cli/Loader.php @@ -332,7 +332,8 @@ class Loader { if (! $this->hasModule($module)) { throw new ProgrammingError( - sprintf('There is no such module: %s', $module) + 'There is no such module: %s', + $module ); } } @@ -341,7 +342,8 @@ class Loader { if (! $this->hasCommand($command)) { throw new ProgrammingError( - sprintf('There is no such command: %s', $command) + 'There is no such command: %s', + $command ); } } @@ -351,7 +353,9 @@ class Loader $this->assertModuleExists($module); if (! $this->hasModuleCommand($module, $command)) { throw new ProgrammingError( - sprintf("The module '%s' has no such command: %s", $module, $command) + 'The module \'%s\' has no such command: %s', + $module, + $command ); } } diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php index af9cce05c..da05a429f 100644 --- a/library/Icinga/Data/Db/DbConnection.php +++ b/library/Icinga/Data/Db/DbConnection.php @@ -142,7 +142,10 @@ class DbConnection implements Selectable } break;*/ default: - throw new ConfigurationError(sprintf('Backend "%s" is not supported', $this->dbType)); + throw new ConfigurationError( + 'Backend "%s" is not supported', + $this->dbType + ); } $this->dbAdapter = Zend_Db::factory($adapter, $adapterParamaters); $this->dbAdapter->setFetchMode(Zend_Db::FETCH_OBJ); diff --git a/library/Icinga/Data/Filter/Filter.php b/library/Icinga/Data/Filter/Filter.php index dc62e206a..7e995bb59 100644 --- a/library/Icinga/Data/Filter/Filter.php +++ b/library/Icinga/Data/Filter/Filter.php @@ -34,9 +34,12 @@ abstract class Filter if ((string) $id === $this->getId()) { return $this; } - throw new ProgrammingError(sprintf( - 'Trying to get invalid filter index "%s" from "%s" ("%s")', $id, $this, $this->id - )); + throw new ProgrammingError( + 'Trying to get invalid filter index "%s" from "%s" ("%s")', + $id, + $this, + $this->id + ); } public function getId() @@ -136,7 +139,8 @@ abstract class Filter case '<=': return new FilterEqualOrLessThan($col, $op, $expression); case '!=': return new FilterNotEqual($col, $op, $expression); default: throw new ProgrammingError( - sprintf('There is no such filter sign: %s', $op) + 'There is no such filter sign: %s', + $op ); } } @@ -188,7 +192,7 @@ abstract class Filter $args = $args[0]; } } - if (count($args) > 1) { + if (count($args) > 1) { return new FilterNot(array(new FilterAnd($args))); } else { return new FilterNot($args); @@ -203,7 +207,8 @@ abstract class Filter case 'NOT': return self::not($filters); } throw new ProgrammingError( - sprintf('"%s" is not a valid filter chain operator', $operator) + '"%s" is not a valid filter chain operator', + $operator ); } diff --git a/library/Icinga/Data/ResourceFactory.php b/library/Icinga/Data/ResourceFactory.php index 1db623e17..87f99c0e4 100644 --- a/library/Icinga/Data/ResourceFactory.php +++ b/library/Icinga/Data/ResourceFactory.php @@ -39,7 +39,8 @@ class ResourceFactory implements ConfigAwareFactory self::assertResourcesExist(); if (($resourceConfig = self::$resources->get($resourceName)) === null) { throw new ConfigurationError( - 'Cannot load resource config "' . $resourceName . '". Resource does not exist' + 'Cannot load resource config "%s". Resource does not exist', + $resourceName ); } return $resourceConfig; @@ -77,7 +78,7 @@ class ResourceFactory implements ConfigAwareFactory { if (!isset(self::$resources)) { throw new ProgrammingError( - "The ResourceFactory must be initialised by setting a config, before it can be used" + 'The ResourceFactory must be initialised by setting a config, before it can be used' ); } } @@ -113,7 +114,10 @@ class ResourceFactory implements ConfigAwareFactory $resource = new FileReader($config); break; default: - throw new ConfigurationError('Unsupported resource type "' . $config->type . '"'); + throw new ConfigurationError( + 'Unsupported resource type "%s"', + $config->type + ); } return $resource; } diff --git a/library/Icinga/Exception/AuthenticationException.php b/library/Icinga/Exception/AuthenticationException.php index 91180b796..ebed296e4 100644 --- a/library/Icinga/Exception/AuthenticationException.php +++ b/library/Icinga/Exception/AuthenticationException.php @@ -4,11 +4,9 @@ namespace Icinga\Exception; -use RuntimeException; - /** * Exception thrown if an error occurs during authentication */ -class AuthenticationException extends RuntimeException +class AuthenticationException extends IcingaException { } diff --git a/library/Icinga/Exception/ConfigurationError.php b/library/Icinga/Exception/ConfigurationError.php index 988246f5f..aee601a62 100644 --- a/library/Icinga/Exception/ConfigurationError.php +++ b/library/Icinga/Exception/ConfigurationError.php @@ -8,6 +8,6 @@ namespace Icinga\Exception; * Class ConfigurationError * @package Icinga\Exception */ -class ConfigurationError extends \RuntimeException +class ConfigurationError extends IcingaException { } diff --git a/library/Icinga/Exception/IcingaException.php b/library/Icinga/Exception/IcingaException.php new file mode 100644 index 000000000..8443f9c7c --- /dev/null +++ b/library/Icinga/Exception/IcingaException.php @@ -0,0 +1,29 @@ +type)) . 'Writer'; if (!class_exists($class)) { - throw new ConfigurationError('Cannot find log writer of type "' . $config->type . '"'); + throw new ConfigurationError( + 'Cannot find log writer of type "%s"', + $config->type + ); } return new $class($config); diff --git a/library/Icinga/Logger/Writer/FileWriter.php b/library/Icinga/Logger/Writer/FileWriter.php index fef2e8bc7..2795b3541 100644 --- a/library/Icinga/Logger/Writer/FileWriter.php +++ b/library/Icinga/Logger/Writer/FileWriter.php @@ -33,13 +33,20 @@ class FileWriter extends LogWriter $this->path = $config->target; if (substr($this->path, 0, 6) !== 'php://' && false === file_exists(dirname($this->path))) { - throw new ConfigurationError('Log path "' . dirname($this->path) . '" does not exist'); + throw new ConfigurationError( + 'Log path "%s" does not exist', + dirname($this->path) + ); } try { $this->write(''); // Avoid to handle such errors on every write access } catch (Exception $e) { - throw new ConfigurationError('Cannot write to log file "' . $this->path . '" (' . $e->getMessage() . ')'); + throw new ConfigurationError( + 'Cannot write to log file "%s" (%s)', + $this->path, + $e->getMessage() + ); } } diff --git a/library/Icinga/Logger/Writer/SyslogWriter.php b/library/Icinga/Logger/Writer/SyslogWriter.php index fea20b592..8f7711a8a 100644 --- a/library/Icinga/Logger/Writer/SyslogWriter.php +++ b/library/Icinga/Logger/Writer/SyslogWriter.php @@ -45,7 +45,8 @@ class SyslogWriter extends LogWriter { if (!array_key_exists($config->facility, $this->facilities)) { throw new ConfigurationError( - 'Cannot create syslog writer with unknown facility "' . $config->facility . '"' + 'Cannot create syslog writer with unknown facility "%s"', + $config->facility ); } diff --git a/library/Icinga/Protocol/Commandpipe/Command.php b/library/Icinga/Protocol/Commandpipe/Command.php index b7332ce33..e89169f35 100644 --- a/library/Icinga/Protocol/Commandpipe/Command.php +++ b/library/Icinga/Protocol/Commandpipe/Command.php @@ -138,7 +138,10 @@ abstract class Command */ public function getHostgroupCommand($hostgroup) { - throw new ProgrammingError(get_class($this) . ' does not provide a hostgroup command'); + throw new ProgrammingError( + '%s does not provide a hostgroup command', + get_class($this) + ); } /** @@ -150,7 +153,10 @@ abstract class Command */ public function getServicegroupCommand($servicegroup) { - throw new ProgrammingError(get_class($this) . ' does not provide a servicegroup command'); + throw new ProgrammingError( + '%s does not provide a servicegroup command', + get_class($this) + ); } /** @@ -163,6 +169,9 @@ abstract class Command */ public function getGlobalCommand($instance = null) { - throw new ProgrammingError(getclass($this) . ' does not provide a global command'); + throw new ProgrammingError( + '%s does not provide a global command', + getclass($this) + ); } } diff --git a/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php b/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php index ecf1a981c..32f745565 100644 --- a/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php +++ b/library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php @@ -49,11 +49,9 @@ class LocalPipe implements Transport $file->fflush(); } catch (Exception $e) { throw new ConfigurationError( - sprintf( - 'Could not open icinga command pipe at "%s" (%s)', - $this->path, - $e->getMessage() - ) + 'Could not open icinga command pipe at "%s" (%s)', + $this->path, + $e->getMessage() ); } diff --git a/library/Icinga/Protocol/Statusdat/Reader.php b/library/Icinga/Protocol/Statusdat/Reader.php index e9b767127..6891e7ba8 100644 --- a/library/Icinga/Protocol/Statusdat/Reader.php +++ b/library/Icinga/Protocol/Statusdat/Reader.php @@ -246,7 +246,8 @@ class Reader implements IReader, Selectable { if (!is_readable($this->config->object_file)) { throw new ConfigurationError( - 'Can\'t read object-file "' . $this->config->object_file . '", check your configuration' + 'Can\'t read object-file "%s", check your configuration', + $this->config->object_file ); } if (!$this->parser) { @@ -265,7 +266,8 @@ class Reader implements IReader, Selectable { if (!is_readable($this->config->status_file)) { throw new ConfigurationError( - "Can't read status-file {$this->config->status_file}, check your configuration" + 'Can\'t read status-file %s, check your configuration', + $this->config->status_file ); } if (!$this->parser) { diff --git a/library/Icinga/User/Preferences/PreferencesStore.php b/library/Icinga/User/Preferences/PreferencesStore.php index 81d47b394..749d054dc 100644 --- a/library/Icinga/User/Preferences/PreferencesStore.php +++ b/library/Icinga/User/Preferences/PreferencesStore.php @@ -127,7 +127,8 @@ abstract class PreferencesStore $storeClass = 'Icinga\\User\\Preferences\\Store\\' . $type . 'Store'; if (!class_exists($storeClass)) { throw new ConfigurationError( - 'Preferences configuration defines an invalid storage type. Storage type ' . $type . ' not found' + 'Preferences configuration defines an invalid storage type. Storage type %s not found', + $type ); } diff --git a/library/Icinga/User/Preferences/Store/DbStore.php b/library/Icinga/User/Preferences/Store/DbStore.php index 728637a35..348a4f04d 100644 --- a/library/Icinga/User/Preferences/Store/DbStore.php +++ b/library/Icinga/User/Preferences/Store/DbStore.php @@ -78,7 +78,9 @@ class DbStore extends PreferencesStore ->fetchAll(); } catch (Exception $e) { throw new NotReadableError( - 'Cannot fetch preferences for user ' . $this->getUser()->getUsername() . ' from database', 0, $e + 'Cannot fetch preferences for user %s from database', + $this->getUser()->getUsername(), + $e ); } @@ -145,7 +147,9 @@ class DbStore extends PreferencesStore } } catch (Exception $e) { throw new NotWritableError( - 'Cannot insert preferences for user ' . $this->getUser()->getUsername() . ' into database', 0, $e + 'Cannot insert preferences for user %s into database', + $this->getUser()->getUsername(), + $e ); } } @@ -174,7 +178,9 @@ class DbStore extends PreferencesStore } } catch (Exception $e) { throw new NotWritableError( - 'Cannot update preferences for user ' . $this->getUser()->getUsername() . ' in database', 0, $e + 'Cannot update preferences for user %s in database', + $this->getUser()->getUsername(), + $e ); } } @@ -200,7 +206,9 @@ class DbStore extends PreferencesStore ); } catch (Exception $e) { throw new NotWritableError( - 'Cannot delete preferences for user ' . $this->getUser()->getUsername() . ' from database', 0, $e + 'Cannot delete preferences for user %s from database', + $this->getUser()->getUsername(), + $e ); } } diff --git a/library/Icinga/User/Preferences/Store/IniStore.php b/library/Icinga/User/Preferences/Store/IniStore.php index eb1c4cbfb..1f01925c9 100644 --- a/library/Icinga/User/Preferences/Store/IniStore.php +++ b/library/Icinga/User/Preferences/Store/IniStore.php @@ -62,8 +62,9 @@ class IniStore extends PreferencesStore if (file_exists($this->preferencesFile)) { if (!is_readable($this->preferencesFile)) { throw new NotReadableError( - 'Preferences INI file ' . $this->preferencesFile . ' for user ' - . $this->getUser()->getUsername() . ' is not readable' + 'Preferences INI file %s for user %s is not readable', + $this->preferencesFile, + $this->getUser()->getUsername() ); } else { $this->preferences = parse_ini_file($this->preferencesFile); @@ -97,10 +98,8 @@ class IniStore extends PreferencesStore if (!file_exists($this->preferencesFile)) { if (!is_writable($this->getStoreConfig()->location)) { throw new NotWritableError( - sprintf( - 'Path to the preferences INI files %s is not writable', - $this->getStoreConfig()->location - ) + 'Path to the preferences INI files %s is not writable', + $this->getStoreConfig()->location ); } @@ -109,8 +108,9 @@ class IniStore extends PreferencesStore if (!is_writable($this->preferencesFile)) { throw new NotWritableError( - 'Preferences INI file ' . $this->preferencesFile . ' for user ' - . $this->getUser()->getUsername() . ' is not writable' + 'Preferences INI file %s for user %s is not writable', + $this->preferencesFile, + $this->getUser()->getUsername() ); } diff --git a/library/Icinga/Util/Format.php b/library/Icinga/Util/Format.php index 0658b2a57..0c69fbde4 100644 --- a/library/Icinga/Util/Format.php +++ b/library/Icinga/Util/Format.php @@ -95,7 +95,10 @@ class Format return '-'; } if (! preg_match('~^\d+$~', $timestamp)) { - throw new ProgrammingError(sprintf('"%s" is not a number', $timestamp)); + throw new ProgrammingError( + '"%s" is not a number', + $timestamp + ); } $prefix = ''; if ($diff < 0) { diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index d6f07cd3a..65dc7c8d1 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -369,8 +369,8 @@ class Form extends Zend_Form $element->setAttrib('class', $class); } else { throw new ProgrammingError( - 'You need to add the element "' . $elementName . '" to' . - ' the form before automatic submission can be enabled!' + 'You need to add the element "%s" to the form before automatic submission can be enabled!', + $elementName ); } } diff --git a/library/Icinga/Web/Hook.php b/library/Icinga/Web/Hook.php index 2b776daca..76200493a 100644 --- a/library/Icinga/Web/Hook.php +++ b/library/Icinga/Web/Hook.php @@ -117,11 +117,9 @@ class Hook $base_class = self::$BASE_NS . ucfirst($name); if (!$instance instanceof $base_class) { throw new ProgrammingError( - sprintf( - '%s is not an instance of %s', - get_class($instance), - $base_class - ) + '%s is not an instance of %s', + get_class($instance), + $base_class ); } } @@ -185,7 +183,10 @@ class Hook public static function registerClass($name, $key, $class) { if (!class_exists($class)) { - throw new ProgrammingError('"' . $class . '" is not an existing class'); + throw new ProgrammingError( + '"%s" is not an existing class', + $class + ); } if (!isset(self::$hooks[$name])) { @@ -207,7 +208,10 @@ class Hook public static function registerObject($name, $key, $object) { if (!is_object($object)) { - throw new ProgrammingError('"' . $object . '" is not an instantiated class'); + throw new ProgrammingError( + '"%s" is not an instantiated class', + $object + ); } if (!isset(self::$instances[$name])) { diff --git a/library/Icinga/Web/Menu.php b/library/Icinga/Web/Menu.php index 0d8cda402..2fa49b99c 100644 --- a/library/Icinga/Web/Menu.php +++ b/library/Icinga/Web/Menu.php @@ -456,7 +456,10 @@ class Menu implements RecursiveIterator public function getSubMenu($id) { if (false === $this->hasSubMenu($id)) { - throw new ProgrammingError('Tried to get invalid sub menu "' . $id . '"'); + throw new ProgrammingError( + 'Tried to get invalid sub menu "%s"', + $id + ); } return $this->subMenus[$id]; diff --git a/library/Icinga/Web/Notification.php b/library/Icinga/Web/Notification.php index 3dd04c615..178a07e0a 100644 --- a/library/Icinga/Web/Notification.php +++ b/library/Icinga/Web/Notification.php @@ -53,10 +53,8 @@ class Notification ) )) { throw new ProgrammingError( - sprintf( - '"%s" is not a valid notification type', - $type - ) + '"%s" is not a valid notification type', + $type ); } diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index ed3acf6a7..9f0294c3c 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -120,7 +120,10 @@ class Url } if (!is_string($url)) { - throw new ProgrammingError(sprintf('url "%s" is not a string', $url)); + throw new ProgrammingError( + 'url "%s" is not a string', + $url + ); } $urlObject = new Url(); diff --git a/library/Icinga/Web/View.php b/library/Icinga/Web/View.php index b74bca41c..22e8e6fbd 100644 --- a/library/Icinga/Web/View.php +++ b/library/Icinga/Web/View.php @@ -103,10 +103,8 @@ class View extends Zend_View_Abstract { if ($this->hasHelperFunction($name)) { throw new ProgrammingError( - sprintf( - 'Cannot assign the same helper function twice: "%s"', - $name - ) + 'Cannot assign the same helper function twice: "%s"', + $name ); } diff --git a/library/Icinga/Web/View/helpers/url.php b/library/Icinga/Web/View/helpers/url.php index 14b741e78..2fca99098 100644 --- a/library/Icinga/Web/View/helpers/url.php +++ b/library/Icinga/Web/View/helpers/url.php @@ -94,10 +94,10 @@ $this->addHelperFunction('attributeToString', function ($key, $value) { // TODO: Doublecheck this! if (! preg_match('~^[a-zA-Z0-9-]+$~', $key)) { - throw new ProgrammingError(sprintf( + throw new ProgrammingError( 'Trying to set an invalid HTML attribute name: %s', $key - )); + ); } return sprintf( diff --git a/library/Icinga/Web/Widget.php b/library/Icinga/Web/Widget.php index 4bb177341..b181a49ea 100644 --- a/library/Icinga/Web/Widget.php +++ b/library/Icinga/Web/Widget.php @@ -38,10 +38,8 @@ class Widget if (! class_exists($class)) { throw new ProgrammingError( - sprintf( - 'There is no such widget: %s', - $name - ) + 'There is no such widget: %s', + $name ); } diff --git a/library/Icinga/Web/Widget/AbstractWidget.php b/library/Icinga/Web/Widget/AbstractWidget.php index 37fb7ad36..fe4d2434d 100644 --- a/library/Icinga/Web/Widget/AbstractWidget.php +++ b/library/Icinga/Web/Widget/AbstractWidget.php @@ -52,11 +52,9 @@ abstract class AbstractWidget } throw new ProgrammingError( - sprintf( - 'Trying to get invalid "%s" property for %s', - $key, - get_class($this) - ) + 'Trying to get invalid "%s" property for %s', + $key, + get_class($this) ); } @@ -78,14 +76,12 @@ abstract class AbstractWidget } throw new ProgrammingError( - sprintf( - 'Trying to set invalid "%s" property in %s. Allowed are: %s', - $key, - get_class($this), - empty($this->properties) + 'Trying to set invalid "%s" property in %s. Allowed are: %s', + $key, + get_class($this), + empty($this->properties) ? 'none' : implode(', ', array_keys($this->properties)) - ) ); } diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index f565c0fca..d8b09b15a 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -274,7 +274,8 @@ class Dashboard extends AbstractWidget { if (! array_key_exists($name, $this->panes)) { throw new ProgrammingError( - sprintf('Trying to retrieve invalid dashboard pane "%s"', $name) + 'Trying to retrieve invalid dashboard pane "%s"', + $name ); } return $this->panes[$name]; diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php index 15cf56524..39ad1fda3 100644 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ b/library/Icinga/Web/Widget/Dashboard/Pane.php @@ -105,7 +105,10 @@ class Pane extends AbstractWidget if ($this->hasComponent($title)) { return $this->components[$title]; } - throw new ProgrammingError(sprintf('Trying to access invalid component: %s', $title)); + throw new ProgrammingError( + 'Trying to access invalid component: %s', + $title + ); } /** @@ -157,7 +160,7 @@ class Pane extends AbstractWidget } elseif (is_string($component) && $url !== null) { $this->components[$component] = new Component($component, $url, $this); } else { - throw new ConfigurationError('Invalid component added: ' . $component); + throw new ConfigurationError('Invalid component added: %s', $component); } return $this; } diff --git a/library/Icinga/Web/Widget/Tabs.php b/library/Icinga/Web/Widget/Tabs.php index cd480ba32..716d5a959 100644 --- a/library/Icinga/Web/Widget/Tabs.php +++ b/library/Icinga/Web/Widget/Tabs.php @@ -154,10 +154,8 @@ EOT; { if ($this->has($name)) { throw new ProgrammingError( - sprintf( - 'Cannot add a tab named "%s" twice"', - $name - ) + 'Cannot add a tab named "%s" twice"', + $name ); } return $this->set($name, $tab); diff --git a/modules/monitoring/application/controllers/CommandController.php b/modules/monitoring/application/controllers/CommandController.php index bb1abcc74..f3055371a 100644 --- a/modules/monitoring/application/controllers/CommandController.php +++ b/modules/monitoring/application/controllers/CommandController.php @@ -114,7 +114,7 @@ class Monitoring_CommandController extends Controller if ($targetConfig->get($instance)) { $this->target = new CommandPipe($targetConfig->get($instance)); } else { - throw new ConfigurationError('Instance is not configured: '. $instance); + throw new ConfigurationError('Instance is not configured: %s', $instance); } } else { if ($targetConfig && $targetInfo = $targetConfig->current()) { diff --git a/modules/monitoring/library/Monitoring/Backend.php b/modules/monitoring/library/Monitoring/Backend.php index 21f2b91db..e10c70d4e 100644 --- a/modules/monitoring/library/Monitoring/Backend.php +++ b/modules/monitoring/library/Monitoring/Backend.php @@ -87,12 +87,13 @@ class Backend implements Selectable, Queryable, ConnectionInterface $backendConfig = $defaultBackend; } else { if (!array_key_exists($backendName, $allBackends)) { - throw new ConfigurationError('No configuration for backend ' . $backendName); + throw new ConfigurationError('No configuration for backend %s', $backendName); } $backendConfig = $allBackends[$backendName]; if ((bool) $backendConfig->get('disabled', false)) { throw new ConfigurationError( - 'Configuration for backend ' . $backendName . ' available but backend is disabled' + 'Configuration for backend %s available but backend is disabled', + $backendName ); } } @@ -147,7 +148,10 @@ public function getResource() { $viewClass = '\\Icinga\\Module\\Monitoring\\DataView\\' . ucfirst($viewName); if (!class_exists($viewClass)) { - throw new ProgrammingError('DataView ' . ucfirst($viewName) . ' does not exist'); + throw new ProgrammingError( + 'DataView %s does not exist', + ucfirst($viewName) + ); } return $viewClass; } @@ -174,7 +178,9 @@ public function getResource() . 'Query'; if (!class_exists($queryClass)) { throw new ProgrammingError( - 'Query "' . ucfirst($queryName) . '" does not exist for backend ' . ucfirst($this->type) + 'Query "%s" does not exist for backend %s', + ucfirst($queryName), + ucfirst($this->type) ); } return $queryClass; diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index f0f927487..df7118fe0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -442,7 +442,11 @@ abstract class IdoQuery extends DbQuery } elseif ($this->isCustomVar($alias)) { $this->requireCustomvar($alias); } else { - throw new ProgrammingError(sprintf('%s : Got invalid column: %s', get_called_class(), $alias)); + throw new ProgrammingError( + '%s : Got invalid column: %s', + get_called_class(), + $alias + ); } return $this; } @@ -476,7 +480,8 @@ abstract class IdoQuery extends DbQuery { if ($this->hasJoinedVirtualTable($name)) { throw new ProgrammingError( - sprintf('IDO query virtual table conflict with "%s"', $name) + 'IDO query virtual table conflict with "%s"', + $name ); } return $this; @@ -499,10 +504,8 @@ abstract class IdoQuery extends DbQuery $this->$func(); } else { throw new ProgrammingError( - sprintf( - 'Cannot join "%s", no such table found', - $table - ) + 'Cannot join "%s", no such table found', + $table ); } $this->joinedVirtualTables[$table] = true; @@ -581,10 +584,8 @@ abstract class IdoQuery extends DbQuery // TODO: Improve this: if (! preg_match('~^_(host|service)_([a-zA-Z0-9_]+)$~', $customvar, $m)) { throw new ProgrammingError( - sprintf( - 'Got invalid custom var: "%s"', - $customvar - ) + 'Got invalid custom var: "%s"', + $customvar ); } return array($m[1], $m[2]); diff --git a/modules/monitoring/library/Monitoring/Timeline/TimeEntry.php b/modules/monitoring/library/Monitoring/Timeline/TimeEntry.php index 7a91bfc85..615999bdb 100644 --- a/modules/monitoring/library/Monitoring/Timeline/TimeEntry.php +++ b/modules/monitoring/library/Monitoring/Timeline/TimeEntry.php @@ -79,7 +79,9 @@ class TimeEntry $entry->{$methodName}($value); } else { throw new ProgrammingError( - 'Method "' . $methodName . '" does not exist on object of type "' . __CLASS__ . '"' + 'Method "%s" does not exist on object of type "%s"', + $methodName, + __CLASS__ ); } }