Skip to content

Commit

Permalink
Use SPL or special-purpose exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Apr 9, 2014
1 parent 28a4a42 commit 7fb0372
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion kronolith/lib/Calendars/Default.php
Expand Up @@ -27,7 +27,7 @@ class Kronolith_Calendars_Default extends Kronolith_Calendars_Base
public function __construct($shares, $user, $params)
{
if (!isset($params['identity'])) {
throw new Kronolith_Exception('This calendars handler needs an "identity" parameter!');
throw new BadMethodCallException('This calendars handler needs an "identity" parameter!');
} else {
$this->_identity = $params['identity'];
unset($params['identity']);
Expand Down
10 changes: 5 additions & 5 deletions kronolith/lib/Driver.php
Expand Up @@ -383,7 +383,7 @@ protected function _updateEvent(Kronolith_Event $event)
*/
public function exists($uid, $calendar_id = null)
{
throw new Kronolith_Exception('Not supported');
throw new BadMethodCallException('Not supported');
}

/**
Expand Down Expand Up @@ -419,7 +419,7 @@ public function move($eventId, $newCalendar)
*/
protected function _move($eventId, $newCalendar)
{
throw new Kronolith_Exception('Not supported');
throw new BadMethodCallException('Not supported');
}

/**
Expand All @@ -429,7 +429,7 @@ protected function _move($eventId, $newCalendar)
*/
public function delete($calendar)
{
throw new Kronolith_Exception('Not supported');
throw new BadMethodCallException('Not supported');
}

/**
Expand Down Expand Up @@ -545,7 +545,7 @@ protected function _handleNotifications(Kronolith_Event $event, $action)
*/
public function filterEventsByCalendar($uids, $calendar)
{
throw new Kronolith_Exception('Not supported');
throw new BadMethodCallException('Not supported');
}

/**
Expand All @@ -557,7 +557,7 @@ public function filterEventsByCalendar($uids, $calendar)
*/
public function removeUserData($user)
{
throw new Kronolith_Exception('Deprecated.');
throw new BadMethodCallException('Deprecated.');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions kronolith/lib/Driver/Kolab.php
Expand Up @@ -188,8 +188,7 @@ public function exists($uid, $calendar_id = null)
{
// Log error if someone uses this function in an unsupported way
if ($calendar_id != $this->calendar) {
Horde::log(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar), 'ERR');
throw new Kronolith_Exception(sprintf("Kolab::exists called for calendar %s. Currently active is %s.", $calendar_id, $this->calendar));
throw new BadMethodCallException(sprintf('Kolab::exists called for calendar %s. Currently active is %s.', $calendar_id, $this->calendar));
}

$this->synchronize();
Expand Down
4 changes: 2 additions & 2 deletions kronolith/lib/Event.php
Expand Up @@ -535,7 +535,7 @@ public function getShare()
if ($GLOBALS['calendar_manager']->getEntry(Kronolith::ALL_CALENDARS, $this->calendar) !== false) {
return $GLOBALS['calendar_manager']->getEntry(Kronolith::ALL_CALENDARS, $this->calendar)->share();
}
throw new Kronolith_Exception('Share not found');
throw new LogicException('Share not found');
}

/**
Expand Down Expand Up @@ -568,7 +568,7 @@ public function hasPermission($permission, $user = null)
public function save()
{
if (!$this->initialized) {
throw new Kronolith_Exception('Event not yet initialized');
throw new LogicException('Event not yet initialized');
}

/* Check for acceptance/denial of this event's resources. */
Expand Down
2 changes: 1 addition & 1 deletion kronolith/lib/Factory/Driver.php
Expand Up @@ -103,7 +103,7 @@ public function create($driver, array $params = array())
break;

default:
throw new Kronolith_Exception('No calendar driver specified');
throw new InvalidArgumentException('No calendar driver specified');
break;
}

Expand Down
4 changes: 2 additions & 2 deletions kronolith/lib/Resource/Base.php
Expand Up @@ -51,7 +51,7 @@ public function __construct(array $params = array())

// Names are required.
if (empty($params['name'])) {
throw new Horde_Exception('Required \'name\' attribute missing from resource calendar');
throw new BadMethodCallException('Required \'name\' attribute missing from resource calendar');
}
$this->_params = array_merge(
array('description' => '',
Expand Down Expand Up @@ -120,7 +120,7 @@ public function get($property)
return ($this instanceof Kronolith_Resource_Single) ? 'Single' : 'Group';
}
if (!array_key_exists($property, $this->_params)) {
throw new Horde_Exception(sprintf('The property \'%s\' does not exist', $property));
throw new LogicException(sprintf('The property \'%s\' does not exist', $property));
}
return $this->_params[$property];
}
Expand Down
10 changes: 5 additions & 5 deletions kronolith/lib/Resource/Group.php
Expand Up @@ -158,7 +158,7 @@ public function addEvent(Kronolith_Event $event)
if (!empty($this->_selectedResource)) {
$this->_selectedResource->addEvent($event);
} else {
throw new Kronolith_Exception('Events should be added to the Single resource object, not directly to the Group object.');
throw new LogicException('Events should be added to the Single resource object, not directly to the Group object.');
}
}

