| Conditions | 10 |
| Paths | 34 |
| Total Lines | 64 |
| Code Lines | 38 |
| 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 |
||
| 35 | public function createView(AgentInterface $agent, GridContext $gridContext, GridMetadata $gridMetadata): GridView |
||
| 36 | { |
||
| 37 | // create the filter form based on the metadata and submit any data. |
||
| 38 | $filterForm = $this->filterFactory->createForm($gridMetadata, $agent->getCapabilities()); |
||
| 39 | |||
| 40 | if ($gridContext->getFilter()) { |
||
| 41 | $filterForm->submit($gridContext->getFilter()); |
||
| 42 | |||
| 43 | if (false === $filterForm->isValid()) { |
||
| 44 | foreach ($filterForm->getErrors(true) as $name => $error) { |
||
| 45 | $message[] = sprintf( |
||
| 46 | '%s %s', |
||
| 47 | $error->getOrigin()->getPropertyPath(), |
||
| 48 | $error->getMessage() |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | throw new \InvalidArgumentException(sprintf( |
||
| 53 | 'Invalid filter form: ' . implode(', ', $message) |
||
| 54 | )); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | $criteria = $this->filterFactory->createExpression($gridMetadata, $filterForm->getData()); |
||
| 59 | |||
| 60 | if ($criteria instanceof Composite && empty($criteria->getExpressions())) { |
||
| 61 | $criteria = null; |
||
| 62 | } |
||
| 63 | |||
| 64 | $criteria = [ |
||
| 65 | 'criteria' => $criteria, |
||
| 66 | 'orderings' => $this->resolveOrderings($gridContext->getOrderings(), $gridMetadata), |
||
| 67 | 'firstResult' => $gridContext->getPageOffset(), |
||
| 68 | 'maxResults' => $gridContext->isPaginated() ? $gridContext->getPageSize() : null, |
||
| 69 | ]; |
||
| 70 | |||
| 71 | if ($gridMetadata->hasQuery()) { |
||
| 72 | $query = $this->queryFactory->createQuery($agent->getCanonicalClassFqn($gridContext->getClassFqn()), $gridMetadata->getQuery()); |
||
| 73 | $criteria['selects'] = $query->getSelects(); |
||
| 74 | $criteria['joins'] = $query->getJoins(); |
||
| 75 | |||
| 76 | if ($query->hasExpression()) { |
||
| 77 | if (null === $criteria['criteria']) { |
||
| 78 | $criteria['criteria'] = $query->getExpression(); |
||
| 79 | } else { |
||
| 80 | // filter and user criterias need to be combined |
||
| 81 | $criteria['criteria'] = new Composite(Composite::AND, [$query->getExpression(), $criteria['criteria']]); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | // create the query and get the data collection from the object-agent. |
||
| 87 | $query = Query::create($gridContext->getClassFqn(), $criteria); |
||
| 88 | $collection = new \IteratorIterator($agent->query($query)); |
||
| 89 | |||
| 90 | return new View\Grid( |
||
| 91 | $gridContext->getClassFqn(), |
||
| 92 | $gridMetadata->getName(), |
||
| 93 | new View\Table($this->columnFactory, $gridMetadata, $gridContext, $collection, $gridContext), |
||
| 94 | new View\Paginator($gridContext, count($collection), $this->getNumberOfRecords($agent, $query)), |
||
| 95 | new View\FilterBar($filterForm->createView(), $gridContext), |
||
| 96 | new View\ActionBar($gridMetadata) |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | |||
| 134 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..