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

Commit

Permalink
Replace ReflectionClass::getName by name property call
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jul 10, 2018
1 parent c3ccc55 commit c64cc83
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function responseStatusCodeShouldBe405()
/**
* @Then /^the (?P<name>[\w\_]+) has been successfully deleted$/
*/
public function itemShouldHaveBeSuccessfullyDeleted(string $name)
public function itemShouldHaveBeSuccessfullyDeleted()
{
$this->minkContext->assertResponseStatus(204);
// todo Ensure object has been deleted from database
Expand Down Expand Up @@ -385,9 +385,9 @@ public function printJsonData()
private function findObject(string $name, $value)
{
$reflectionClass = $this->helper->getReflectionClass($name);
$object = $this->transformer->toObject(['targetEntity' => $reflectionClass->getName(), 'type' => ClassMetadataInfo::ONE_TO_ONE], $value);
$object = $this->transformer->toObject(['targetEntity' => $reflectionClass->name, 'type' => ClassMetadataInfo::ONE_TO_ONE], $value);
if (null === $object) {
throw new EntityNotFoundException(sprintf('Unable to find an existing object of class %s with any value equal to %s.', $reflectionClass->getName(), $value));
throw new EntityNotFoundException(sprintf('Unable to find an existing object of class %s with any value equal to %s.', $reflectionClass->name, $value));
}

return $object;
Expand Down
6 changes: 3 additions & 3 deletions src/Context/FixturesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function __construct(Populator $populator, ManagerRegistry $registry, Api
public function theFollowing($name, TableNode $table)
{
$reflectionClass = $this->helper->getReflectionClass($name);
$em = $this->registry->getManagerForClass($reflectionClass->getName());
$em = $this->registry->getManagerForClass($reflectionClass->name);
$rows = $table->getRows();
$headers = array_shift($rows);
/** @var ClassMetadataInfo $classMetadata */
$classMetadata = $this->registry->getManagerForClass($reflectionClass->getName())->getClassMetadata($reflectionClass->getName());
$classMetadata = $this->registry->getManagerForClass($reflectionClass->name)->getClassMetadata($reflectionClass->name);
if (array_intersect($headers, $classMetadata->getIdentifierFieldNames())) {
$idGenerator = $classMetadata->idGenerator;
$classMetadata->setIdGenerator(new AssignedGenerator());
Expand All @@ -71,7 +71,7 @@ public function theFollowing($name, TableNode $table)
public function thereIs(string $name, int $number)
{
$reflectionClass = $this->helper->getReflectionClass($name);
$em = $this->registry->getManagerForClass($reflectionClass->getName());
$em = $this->registry->getManagerForClass($reflectionClass->name);
for ($i = 0; $i < $number; ++$i) {
$em->persist($this->populator->getObject($reflectionClass));
}
Expand Down
10 changes: 5 additions & 5 deletions src/Helper/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function setRouter(RouterInterface $router)

public function getUri(\ReflectionClass $reflectionClass): string
{
return $this->iriConverter->getIriFromResourceClass($reflectionClass->getName());
return $this->iriConverter->getIriFromResourceClass($reflectionClass->name);
}

public function getUrl(string $url, array $parameters = [])
Expand All @@ -76,15 +76,15 @@ public function getUrl(string $url, array $parameters = [])
public function getItemUri(\ReflectionClass $reflectionClass, array $ids = null): string
{
/** @var EntityManagerInterface $em */
$em = $this->registry->getManagerForClass($reflectionClass->getName());
$em = $this->registry->getManagerForClass($reflectionClass->name);
if (null === $ids) {
if (null === ($object = $em->getRepository($reflectionClass->getName())->findOneBy([]))) {
throw new EntityNotFoundException('Unable to find an existing object of class '.$reflectionClass->getName());
if (null === ($object = $em->getRepository($reflectionClass->name)->findOneBy([]))) {
throw new EntityNotFoundException('Unable to find an existing object of class '.$reflectionClass->name);
}
$ids = $this->getObjectIdentifiers($object);
}

return $this->iriConverter->getItemIriFromResourceClass($reflectionClass->getName(), $ids);
return $this->iriConverter->getItemIriFromResourceClass($reflectionClass->name, $ids);
}

public function getItemUriPattern(\ReflectionClass $reflectionClass): string
Expand Down
8 changes: 4 additions & 4 deletions src/Populator/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function setRegistry(ManagerRegistry $registry)

public function getObject(\ReflectionClass $reflectionClass, array $values = [])
{
$className = $reflectionClass->getName();
$className = $reflectionClass->name;

// Complete required properties
/** @var ClassMetadataInfo $classMetadata */
Expand Down Expand Up @@ -119,7 +119,7 @@ public function getObject(\ReflectionClass $reflectionClass, array $values = [])

public function getRequestData(\ReflectionClass $reflectionClass, string $operation, array $values = []): array
{
$className = $reflectionClass->getName();
$className = $reflectionClass->name;

// Get serialization groups
$resourceMetadata = $this->metadataFactory->create($className);
Expand Down Expand Up @@ -220,7 +220,7 @@ public function getMapping(ClassMetadataInfo $classMetadata, string $property):
private function isRequired(\ReflectionProperty $reflectionProperty, $groups): bool
{
/** @var ClassMetadataInfo $classMetadata */
$className = $reflectionProperty->getDeclaringClass()->getName();
$className = $reflectionProperty->getDeclaringClass()->name;
$classMetadata = $this->registry->getManagerForClass($className)->getClassMetadata($className);

foreach ([NotBlank::class, NotNull::class, Count::class] as $class) {
Expand All @@ -230,7 +230,7 @@ private function isRequired(\ReflectionProperty $reflectionProperty, $groups): b
}
}

return !($this->getMapping($classMetadata, $reflectionProperty->getName())['nullable'] ?? false);
return !($this->getMapping($classMetadata, $reflectionProperty->name)['nullable'] ?? false);
}

private function filterOperations(array $operations, string $operation): array
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/CollectionSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function supports(\ReflectionClass $reflectionClass, array $context = [])

public function generate(\ReflectionClass $reflectionClass, array $context = []): array
{
$resourceMetadata = $this->metadataFactory->create($reflectionClass->getName());
$resourceMetadata = $this->metadataFactory->create($reflectionClass->name);
$normalizationContext = $resourceMetadata->getCollectionOperationAttribute('get', 'normalization_context', [], true);

$schema = [
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/ErrorSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setRouter(RouterInterface $router)

public function supports(\ReflectionClass $reflectionClass, array $context = []): bool
{
return is_a($reflectionClass->getName(), ConstraintViolationListInterface::class, true);
return is_a($reflectionClass->name, ConstraintViolationListInterface::class, true);
}

public function generate(\ReflectionClass $reflectionClass, array $context = []): array
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/ObjectSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function generate(\ReflectionClass $reflectionClass, array $context = [])
throw new MaxDepthException(sprintf('Maximum depth of %d has been reached. This could be caused by a circular reference due to serialization groups.%sPath: %s', self::MAX_DEPTH, PHP_EOL, implode('->', $this->path)));
}
++$context['depth'];
$className = $reflectionClass->getName();
$className = $reflectionClass->name;
$schema = [
'type' => 'object',
'properties' => [],
Expand Down Expand Up @@ -137,7 +137,7 @@ public function generate(\ReflectionClass $reflectionClass, array $context = [])
if (!empty($mapping['targetEntity'])) {
$this->path[$context['depth']] = $property;
}
if (($mapping['targetEntity'] ?? null) === $reflectionClass->getName()) {
if (($mapping['targetEntity'] ?? null) === $reflectionClass->name) {
// todo Is there a better way to handle this case?
$schema['properties'][$property] = $this->typeGenerator->generate($property, $mapping, ['serializer_groups' => []] + $context);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/SchemaGeneratorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public function generate(\ReflectionClass $reflectionClass, array $context = [])
}
}

throw new SchemaGeneratorNotFoundException('No schema generator found for class '.$reflectionClass->getName());
throw new SchemaGeneratorNotFoundException('No schema generator found for class '.$reflectionClass->name);
}
}

0 comments on commit c64cc83

Please sign in to comment.