| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 1 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 55 | public function getSubcollection(string $resourceClass, array $identifiers, array $context = []) |
||
| 56 | { |
||
| 57 | // $manager = $this->managerRegistry->getManagerForClass($resourceClass); |
||
| 58 | // if (null === $manager) { |
||
| 59 | // throw new ResourceClassNotSupportedException(); |
||
| 60 | // } |
||
| 61 | // |
||
| 62 | // $identifiers = $this->normalizeIdentifiers($id, $manager, $resourceClass); |
||
| 63 | // |
||
| 64 | // $fetchData = $context['fetch_data'] ?? true; |
||
| 65 | // if (!$fetchData && $manager instanceof EntityManagerInterface) { |
||
| 66 | // return $manager->getReference($resourceClass, $identifiers); |
||
| 67 | // } |
||
| 68 | // |
||
| 69 | // $classMetadata = $manager->getClassMetadata($resourceClass); |
||
| 70 | // $subResourceClass = $classMetadata->getAssociationTargetClass($subcollectionProperty); |
||
| 71 | // $subResourceClassMetadata = $manager->getClassMetadata($subResourceClass); |
||
| 72 | // |
||
| 73 | // $repository = $manager->getRepository($subResourceClass); |
||
| 74 | // if (!method_exists($repository, 'createQueryBuilder')) { |
||
| 75 | // throw new RuntimeException('The repository class must have a "createQueryBuilder" method.'); |
||
| 76 | // } |
||
| 77 | // |
||
| 78 | // $queryBuilder = $repository->createQueryBuilder('o'); |
||
| 79 | // |
||
| 80 | // $where = null; |
||
| 81 | // foreach ($identifiers as $identifier => $value) { |
||
| 82 | // $placeholder = ':id_'.$identifier; |
||
| 83 | // $expression = "parentResourceClass.$identifier = $placeholder"; |
||
| 84 | // |
||
| 85 | // $where = $where ? "$where AND $expression" : $expression; |
||
| 86 | // $queryBuilder->setParameter($placeholder, $value); |
||
| 87 | // } |
||
| 88 | // |
||
| 89 | // //@TODO support composite identifiers relation |
||
| 90 | // $queryBuilder->andWhere(sprintf( |
||
| 91 | // 'o.%s IN (SELECT child.%1$s FROM %s parentResourceClass JOIN parentResourceClass.%s child WHERE %s)', |
||
| 92 | // $subResourceClassMetadata->getSingleIdentifierFieldName(), $resourceClass, $subcollectionProperty, $where |
||
| 93 | // )); |
||
| 94 | // |
||
| 95 | // $queryNameGenerator = new QueryNameGenerator(); |
||
| 96 | // |
||
| 97 | // foreach ($this->collectionExtensions as $extension) { |
||
| 98 | // $extension->applyToCollection($queryBuilder, $queryNameGenerator, $resourceClass, $operationName); |
||
| 99 | // |
||
| 100 | // if ($extension instanceof QueryResultCollectionExtensionInterface && $extension->supportsResult($resourceClass, $operationName)) { |
||
| 101 | // return $extension->getResult($queryBuilder); |
||
| 102 | // } |
||
| 103 | // } |
||
| 104 | // |
||
| 105 | // return $queryBuilder->getQuery()->getResult(); |
||
| 106 | } |
||
| 107 | } |
||
| 108 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.