Skip to content

Commit

Permalink
Add RegistryException
Browse files Browse the repository at this point in the history
  • Loading branch information
ignaszak committed Mar 23, 2016
1 parent 101a60a commit 3b6cc07
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function get(string $name)
/**
* @param string $name
* @return object
* @throws Exception
* @throws RegistryException
*/
public function register(string $name)
{
Expand All @@ -84,43 +84,43 @@ public function remove(string $name): bool
/**
* @param string $name
* @return boolean
* @throws Exception
* @throws RegistryException
*/
public function reload(string $name): bool
{
if ($this->_registry->isAdded($name)) {
$className = get_class($this->get($name));
return $this->set($name, new $className);
} else {
throw new \RuntimeException("Class '$name' not registered");
throw new RegistryException("Class '$name' not registered");
}
}

/**
* @param object $value
* @return boolean
* @throws Exception
* @throws RegistryException
*/
private function isObject($value): bool
{
if (is_object($value)) {
return true;
} else {
throw new \RuntimeException('Object not exists');
throw new RegistryException('Object not exists');
}
}

/**
* @param string $name
* @return boolean
* @throws Exception
* @throws RegistryException
*/
private function classExists(string $name): bool
{
if (class_exists($name)) {
return true;
} else {
throw new \RuntimeException("Class '$name' not exists");
throw new RegistryException("Class '$name' not exists");
}
}
}
21 changes: 21 additions & 0 deletions src/RegistryException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* phpDocumentor
*
* PHP Version 7.0
*
* @copyright 2015 Tomasz Ignaszak
* @license http://www.opensource.org/licenses/mit-license.php MIT
*/
declare(strict_types=1);

namespace Ignaszak\Registry;

class RegistryException extends \Exception
{

public function __construct(string $message, int $code = 0)
{
parent::__construct($message, $code);
}
}
4 changes: 2 additions & 2 deletions src/RegistryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function start(string $registry = 'request'): Registry
/**
*
* @param string $registry
* @throws \InvalidArgumentException
* @throws RegistryException
* @return \Ignaszak\Registry\Scope\IRegistry
*/
private static function getRegistryInstance(string $registry): IRegistry
Expand All @@ -62,7 +62,7 @@ private static function getRegistryInstance(string $registry): IRegistry
case 'file':
return new Scope\FileRegistry();
default:
throw new \InvalidArgumentException('Incorrect argument');
throw new RegistryException('Incorrect argument');
}
}
}
2 changes: 1 addition & 1 deletion tests/RegistryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testGetFileInstance()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testStartException()
{
Expand Down
8 changes: 4 additions & 4 deletions tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testRegisterNew()
}

/**
* @expectedException \RuntimeException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testRegisterException()
{
Expand All @@ -105,7 +105,7 @@ public function testRemove()
}

/**
* @expectedException \RuntimeException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testReloadNonAddedClass()
{
Expand Down Expand Up @@ -140,7 +140,7 @@ public function testIsObject()
}

/**
* @expectedException \RuntimeException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testIsObjectException()
{
Expand All @@ -154,7 +154,7 @@ public function testClassExists()
}

/**
* @expectedException \RuntimeException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testClassExistsException()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Scope/FileRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSetAgain()
}

/**
* @expectedException \RuntimeException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testCantCreateTmpFolder()
{
Expand All @@ -45,7 +45,7 @@ public function testCantCreateTmpFolder()
}

/**
* @expectedException \RuntimeException
* @expectedException \Ignaszak\Registry\RegistryException
*/
public function testCantSave()
{
Expand Down

0 comments on commit 3b6cc07

Please sign in to comment.