Code should not be duplicated

  • Minor
  • Architecture

More information: https://insight.symfony.com/what-we-analyse/php.duplicated_code

  1. $successResponse['schema'] = ['$ref' => sprintf('#/definitions/%s', $responseDefinitionKey)];
  2. }
  3. }
  4. $pathOperation['responses'] ?? $pathOperation['responses'] = [
  5. (string) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'status', '201') => $successResponse,

    The next 15 lines appear both in src/Swagger/Serializer/DocumentationNormalizer.php:454 and src/Swagger/Serializer/DocumentationNormalizer.php:515.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Kévin Dunglas
  6. '400' => ['description' => 'Invalid input'],
  7. '404' => ['description' => 'Resource not found'],
  8. ];
  9. $inputMetadata = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'input', ['class' => $resourceClass], true);

Source code should not contain TODO comments

  • Minor
  • Architecture

More information: https://insight.symfony.com/what-we-analyse/task_todo_comment

  1. /**
  2. * @throws ResourceClassNotFoundException
  3. */
  4. private function addSubresourceOperation(bool $v3, array $subresourceOperation, \ArrayObject $definitions, string $operationId, array $mimeTypes, string $resourceClass, ResourceMetadata $resourceMetadata): \ArrayObject
  5. {
  6. $operationName = 'get'; // TODO: we might want to extract that at some point to also support other subresource operations

    TODO comments are left in the code when a feature (or a bug) isn't completely developed (or fixed). You should complete the implementation and remove the comment.

    Time to fix: about 4 hours
    Open Issue Permalink
    Last edited by Ron Rademaker
  7. $subResourceMetadata = $this->resourceMetadataFactory->create($subresourceOperation['resource_class']);
  8. $serializerContext = $this->getSerializerContext(OperationType::SUBRESOURCE, false, $subResourceMetadata, $operationName);
  9. $responseDefinitionKey = $this->getDefinition($v3, $definitions, $subResourceMetadata, $subresourceOperation['resource_class'], null, $serializerContext);
  10. $pathOperation = new \ArrayObject([]);

Unused method, property, variable or parameter 7

  • Minor
  • Deadcode

More information: https://insight.symfony.com/what-we-analyse/php.unused_local_variable_or_private_member

  1. /**
  2. * @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
  3. *
  4. * @var bool
  5. */
  6. private $elasticsearch;

    This elasticsearch attribute is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by soyuka
  7. /**
  8. * @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112
  9. *
  10. * @var bool
  1. *
  2. * @throws UnexpectedValueException
  3. */
  4. public function normalize($object, $format = null, array $context = [])
  5. {
  6. if (null !== $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {

    This outputClass local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Teoh Han Hui
  7. return parent::normalize($object, $format, $context);
  8. }
  9. $data = parent::normalize($object, $format, $context);
  10. if (!\is_array($data)) {
  1. $queryFields += $this->getQueryFields($resourceClass, $resourceMetadata, $operationName, [], []);
  2. continue;
  3. }
  4. if ($itemQuery = $resourceMetadata->getGraphqlAttribute($operationName, 'item_query')) {

    This itemQuery local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Lukas Lücke
  5. $queryFields += $this->getQueryFields($resourceClass, $resourceMetadata, $operationName, $value, false);
  6. continue;
  7. }
  1. $queryFields += $this->getQueryFields($resourceClass, $resourceMetadata, $operationName, $value, false);
  2. continue;
  3. }
  4. if ($collectionQuery = $resourceMetadata->getGraphqlAttribute($operationName, 'collection_query')) {

    This collectionQuery local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Lukas Lücke
  5. $queryFields += $this->getQueryFields($resourceClass, $resourceMetadata, $operationName, false, $value);
  6. continue;
  7. }
  1. /**
  2. * {@inheritdoc}
  3. */
  4. public function normalize($object, $format = null, array $context = [])
  5. {
  6. if (null !== $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {

    This outputClass local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Teoh Han Hui
  7. return parent::normalize($object, $format, $context);
  8. }
  9. if (!isset($context['cache_key'])) {
  10. $context['cache_key'] = $this->getHalCacheKey($format, $context);
  1. /**
  2. * {@inheritdoc}
  3. */
  4. public function normalize($object, $format = null, array $context = [])
  5. {
  6. if (null !== $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {

    This outputClass local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Teoh Han Hui
  7. return parent::normalize($object, $format, $context);
  8. }
  9. if (!isset($context['cache_key'])) {
  10. $context['cache_key'] = $this->getJsonApiCacheKey($format, $context);
  1. *
  2. * @throws LogicException
  3. */
  4. public function normalize($object, $format = null, array $context = [])
  5. {
  6. if (null !== $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {

    This outputClass local variable is declared but never used. You should remove it.

    Time to fix: about 15 minutes
    Open Issue Permalink
    Last edited by Teoh Han Hui
  7. return parent::normalize($object, $format, $context);
  8. }
  9. // Use resolved resource class instead of given resource class to support multiple inheritance child types
  10. $resourceClass = $this->resourceClassResolver->getResourceClass($object, $context['resource_class'] ?? null, true);