Expand All @@ -171,7 +171,7 @@ public function addEvent(Kronolith_Event $event)
*/
public function removeEvent(Kronolith_Event $event)
{
throw new Kronolith_Exception('Unsupported');
throw new BadMethodCallException('Unsupported');
}

/**
Expand All @@ -181,7 +181,7 @@ public function removeEvent(Kronolith_Event $event)
*/
public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false, $json = false)
{
throw new Kronolith_Exception('Unsupported');
throw new BadMethodCallException('Unsupported');
}

/**
Expand All @@ -196,7 +196,7 @@ public function setId($id)
if (empty($this->_id)) {
$this->_id = $id;
} else {
throw new Kronolith_Exception('Resource already exists. Cannot change the id.');
throw new LogicException('Resource already exists. Cannot change the id.');
}
}

Expand All @@ -210,4 +210,4 @@ public function getResponseType()
return Kronolith_Resource::RESPONSETYPE_AUTO;
}

}
}
2 changes: 1 addition & 1 deletion kronolith/lib/Resource/Single.php
Expand Up @@ -129,7 +129,7 @@ public function setId($id)
if (empty($this->_id)) {
$this->_id = $id;
} else {
throw new Kronolith_Exception('Resource already exists. Cannot change the id.');
throw new LogicException('Resource already exists. Cannot change the id.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion kronolith/lib/View/DeleteEvent.php
Expand Up @@ -28,7 +28,7 @@ public function __get($property)
case 'event':
return $this->_event;
default:
throw new Kronolith_Exception('Property does not exist.');
throw new LogicException('Property does not exist.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion kronolith/lib/View/EditEvent.php
Expand Up @@ -29,7 +29,7 @@ public function __get($property)
case 'event':
return $this->_event;
default:
throw new Kronolith_Exception('Property does not exist.');
throw new LogicException('Property does not exist.');
}
}

Expand Down
2 changes: 1 addition & 1 deletion kronolith/lib/View/Event.php
Expand Up @@ -28,7 +28,7 @@ public function __get($property)
case 'event':
return $this->_event;
default:
throw new Kronolith_Exception('Property does not exist.');
throw new LogicException('Property does not exist.');
}
}

Expand Down
6 changes: 3 additions & 3 deletions kronolith/perms.php
Expand Up @@ -18,7 +18,7 @@

// Exit if the user shouldn't be able to change share permissions.
if (!empty($conf['share']['no_sharing'])) {
throw new Horde_Exception('Permission denied.');
throw new Horde_Exception_PermissionDenied();
}

$shares = $injector->getInstance('Horde_Core_Factory_Share')->create();
Expand Down Expand Up @@ -51,7 +51,7 @@
(isset($share) &&
!$registry->isAdmin() &&
($registry->getAuth() != $share->get('owner')))) {
throw new Horde_Exception('Permission denied.');
throw new Horde_Exception_PermissionDenied();
}
break;

Expand All @@ -71,7 +71,7 @@
if (!$registry->getAuth() ||
(!$registry->isAdmin() &&
($registry->getAuth() != $share->get('owner')))) {
throw new Horde_Exception('Permission denied.');
throw new Horde_Exception_PermissionDenied();
}

try {
Expand Down

0 comments on commit 7fb0372

Please sign in to comment.