Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Commit

Permalink
Fix code style and better exception messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonwalz committed Feb 10, 2015
1 parent fe810de commit 88fe97e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/Midgard/CreatePHP/Mapper/BaseDoctrineRdfMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ public function supportsCreate(TypeInterface $type)
if (isset($this->typeMap[$name])) {
try {
$metadata = $this->om->getClassMetadata($this->typeMap[$name]);

return is_object($metadata);
} catch (MappingException $e) { }
} catch (MappingException $e) {
}
}

return false;
}
}
}
28 changes: 11 additions & 17 deletions src/Midgard/CreatePHP/Mapper/ChainRdfMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace Midgard\CreatePHP\Mapper;


use Midgard\CreatePHP\RdfChainableMapperInterface;
use Midgard\CreatePHP\RdfMapperInterface;
use Midgard\CreatePHP\Entity\PropertyInterface;
use Midgard\CreatePHP\Entity\CollectionInterface;
use Midgard\CreatePHP\Type\TypeInterface;
use Midgard\CreatePHP\Entity\EntityInterface;

use \RuntimeException;
use RuntimeException;

/**
* Looks at all registered mappers to find one that can handle objects.
Expand All @@ -37,7 +35,7 @@ class ChainRdfMapper implements RdfMapperInterface
* Register a mapper with a key. The key will be prefixed to all subjects.
*
* @param RdfChainableMapperInterface $mapper
* @param string $mapperKey
* @param string $mapperKey
*/
public function registerMapper(RdfChainableMapperInterface $mapper, $mapperKey)
{
Expand All @@ -47,14 +45,13 @@ public function registerMapper(RdfChainableMapperInterface $mapper, $mapperKey)
/**
* Get the mapper than can handle object.
*
* @param mixed $object
* @param mixed $object
* @return RdfChainableMapperInterface
* @throws RuntimeException when no mapper can handle the object
* @throws RuntimeException when no mapper can handle the object
*/
protected function getMapperForObject($object)
{
foreach ($this->mappers as $mapper)
{
foreach ($this->mappers as $mapper) {
if ($mapper->supports($object)) {
return $mapper;
}
Expand Down Expand Up @@ -120,8 +117,7 @@ public function objectToName($object)
*/
public function prepareObject(TypeInterface $controller, $parent = null)
{
foreach ($this->mappers as $mapper)
{
foreach ($this->mappers as $mapper) {
if ($mapper->supportsCreate($controller)) {
$object = $mapper->prepareObject($controller, $parent);
$this->createdObjects[spl_object_hash($object)] = $mapper;
Expand All @@ -130,7 +126,7 @@ public function prepareObject(TypeInterface $controller, $parent = null)
}
}

throw new RuntimeException("No mapper can create an object for type.");
throw new RuntimeException(sprintf('None of the registered mappers can create an object of type %s', $controller->getRdfType()));
}

/**
Expand All @@ -148,8 +144,7 @@ public function getBySubject($subject)
{
list($mapperKey, $mapperSubject) = explode('|', $subject, 2);

if (!isset($this->mappers[$mapperKey]))
{
if (!isset($this->mappers[$mapperKey])) {
throw new RuntimeException("Invalid subject: $subject");
}

Expand All @@ -163,14 +158,13 @@ public function getBySubject($subject)
*/
public function createSubject($object)
{
foreach ($this->mappers as $mapperKey => $mapper)
{
foreach ($this->mappers as $mapperKey => $mapper) {
if ($mapper->supports($object)) {
return $mapperKey . '|' . $mapper->createSubject($object);
return $mapperKey.'|'.$mapper->createSubject($object);
}
}

throw new RuntimeException("No mapper can create a subject for object.");
throw new RuntimeException(sprintf('None of the registered mappers can create the subject for object of class %s', get_class($object)));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Midgard/CreatePHP/Mapper/DoctrineOrmMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function createSubject($object)

$idstring = implode('|', $key);

return str_replace('\\', '-', $this->objectToName($object)) . "|$idstring";
return str_replace('\\', '-', $this->objectToName($object))."|$idstring";
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Midgard/CreatePHP/RdfChainableMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @license Dual licensed under the MIT (MIT-LICENSE.txt) and LGPL (LGPL-LICENSE.txt) licenses.
* @package Midgard.CreatePHP
*/

namespace Midgard\CreatePHP;

use Midgard\CreatePHP\Type\TypeInterface;
Expand Down

0 comments on commit 88fe97e

Please sign in to comment.