Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minor #13796 [Serializer] Replace BadMethodCallException by MappingEx…
…ception (dunglas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Serializer] Replace BadMethodCallException by MappingException

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no (`AnnotationLoader` will be introduced in 2.7)
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

469b8e7 [Serializer] Replace BadMethodCallException by UnexpectedValueException
  • Loading branch information
dunglas committed Mar 6, 2015
2 parents b001a79 + 469b8e7 commit 37e0fa1
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Annotations\Reader;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Exception\MappingException;
use Symfony\Component\Serializer\Mapping\ClassMetadata;

/**
Expand Down Expand Up @@ -45,7 +46,7 @@ public function loadClassMetadata(ClassMetadata $metadata)
$loaded = false;

foreach ($reflClass->getProperties() as $property) {
if ($property->getDeclaringClass()->name == $className) {
if ($property->getDeclaringClass()->name === $className) {
foreach ($this->reader->getPropertyAnnotations($property) as $groups) {
if ($groups instanceof Groups) {
foreach ($groups->getGroups() as $group) {
Expand All @@ -59,15 +60,15 @@ public function loadClassMetadata(ClassMetadata $metadata)
}

foreach ($reflClass->getMethods() as $method) {
if ($method->getDeclaringClass()->name == $className) {
if ($method->getDeclaringClass()->name === $className) {
foreach ($this->reader->getMethodAnnotations($method) as $groups) {
if ($groups instanceof Groups) {
if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) {
foreach ($groups->getGroups() as $group) {
$metadata->addAttributeGroup(lcfirst($matches[2]), $group);
}
} else {
throw new \BadMethodCallException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name));
throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name));
}
}

Expand Down

0 comments on commit 37e0fa1

Please sign in to comment.