Skip to content

Commit

Permalink
Progressbar: review exception, all tests passed
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkael committed Oct 3, 2010
1 parent 0add67d commit f7786bf
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 8 deletions.
11 changes: 6 additions & 5 deletions library/Zend/ProgressBar/Adapter/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @namespace
*/
namespace Zend\ProgressBar\Adapter;
use Zend\ProgressBar\Adapter\Exception;

/**
* Zend_ProgressBar_Adapter_Console offers a text-based progressbar for console
Expand Down Expand Up @@ -188,7 +189,7 @@ public function setOutputStream($resource)
$stream = @fopen($resource, 'w');

if ($stream === false) {
throw new Exception('Unable to open stream');
throw new Exception\RuntimeException('Unable to open stream');
}

if ($this->_outputStream !== null) {
Expand Down Expand Up @@ -266,7 +267,7 @@ public function setElements(array $elements)
self::ELEMENT_TEXT);

if (count(array_diff($elements, $allowedElements)) > 0) {
throw new Exception('Invalid element found in $elements array');
throw new Exception\InvalidArgumentException('Invalid element found in $elements array');
}

$this->_elements = $elements;
Expand All @@ -286,7 +287,7 @@ public function setElements(array $elements)
public function setBarLeftChar($char)
{
if (empty($char)) {
throw new Exception('Character may not be empty');
throw new Exception\InvalidArgumentException('Character may not be empty');
}

$this->_barLeftChar = (string) $char;
Expand All @@ -304,7 +305,7 @@ public function setBarLeftChar($char)
public function setBarRightChar($char)
{
if (empty($char)) {
throw new Exception('Character may not be empty');
throw new Exception\InvalidArgumentException('Character may not be empty');
}

$this->_barRightChar = (string) $char;
Expand Down Expand Up @@ -364,7 +365,7 @@ public function setFinishAction($action)
self::FINISH_ACTION_NONE);

if (!in_array($action, $allowedActions)) {
throw new Exception('Invalid finish action specified');
throw new Exception\InvalidArgumentException('Invalid finish action specified');
}

$this->_finishAction = $action;
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/ProgressBar/Adapter/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\ProgressBar\Exception
interface Exception extends \Zend\ProgressBar\Exception
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_ProgressBar
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\ProgressBar\Adapter\Exception;
use Zend\ProgressBar\Adapter\Exception;

/**
* Exception for Zend_Progressbar component.
*
* @uses Zend\Exception
* @category Zend
* @package Zend_ProgressBar
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class InvalidArgumentException
extends \InvalidArgumentException
implements Exception
{
}
41 changes: 41 additions & 0 deletions library/Zend/ProgressBar/Adapter/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_ProgressBar
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\ProgressBar\Adapter\Exception;
use Zend\ProgressBar\Adapter\Exception;

/**
* Exception for Zend_Progressbar component.
*
* @uses Zend\Exception
* @category Zend
* @package Zend_ProgressBar
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class RuntimeException
extends \RuntimeException
implements Exception
{
}
2 changes: 1 addition & 1 deletion library/Zend/ProgressBar/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Exception
interface Exception
{
}
41 changes: 41 additions & 0 deletions library/Zend/ProgressBar/Exception/OutOfRangeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_ProgressBar
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\ProgressBar\Exception;
use Zend\ProgressBar\Exception;

/**
* Exception for Zend_Progressbar component.
*
* @uses Zend\Exception
* @category Zend
* @package Zend_ProgressBar
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class OutOfRangeException
extends \OutOfRangeException
implements Exception
{
}
3 changes: 2 additions & 1 deletion library/Zend/ProgressBar/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @namespace
*/
namespace Zend\ProgressBar;
use Zend\ProgressBar\Exception;

/**
* Zend_ProgressBar offers an interface for multiple enviroments.
Expand Down Expand Up @@ -96,7 +97,7 @@ public function __construct(Adapter\AbstractAdapter $adapter, $min = 0, $max = 1
{
// Check min/max values and set them
if ($min > $max) {
throw new Exception('$max must be greater than $min');
throw new Exception\OutOfRangeException('$max must be greater than $min');
}

$this->_min = (float) $min;
Expand Down

0 comments on commit f7786bf

Please sign in to comment.