Conditions | 9 |
Paths | 32 |
Total Lines | 64 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
62 | public function buildPagination( |
||
63 | Entity $entity, |
||
64 | QueryBuilder $queryBuilder, |
||
65 | string|null $eventName, |
||
66 | mixed ...$resolve, |
||
67 | ): array { |
||
68 | $paginationFields = [ |
||
69 | 'first' => 0, |
||
70 | 'last' => 0, |
||
71 | 'before' => 0, |
||
72 | 'after' => 0, |
||
73 | ]; |
||
74 | |||
75 | if (isset($resolve['args']['pagination'])) { |
||
76 | foreach ($resolve['args']['pagination'] as $field => $value) { |
||
77 | $paginationFields[$field] = $value; |
||
78 | |||
79 | if ($field === 'after') { |
||
80 | $paginationFields[$field] = (int) base64_decode($value, true) + 1; |
||
81 | } |
||
82 | |||
83 | if ($field !== 'before') { |
||
84 | continue; |
||
85 | } |
||
86 | |||
87 | $paginationFields[$field] = (int) base64_decode($value, true); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $offsetAndLimit = $this->calculateOffsetAndLimit($entity, $paginationFields); |
||
92 | |||
93 | if ($offsetAndLimit['offset']) { |
||
94 | $queryBuilder->setFirstResult($offsetAndLimit['offset']); |
||
95 | } |
||
96 | |||
97 | if ($offsetAndLimit['limit']) { |
||
98 | $queryBuilder->setMaxResults($offsetAndLimit['limit']); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Fire the event dispatcher using the passed event name. |
||
103 | * Include all resolve variables. |
||
104 | */ |
||
105 | if ($eventName) { |
||
106 | $this->eventDispatcher->dispatch( |
||
107 | new QueryBuilderEvent( |
||
108 | $queryBuilder, |
||
109 | $eventName, |
||
110 | ...$resolve, |
||
111 | ), |
||
112 | ); |
||
113 | } |
||
114 | |||
115 | $edgesAndCursors = $this->buildEdgesAndCursors($queryBuilder, $offsetAndLimit, $paginationFields); |
||
116 | |||
117 | return [ |
||
118 | 'edges' => $edgesAndCursors['edges'], |
||
119 | 'totalCount' => $edgesAndCursors['totalCount'], |
||
120 | 'pageInfo' => [ |
||
121 | 'endCursor' => $edgesAndCursors['cursors']['end'], |
||
122 | 'startCursor' => $edgesAndCursors['cursors']['start'], |
||
123 | 'hasNextPage' => $edgesAndCursors['cursors']['end'] !== $edgesAndCursors['cursors']['last'], |
||
124 | 'hasPreviousPage' => $edgesAndCursors['cursors']['first'] !== null |
||
125 | && $edgesAndCursors['cursors']['start'] !== $edgesAndCursors['cursors']['first'], |
||
126 | ], |
||
218 |