@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | class LaravelServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - public function register() |
|
9 | + public function register () |
|
10 | 10 | { |
11 | 11 | $this->app->register(\Bludata\Doctrine\ORM\Providers\ORMServiceProvider::class); |
12 | 12 | } |
@@ -6,12 +6,12 @@ discard block |
||
6 | 6 | * @param string $repository |
7 | 7 | * @param string $entity |
8 | 8 | */ |
9 | - function bind_repository(string $repositoryInterface, string $repository, string $entity) |
|
9 | + function bind_repository (string $repositoryInterface, string $repository, string $entity) |
|
10 | 10 | { |
11 | 11 | app()->bind($repositoryInterface, function ($app) use ($repository, $entity) { |
12 | 12 | return new $repository( |
13 | - $app['em'], |
|
14 | - $app['em']->getClassMetaData($entity) |
|
13 | + $app[ 'em' ], |
|
14 | + $app[ 'em' ]->getClassMetaData($entity) |
|
15 | 15 | ); |
16 | 16 | }); |
17 | 17 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @param string $className |
23 | 23 | */ |
24 | - function bdEntityName(string $className) |
|
24 | + function bdEntityName (string $className) |
|
25 | 25 | { |
26 | 26 | return config('bludata.generator.namespace.root').config('bludata.generator.namespace.entities').$className; |
27 | 27 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @param string $className |
33 | 33 | */ |
34 | - function bdEntity(string $className) |
|
34 | + function bdEntity (string $className) |
|
35 | 35 | { |
36 | 36 | return app(bdEntityName($className)); |
37 | 37 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * @param string $className |
43 | 43 | */ |
44 | - function bdContractRepositoryName(string $className) |
|
44 | + function bdContractRepositoryName (string $className) |
|
45 | 45 | { |
46 | 46 | return config('bludata.generator.namespace.root').config('bludata.generator.namespace.contracts.repositories').$className.'ContractRepository'; |
47 | 47 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * @param string $className |
53 | 53 | */ |
54 | - function bdRepositoryName(string $className) |
|
54 | + function bdRepositoryName (string $className) |
|
55 | 55 | { |
56 | 56 | return config('bludata.generator.namespace.root').config('bludata.generator.namespace.repositories').$className.'Repository'; |
57 | 57 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @param string $className |
63 | 63 | */ |
64 | - function bdRepository(string $className) |
|
64 | + function bdRepository (string $className) |
|
65 | 65 | { |
66 | 66 | return app(bdContractRepositoryName($className)); |
67 | 67 | } |
@@ -7,23 +7,23 @@ |
||
7 | 7 | |
8 | 8 | interface RepositoryContract |
9 | 9 | { |
10 | - public function getEntityManager(): EntityManager; |
|
10 | + public function getEntityManager (): EntityManager; |
|
11 | 11 | |
12 | - public function getClassMetadata(): ClassMetadata; |
|
12 | + public function getClassMetadata (): ClassMetadata; |
|
13 | 13 | |
14 | - public function createQueryWorker(): QueryWorkerContract; |
|
14 | + public function createQueryWorker (): QueryWorkerContract; |
|
15 | 15 | |
16 | - public function findAll(): QueryWorkerContract; |
|
16 | + public function findAll (): QueryWorkerContract; |
|
17 | 17 | |
18 | - public function findOneBy(array $criteria, bool $abort = true): ?EntityContract; |
|
18 | + public function findOneBy (array $criteria, bool $abort = true): ?EntityContract; |
|
19 | 19 | |
20 | - public function find($id, bool $abort = true): ?EntityContract; |
|
20 | + public function find ($id, bool $abort = true): ?EntityContract; |
|
21 | 21 | |
22 | - public function findAllRemoved(): QueryWorkerContract; |
|
22 | + public function findAllRemoved (): QueryWorkerContract; |
|
23 | 23 | |
24 | - public function findRemoved($id, bool $abort = true): ?EntityContract; |
|
24 | + public function findRemoved ($id, bool $abort = true): ?EntityContract; |
|
25 | 25 | |
26 | - public function createEntity(): EntityContract; |
|
26 | + public function createEntity (): EntityContract; |
|
27 | 27 | |
28 | - public function remove(EntityContract $entity): EntityContract; |
|
28 | + public function remove (EntityContract $entity): EntityContract; |
|
29 | 29 | } |
@@ -4,5 +4,5 @@ |
||
4 | 4 | |
5 | 5 | interface ToArrayContract |
6 | 6 | { |
7 | - public function toArray(array $options = []): array; |
|
7 | + public function toArray (array $options = [ ]): array; |
|
8 | 8 | } |
@@ -6,9 +6,9 @@ |
||
6 | 6 | |
7 | 7 | interface QueryWorkerContract |
8 | 8 | { |
9 | - public function __construct(RepositoryContract $repository); |
|
9 | + public function __construct (RepositoryContract $repository); |
|
10 | 10 | |
11 | - public function getResult(): ArrayCollection; |
|
11 | + public function getResult (): ArrayCollection; |
|
12 | 12 | |
13 | - public function getOneResult(): ?EntityContract; |
|
13 | + public function getOneResult (): ?EntityContract; |
|
14 | 14 | } |
@@ -6,35 +6,35 @@ |
||
6 | 6 | |
7 | 7 | interface EntityContract |
8 | 8 | { |
9 | - public function getId(); |
|
9 | + public function getId (); |
|
10 | 10 | |
11 | - public function getCreatedAt(): ?DateTime; |
|
11 | + public function getCreatedAt (): ?DateTime; |
|
12 | 12 | |
13 | - public function getUpdatedAt(): ?DateTime; |
|
13 | + public function getUpdatedAt (): ?DateTime; |
|
14 | 14 | |
15 | - public function getDeletedAt(): ?DateTime; |
|
15 | + public function getDeletedAt (): ?DateTime; |
|
16 | 16 | |
17 | - public function getRepository(): RepositoryContract; |
|
17 | + public function getRepository (): RepositoryContract; |
|
18 | 18 | |
19 | - public function preRemove(); |
|
19 | + public function preRemove (); |
|
20 | 20 | |
21 | - public function postRemove(); |
|
21 | + public function postRemove (); |
|
22 | 22 | |
23 | - public function prePersist(); |
|
23 | + public function prePersist (); |
|
24 | 24 | |
25 | - public function postPersist(); |
|
25 | + public function postPersist (); |
|
26 | 26 | |
27 | - public function preUpdate(); |
|
27 | + public function preUpdate (); |
|
28 | 28 | |
29 | - public function postUpdate(); |
|
29 | + public function postUpdate (); |
|
30 | 30 | |
31 | - public function preFlush(); |
|
31 | + public function preFlush (); |
|
32 | 32 | |
33 | - public function persist(): EntityContract; |
|
33 | + public function persist (): EntityContract; |
|
34 | 34 | |
35 | - public function flush(): EntityContract; |
|
35 | + public function flush (): EntityContract; |
|
36 | 36 | |
37 | - public function remove(): EntityContract; |
|
37 | + public function remove (): EntityContract; |
|
38 | 38 | |
39 | - public function undelete(): EntityContract; |
|
39 | + public function undelete (): EntityContract; |
|
40 | 40 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | |
7 | 7 | class CommonServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - public function register() |
|
9 | + public function register () |
|
10 | 10 | { |
11 | 11 | register_annotation_dir(__DIR__.'/../Annotations'); |
12 | 12 | } |
@@ -16,40 +16,40 @@ discard block |
||
16 | 16 | |
17 | 17 | protected $classMetadata; |
18 | 18 | |
19 | - protected $entitys = []; |
|
19 | + protected $entitys = [ ]; |
|
20 | 20 | |
21 | - protected $tables = []; |
|
21 | + protected $tables = [ ]; |
|
22 | 22 | |
23 | - protected $queryFields = []; |
|
23 | + protected $queryFields = [ ]; |
|
24 | 24 | |
25 | - protected $expressions = []; |
|
25 | + protected $expressions = [ ]; |
|
26 | 26 | |
27 | - protected $groupFields = []; |
|
27 | + protected $groupFields = [ ]; |
|
28 | 28 | |
29 | - protected $field = []; |
|
29 | + protected $field = [ ]; |
|
30 | 30 | |
31 | 31 | protected $position = 0; |
32 | 32 | |
33 | - protected $fieldValue = []; |
|
33 | + protected $fieldValue = [ ]; |
|
34 | 34 | |
35 | - public function __construct(BdContracts\RepositoryContract $repository) |
|
35 | + public function __construct (BdContracts\RepositoryContract $repository) |
|
36 | 36 | { |
37 | 37 | $this->em = $repository->getEntityManager(); |
38 | 38 | $this->queryBuilder = $repository->createQueryBuilder(self::DEFAULT_TABLE_ALIAS); |
39 | 39 | $this->classMetadata = $repository->getClassMetadata(); |
40 | 40 | } |
41 | 41 | |
42 | - public function getResult(): ArrayCollection |
|
42 | + public function getResult (): ArrayCollection |
|
43 | 43 | { |
44 | 44 | return new ArrayCollection($this->queryBuilder->getQuery()->execute()); |
45 | 45 | } |
46 | 46 | |
47 | - public function getOneResult(): ?BdContracts\EntityContract |
|
47 | + public function getOneResult (): ?BdContracts\EntityContract |
|
48 | 48 | { |
49 | 49 | return $this->queryBuilder->getQuery()->getOneOrNullResult(); |
50 | 50 | } |
51 | 51 | |
52 | - public function toArray(array $options = []): array |
|
52 | + public function toArray (array $options = [ ]): array |
|
53 | 53 | { |
54 | 54 | return $this->getResult() |
55 | 55 | ->map(function ($element) use ($options){ |
@@ -64,40 +64,40 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return QueryWorker |
66 | 66 | */ |
67 | - public function withFilters(array $filters = null) |
|
67 | + public function withFilters (array $filters = null) |
|
68 | 68 | { |
69 | 69 | if ($filters) { |
70 | 70 | foreach ($filters as $filter) { |
71 | - switch ($filter['type']) { |
|
71 | + switch ($filter[ 'type' ]) { |
|
72 | 72 | case 'select': |
73 | - $this->select($filter['fields']); |
|
73 | + $this->select($filter[ 'fields' ]); |
|
74 | 74 | break; |
75 | 75 | case 'andWhere': |
76 | - $this->andWhere($filter['field'], $filter['operation'], $filter['value']); |
|
76 | + $this->andWhere($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]); |
|
77 | 77 | break; |
78 | 78 | case 'orWhere': |
79 | - $this->orWhere($filter['field'], $filter['operation'], $filter['value']); |
|
79 | + $this->orWhere($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]); |
|
80 | 80 | break; |
81 | 81 | case 'andHaving': |
82 | - $this->andHaving($filter['field'], $filter['operation'], $filter['value']); |
|
82 | + $this->andHaving($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]); |
|
83 | 83 | break; |
84 | 84 | case 'orHaving': |
85 | - $this->orHaving($filter['field'], $filter['operation'], $filter['value']); |
|
85 | + $this->orHaving($filter[ 'field' ], $filter[ 'operation' ], $filter[ 'value' ]); |
|
86 | 86 | break; |
87 | 87 | case 'addGroupBy': |
88 | - $this->addGroupBy($filter['field']); |
|
88 | + $this->addGroupBy($filter[ 'field' ]); |
|
89 | 89 | break; |
90 | 90 | case 'addOrderBy': |
91 | - $this->addOrderBy($filter['field'], $filter['order']); |
|
91 | + $this->addOrderBy($filter[ 'field' ], $filter[ 'order' ]); |
|
92 | 92 | break; |
93 | 93 | case 'fkAddOrderBy': |
94 | - $this->fkAddOrderBy($filter['field'], $filter['fkField'], $filter['order']); |
|
94 | + $this->fkAddOrderBy($filter[ 'field' ], $filter[ 'fkField' ], $filter[ 'order' ]); |
|
95 | 95 | break; |
96 | 96 | case 'paginate': |
97 | - if (isset($filter['page'])) { |
|
98 | - $this->paginate($filter['limit'], $filter['page']); |
|
97 | + if (isset($filter[ 'page' ])) { |
|
98 | + $this->paginate($filter[ 'limit' ], $filter[ 'page' ]); |
|
99 | 99 | } else { |
100 | - $this->paginate($filter['limit']); |
|
100 | + $this->paginate($filter[ 'limit' ]); |
|
101 | 101 | } |
102 | 102 | break; |
103 | 103 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return $this |
117 | 117 | */ |
118 | - public function paginate($limit = 25, $page = 0) |
|
118 | + public function paginate ($limit = 25, $page = 0) |
|
119 | 119 | { |
120 | 120 | if ($limit > 0) { |
121 | 121 | $this->queryBuilder->setMaxResults($limit); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return $this |
139 | 139 | */ |
140 | - public function andWhere($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS) |
|
140 | + public function andWhere ($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS) |
|
141 | 141 | { |
142 | 142 | if (strpos($field, '.') > 0) { |
143 | 143 | //monta os joins |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | 'operation' => $operation, |
147 | 147 | ]; |
148 | 148 | $newAliasField = $this->associationQueryFields($field); |
149 | - $alias = $newAliasField['alias']; |
|
150 | - $field = $newAliasField['field']; |
|
149 | + $alias = $newAliasField[ 'alias' ]; |
|
150 | + $field = $newAliasField[ 'field' ]; |
|
151 | 151 | } |
152 | 152 | $this->queryBuilder->andWhere($this->makeExpression($field, $operation, $value, $alias)); |
153 | 153 | |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return $this |
165 | 165 | */ |
166 | - public function orWhere($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS) |
|
166 | + public function orWhere ($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS) |
|
167 | 167 | { |
168 | 168 | if (strpos($field, '.') > 0) { |
169 | 169 | //monta os joins |
170 | 170 | $newAliasField = $this->associationQueryFields($field); |
171 | - $alias = $newAliasField['alias']; |
|
172 | - $field = $newAliasField['field']; |
|
171 | + $alias = $newAliasField[ 'alias' ]; |
|
172 | + $field = $newAliasField[ 'field' ]; |
|
173 | 173 | } |
174 | 174 | $this->queryBuilder->orWhere($this->makeExpression($field, $operation, $value, $alias)); |
175 | 175 | |
@@ -183,18 +183,18 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return $this |
185 | 185 | */ |
186 | - private function makeExpressions($conditions, $alias = self::DEFAULT_TABLE_ALIAS) |
|
186 | + private function makeExpressions ($conditions, $alias = self::DEFAULT_TABLE_ALIAS) |
|
187 | 187 | { |
188 | - $expressions = []; |
|
188 | + $expressions = [ ]; |
|
189 | 189 | foreach ($conditions as $attr) { |
190 | - $field = $attr['field']; |
|
190 | + $field = $attr[ 'field' ]; |
|
191 | 191 | if (strpos($field, '.') > 0) { |
192 | 192 | //monta os joins |
193 | 193 | $newAliasField = $this->associationQueryFields($field); |
194 | - $alias = $newAliasField['alias']; |
|
195 | - $field = $newAliasField['field']; |
|
194 | + $alias = $newAliasField[ 'alias' ]; |
|
195 | + $field = $newAliasField[ 'field' ]; |
|
196 | 196 | } |
197 | - $expressions[] = $this->makeExpression($field, $attr['operation'], $attr['value'], $alias); |
|
197 | + $expressions[ ] = $this->makeExpression($field, $attr[ 'operation' ], $attr[ 'value' ], $alias); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | return $expressions; |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @param string $field |
207 | 207 | */ |
208 | - public function addGroupBy($field) |
|
208 | + public function addGroupBy ($field) |
|
209 | 209 | { |
210 | 210 | $alias = self::DEFAULT_TABLE_ALIAS; |
211 | 211 | if (strpos($field, '.') > 0) { |
@@ -214,15 +214,15 @@ discard block |
||
214 | 214 | } |
215 | 215 | if (count($this->queryFields) > 0) { |
216 | 216 | foreach ($this->queryFields as $item) { |
217 | - $parts = []; |
|
217 | + $parts = [ ]; |
|
218 | 218 | if (strpos($item, ' AS ')) { |
219 | 219 | $item = str_replace(')', '', str_replace('(', '', $item)); |
220 | 220 | $parts = explode('AS', $item); |
221 | - $item = trim($parts[0]); |
|
221 | + $item = trim($parts[ 0 ]); |
|
222 | 222 | } |
223 | 223 | if (!in_array($item, $this->groupFields)) { |
224 | 224 | $this->queryBuilder->addGroupBy($item); |
225 | - $this->groupFields[] = $item; |
|
225 | + $this->groupFields[ ] = $item; |
|
226 | 226 | } |
227 | 227 | } |
228 | 228 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return $this |
241 | 241 | */ |
242 | - public function andHaving($field, $operation, $value = null) |
|
242 | + public function andHaving ($field, $operation, $value = null) |
|
243 | 243 | { |
244 | 244 | throw new \Exception('Not implemented'); |
245 | 245 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param string $field |
251 | 251 | */ |
252 | - public function orHaving($field, $operation, $value = null) |
|
252 | + public function orHaving ($field, $operation, $value = null) |
|
253 | 253 | { |
254 | 254 | throw new \Exception('Not implemented'); |
255 | 255 | } |
@@ -260,14 +260,14 @@ discard block |
||
260 | 260 | * @param string $field |
261 | 261 | * @param string $order |
262 | 262 | */ |
263 | - public function addOrderBy($field, $order = 'ASC') |
|
263 | + public function addOrderBy ($field, $order = 'ASC') |
|
264 | 264 | { |
265 | 265 | $alias = self::DEFAULT_TABLE_ALIAS; |
266 | 266 | if (strpos($field, '.') > 0) { |
267 | 267 | //monta os joins |
268 | 268 | $newAliasField = $this->associationQueryFields($field); |
269 | - $alias = $newAliasField['alias']; |
|
270 | - $field = $newAliasField['field']; |
|
269 | + $alias = $newAliasField[ 'alias' ]; |
|
270 | + $field = $newAliasField[ 'field' ]; |
|
271 | 271 | } |
272 | 272 | $this->queryBuilder->addOrderBy($this->getFullFieldName($field, $alias), $order); |
273 | 273 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param string $field |
281 | 281 | * @param string $order |
282 | 282 | */ |
283 | - public function fkAddOrderBy($field, $fkField, $order = 'ASC') |
|
283 | + public function fkAddOrderBy ($field, $fkField, $order = 'ASC') |
|
284 | 284 | { |
285 | 285 | $alias = $this->tableAlias(); |
286 | 286 | $this->queryBuilder->join($this->getFullFieldName($field), $alias); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @param associationField.fkField |
296 | 296 | * @param $field |
297 | 297 | */ |
298 | - public function select($fields) |
|
298 | + public function select ($fields) |
|
299 | 299 | { |
300 | 300 | foreach ($fields as $key => $value) { |
301 | 301 | if (is_int($key)) { |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | $alias = $this->tableAlias(); |
305 | 305 | $this->queryBuilder->join($this->getFullFieldName($key, self::DEFAULT_TABLE_ALIAS), $alias); |
306 | 306 | foreach ($value as $valueField) { |
307 | - $this->queryFields[] = $this->getFullFieldName($valueField, $alias); |
|
307 | + $this->queryFields[ ] = $this->getFullFieldName($valueField, $alias); |
|
308 | 308 | } |
309 | 309 | } else { |
310 | - $this->queryFields[] = $value; |
|
310 | + $this->queryFields[ ] = $value; |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | $this->queryBuilder->select(implode(',', $this->queryFields)); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * @param associationField.fkField |
322 | 322 | * @param $field |
323 | 323 | */ |
324 | - public function associationQueryFields($campo) |
|
324 | + public function associationQueryFields ($campo) |
|
325 | 325 | { |
326 | 326 | $this->field = $campo; |
327 | 327 | $pos = strpos($campo, '.'); |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | $arr = explode('.', $campo); |
330 | 330 | $lastField = end($arr); |
331 | 331 | |
332 | - if (count($arr) == 2 && $arr[0] == self::DEFAULT_TABLE_ALIAS) { |
|
332 | + if (count($arr) == 2 && $arr[ 0 ] == self::DEFAULT_TABLE_ALIAS) { |
|
333 | 333 | //não é um campo composto |
334 | 334 | return [ |
335 | 335 | 'field' => $lastField, |
336 | - 'alias' => $arr[0], |
|
336 | + 'alias' => $arr[ 0 ], |
|
337 | 337 | ]; |
338 | 338 | } |
339 | 339 | |
@@ -344,14 +344,14 @@ discard block |
||
344 | 344 | if ($this->position < count($arr) - 1) { |
345 | 345 | $dados = $this->getMetaAndAliases(); |
346 | 346 | |
347 | - $alias = $dados['alias']; |
|
348 | - $parentAlias = $dados['parentAlias']; |
|
347 | + $alias = $dados[ 'alias' ]; |
|
348 | + $parentAlias = $dados[ 'parentAlias' ]; |
|
349 | 349 | |
350 | 350 | if ($tempMeta) { |
351 | 351 | $meta = $tempMeta; |
352 | 352 | $tempMeta = ''; |
353 | 353 | } else { |
354 | - $meta = $dados['parentMeta']; |
|
354 | + $meta = $dados[ 'parentMeta' ]; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | if ($meta->isAssociationWithSingleJoinColumn($value)) { |
@@ -359,22 +359,22 @@ discard block |
||
359 | 359 | $association = $meta->getAssociationMapping($value); |
360 | 360 | $this->setLeftJoin( |
361 | 361 | $meta->getAssociationTargetClass($value), |
362 | - $association['joinColumns'][0]['referencedColumnName'], |
|
363 | - $association['fieldName'], |
|
362 | + $association[ 'joinColumns' ][ 0 ][ 'referencedColumnName' ], |
|
363 | + $association[ 'fieldName' ], |
|
364 | 364 | $alias, |
365 | 365 | $parentAlias |
366 | 366 | ); |
367 | 367 | } elseif ($meta->isCollectionValuedAssociation($value)) { |
368 | 368 | $association = $meta->getAssociationMapping($value); |
369 | - if (empty($association['mappedBy']) && empty($association['joinTable'])) { |
|
369 | + if (empty($association[ 'mappedBy' ]) && empty($association[ 'joinTable' ])) { |
|
370 | 370 | //não tem como fazer o join |
371 | 371 | $this->critical(sprintf('"%s" não é uma associação válida', $campo)); |
372 | 372 | continue; |
373 | 373 | } |
374 | - if (!empty($association['joinTable'])) { |
|
374 | + if (!empty($association[ 'joinTable' ])) { |
|
375 | 375 | //manyToMany |
376 | 376 | $this->setManyToManyJoin( |
377 | - $this->getFullFieldName($association['fieldName'], $parentAlias), |
|
377 | + $this->getFullFieldName($association[ 'fieldName' ], $parentAlias), |
|
378 | 378 | $alias, |
379 | 379 | $this->setManyToManyValuedCondition($association, $alias, $arr) |
380 | 380 | ); |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | //oneToMany |
383 | 383 | $this->setLeftJoin( |
384 | 384 | $meta->getAssociationTargetClass($value), |
385 | - $this->getTargetField($dados['meta'], $meta, $value), |
|
386 | - $meta->getIdentifierColumnNames()[0], |
|
385 | + $this->getTargetField($dados[ 'meta' ], $meta, $value), |
|
386 | + $meta->getIdentifierColumnNames()[ 0 ], |
|
387 | 387 | $alias, |
388 | 388 | $parentAlias |
389 | 389 | ); |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | //subClass |
393 | 393 | if (count($meta->subClasses) > 0) { |
394 | 394 | $temp = $this->getSubClassFields($meta, $value); |
395 | - if (!empty($temp['meta'])) { |
|
396 | - $this->setLeftJoin($temp['table'], $temp['targetField'], $temp['parentField'], $alias, $parentAlias); |
|
397 | - $tempMeta = $temp['meta']; |
|
395 | + if (!empty($temp[ 'meta' ])) { |
|
396 | + $this->setLeftJoin($temp[ 'table' ], $temp[ 'targetField' ], $temp[ 'parentField' ], $alias, $parentAlias); |
|
397 | + $tempMeta = $temp[ 'meta' ]; |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | } |
@@ -421,23 +421,23 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @return string |
423 | 423 | */ |
424 | - private function getMetaAndAliases() |
|
424 | + private function getMetaAndAliases () |
|
425 | 425 | { |
426 | 426 | $arr = explode('.', $this->field); |
427 | 427 | $meta = $this->classMetadata; |
428 | - $metaAnterior = []; |
|
428 | + $metaAnterior = [ ]; |
|
429 | 429 | $parent = ''; |
430 | 430 | $alias = ''; |
431 | 431 | |
432 | 432 | for ($i = 0; $i <= $this->position; $i++) { |
433 | 433 | $metaAnterior = $meta; |
434 | 434 | |
435 | - if ($meta->hasAssociation($arr[$i])) { |
|
436 | - $class = $meta->getAssociationTargetClass($arr[$i]); |
|
435 | + if ($meta->hasAssociation($arr[ $i ])) { |
|
436 | + $class = $meta->getAssociationTargetClass($arr[ $i ]); |
|
437 | 437 | } elseif (count($meta->subClasses) > 0) { |
438 | - $temp = $this->getSubClassFields($meta, $arr[$i]); |
|
439 | - if (!empty($temp['meta'])) { |
|
440 | - $class = $temp['table']; |
|
438 | + $temp = $this->getSubClassFields($meta, $arr[ $i ]); |
|
439 | + if (!empty($temp[ 'meta' ])) { |
|
440 | + $class = $temp[ 'table' ]; |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
@@ -445,12 +445,12 @@ discard block |
||
445 | 445 | |
446 | 446 | if ($i < $this->position) { |
447 | 447 | $parent .= $parent != '' ? '_' : ''; |
448 | - $parent .= $arr[$i]; |
|
448 | + $parent .= $arr[ $i ]; |
|
449 | 449 | } |
450 | 450 | if ($i == $this->position) { |
451 | 451 | $alias .= $parent; |
452 | 452 | $alias .= $parent != '' ? '_' : ''; |
453 | - $alias .= $arr[$i]; |
|
453 | + $alias .= $arr[ $i ]; |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
@@ -478,12 +478,12 @@ discard block |
||
478 | 478 | * @param string $alias |
479 | 479 | * @param string $parentAlias |
480 | 480 | */ |
481 | - private function setJoin($table, $field, $parentField, $alias, $parentAlias) |
|
481 | + private function setJoin ($table, $field, $parentField, $alias, $parentAlias) |
|
482 | 482 | { |
483 | 483 | if (!in_array($alias, $this->tables)) { |
484 | 484 | $condition = $this->getFullFieldName($field, $alias).' = '.$this->getFullFieldName($parentField, $parentAlias); |
485 | 485 | $this->queryBuilder->join($table, $alias, 'WITH', $condition); |
486 | - $this->tables[] = $alias; |
|
486 | + $this->tables[ ] = $alias; |
|
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @param string $parentAlias |
498 | 498 | * @param bool $withWhere |
499 | 499 | */ |
500 | - private function setLeftJoin($table, $field, $parentField, $alias, $parentAlias, $withWhere = false) |
|
500 | + private function setLeftJoin ($table, $field, $parentField, $alias, $parentAlias, $withWhere = false) |
|
501 | 501 | { |
502 | 502 | if (!in_array($alias, $this->tables)) { |
503 | 503 | $condition = $this->getFullFieldName($field, $alias).' = '.$this->getFullFieldName($parentField, $parentAlias); |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | if ($withWhere) { |
506 | 506 | $this->queryBuilder->andWhere($condition); |
507 | 507 | } |
508 | - $this->tables[] = $alias; |
|
508 | + $this->tables[ ] = $alias; |
|
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
@@ -518,14 +518,14 @@ discard block |
||
518 | 518 | * |
519 | 519 | * @return mix|null |
520 | 520 | */ |
521 | - private function setManyToManyValuedCondition($association, $alias, $arr) |
|
521 | + private function setManyToManyValuedCondition ($association, $alias, $arr) |
|
522 | 522 | { |
523 | - if (empty($this->fieldValue['value']) || $this->position < count($arr) - 2) { |
|
523 | + if (empty($this->fieldValue[ 'value' ]) || $this->position < count($arr) - 2) { |
|
524 | 524 | return null; |
525 | 525 | } |
526 | - $targetField = $this->position == count($arr) - 1 ? $association['joinTable']['joinColumns'][0]['referencedColumnName'] : end($arr); |
|
526 | + $targetField = $this->position == count($arr) - 1 ? $association[ 'joinTable' ][ 'joinColumns' ][ 0 ][ 'referencedColumnName' ] : end($arr); |
|
527 | 527 | |
528 | - return $this->makeExpression($targetField, $this->fieldValue['operation'], $this->fieldValue['value'], $alias); |
|
528 | + return $this->makeExpression($targetField, $this->fieldValue[ 'operation' ], $this->fieldValue[ 'value' ], $alias); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @param string $alias |
536 | 536 | * @param mix $condition |
537 | 537 | */ |
538 | - private function setManyToManyJoin($table, $alias, $condition = null) |
|
538 | + private function setManyToManyJoin ($table, $alias, $condition = null) |
|
539 | 539 | { |
540 | 540 | if (!in_array($alias, $this->tables)) { |
541 | 541 | if ($condition) { |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | } else { |
544 | 544 | $this->queryBuilder->join($table, $alias); |
545 | 545 | } |
546 | - $this->tables[] = $alias; |
|
546 | + $this->tables[ ] = $alias; |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | |
@@ -554,19 +554,19 @@ discard block |
||
554 | 554 | * @param $value |
555 | 555 | * @param $alias |
556 | 556 | */ |
557 | - private function setQueryField($meta, $value, $alias) |
|
557 | + private function setQueryField ($meta, $value, $alias) |
|
558 | 558 | { |
559 | 559 | $campo = $this->getFullFieldName($value, $alias); |
560 | 560 | |
561 | 561 | if ($meta->isSingleValuedAssociation($value)) { |
562 | - $targetField = $meta->getAssociationMapping($value)['joinColumns'][0]['referencedColumnName']; |
|
562 | + $targetField = $meta->getAssociationMapping($value)[ 'joinColumns' ][ 0 ][ 'referencedColumnName' ]; |
|
563 | 563 | $alias = $alias == self::DEFAULT_TABLE_ALIAS ? substr($campo, strpos($campo, '.') + 1) : $alias.'_'.$targetField; |
564 | 564 | $campo = 'IDENTITY('.$campo.') '.$alias; |
565 | 565 | } elseif ($this->position > 0) { |
566 | 566 | $campo = '('.$campo.') AS '.$alias.'_'.$value; |
567 | 567 | } |
568 | 568 | // acrescenta o campo ao select |
569 | - $this->queryFields[] = $campo; |
|
569 | + $this->queryFields[ ] = $campo; |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | * |
578 | 578 | * @return string |
579 | 579 | */ |
580 | - private function getSubClassFields($meta, $value) |
|
580 | + private function getSubClassFields ($meta, $value) |
|
581 | 581 | { |
582 | 582 | foreach ($meta->subClasses as $subClass) { |
583 | 583 | $delimiter = strpos($subClass, '/') > 0 ? '/' : '\\'; |
@@ -586,8 +586,8 @@ discard block |
||
586 | 586 | if (end($temp) == $value) { |
587 | 587 | return [ |
588 | 588 | 'table' => $subClass, |
589 | - 'parentField' => $meta->getIdentifierColumnNames()[0], |
|
590 | - 'targetField' => $tempMeta->getIdentifierColumnNames()[0], |
|
589 | + 'parentField' => $meta->getIdentifierColumnNames()[ 0 ], |
|
590 | + 'targetField' => $tempMeta->getIdentifierColumnNames()[ 0 ], |
|
591 | 591 | 'meta' => $tempMeta, |
592 | 592 | ]; |
593 | 593 | } |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | * |
604 | 604 | * @return string |
605 | 605 | */ |
606 | - private function getTargetField($meta, $parentMeta, $value) |
|
606 | + private function getTargetField ($meta, $parentMeta, $value) |
|
607 | 607 | { |
608 | 608 | if (count($parentMeta->parentClasses) > 0) { |
609 | 609 | foreach ($parentMeta->parentClasses as $classe) { |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | return $field; |
624 | 624 | } |
625 | 625 | |
626 | - return $meta->getIdentifierColumnNames()[0]; |
|
626 | + return $meta->getIdentifierColumnNames()[ 0 ]; |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | /** |
@@ -635,11 +635,11 @@ discard block |
||
635 | 635 | * |
636 | 636 | * @return string |
637 | 637 | */ |
638 | - private function searchAssociationField($associationsByTargetClass, $parentTable, $value) |
|
638 | + private function searchAssociationField ($associationsByTargetClass, $parentTable, $value) |
|
639 | 639 | { |
640 | 640 | foreach ($associationsByTargetClass as $table => $association) { |
641 | - if ($table == $parentTable && $association['inversedBy'] == $value) { |
|
642 | - return $association['fieldName']; |
|
641 | + if ($table == $parentTable && $association[ 'inversedBy' ] == $value) { |
|
642 | + return $association[ 'fieldName' ]; |
|
643 | 643 | } |
644 | 644 | } |
645 | 645 | } |
@@ -649,14 +649,14 @@ discard block |
||
649 | 649 | * @param string $expression |
650 | 650 | * @param string $alias |
651 | 651 | */ |
652 | - private function getSelectExpression($expression, $field, $alias, $fieldAlias = self::DEFAULT_TABLE_ALIAS) |
|
652 | + private function getSelectExpression ($expression, $field, $alias, $fieldAlias = self::DEFAULT_TABLE_ALIAS) |
|
653 | 653 | { |
654 | - $validExpressions = ['SUM', 'MIN', 'MAX', 'AVG', 'COUNT']; |
|
654 | + $validExpressions = [ 'SUM', 'MIN', 'MAX', 'AVG', 'COUNT' ]; |
|
655 | 655 | if (in_array(trim(strtoupper($expression)), $validExpressions)) { |
656 | 656 | if (strpos($field, '.') === false) { |
657 | 657 | $field = getFullFieldName($field, $fieldAlias); |
658 | 658 | } |
659 | - $this->queryFields[] = sprintf('%s(%s) AS %s', $expression, $field, $alias); |
|
659 | + $this->queryFields[ ] = sprintf('%s(%s) AS %s', $expression, $field, $alias); |
|
660 | 660 | } |
661 | 661 | } |
662 | 662 | |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | * |
667 | 667 | * @return string |
668 | 668 | */ |
669 | - protected function getFullFieldName($field, $alias = self::DEFAULT_TABLE_ALIAS, $separator = '.') |
|
669 | + protected function getFullFieldName ($field, $alias = self::DEFAULT_TABLE_ALIAS, $separator = '.') |
|
670 | 670 | { |
671 | 671 | return sprintf('%s%s%s', $alias, $separator, $field); |
672 | 672 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | * @param null $value |
678 | 678 | * @param string $alias |
679 | 679 | */ |
680 | - protected function makeExpression($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS) |
|
680 | + protected function makeExpression ($field, $operation, $value = null, $alias = self::DEFAULT_TABLE_ALIAS) |
|
681 | 681 | { |
682 | 682 | $originalValue = $value; |
683 | 683 | |
@@ -739,10 +739,10 @@ discard block |
||
739 | 739 | $expression = $alias.' INSTANCE OF '.$value; |
740 | 740 | break; |
741 | 741 | case 'between': |
742 | - $expression = $this->queryBuilder->expr()->between($field, $this->queryBuilder->expr()->literal($value[0]), $this->queryBuilder->expr()->literal($value[1])); |
|
742 | + $expression = $this->queryBuilder->expr()->between($field, $this->queryBuilder->expr()->literal($value[ 0 ]), $this->queryBuilder->expr()->literal($value[ 1 ])); |
|
743 | 743 | break; |
744 | 744 | case 'dateparteq': |
745 | - $expression = $this->queryBuilder->expr()->eq("DATEPART('".$value['format']."', ".$field.')', $value['value']); |
|
745 | + $expression = $this->queryBuilder->expr()->eq("DATEPART('".$value[ 'format' ]."', ".$field.')', $value[ 'value' ]); |
|
746 | 746 | } |
747 | 747 | |
748 | 748 | return $expression; |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | /** |
752 | 752 | * @return string |
753 | 753 | */ |
754 | - protected function tableAlias() |
|
754 | + protected function tableAlias () |
|
755 | 755 | { |
756 | 756 | return self::DEFAULT_TABLE_ALIAS.count($this->queryBuilder->getAllAliases()); |
757 | 757 | } |
@@ -11,27 +11,27 @@ discard block |
||
11 | 11 | |
12 | 12 | abstract class BaseRepository extends EntityRepository implements RepositoryContract |
13 | 13 | { |
14 | - public function getEntityManager(): EntityManager |
|
14 | + public function getEntityManager (): EntityManager |
|
15 | 15 | { |
16 | 16 | return parent::getEntityManager(); |
17 | 17 | } |
18 | 18 | |
19 | - public function getClassMetadata(): ClassMetadata |
|
19 | + public function getClassMetadata (): ClassMetadata |
|
20 | 20 | { |
21 | 21 | return parent::getClassMetadata(); |
22 | 22 | } |
23 | 23 | |
24 | - public function createQueryWorker(): QueryWorkerContract |
|
24 | + public function createQueryWorker (): QueryWorkerContract |
|
25 | 25 | { |
26 | 26 | return new QueryWorker($this); |
27 | 27 | } |
28 | 28 | |
29 | - public function findAll(): QueryWorkerContract |
|
29 | + public function findAll (): QueryWorkerContract |
|
30 | 30 | { |
31 | 31 | return $this->createQueryWorker(); |
32 | 32 | } |
33 | 33 | |
34 | - public function findOneBy(array $criteria, bool $abort = true): ?EntityContract |
|
34 | + public function findOneBy (array $criteria, bool $abort = true): ?EntityContract |
|
35 | 35 | { |
36 | 36 | $findAll = $this->findAll(); |
37 | 37 | |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | return null; |
53 | 53 | } |
54 | 54 | |
55 | - public function find($id, bool $abort = true): ?EntityContract |
|
55 | + public function find ($id, bool $abort = true): ?EntityContract |
|
56 | 56 | { |
57 | - return $this->findOneBy(['id' => $id], $abort); |
|
57 | + return $this->findOneBy([ 'id' => $id ], $abort); |
|
58 | 58 | } |
59 | 59 | |
60 | - public function findAllRemoved(): QueryWorkerContract |
|
60 | + public function findAllRemoved (): QueryWorkerContract |
|
61 | 61 | { |
62 | 62 | disableSoftDeleteableFilter(); |
63 | 63 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ->andWhere('deletedAt', 'isnotnull'); |
66 | 66 | } |
67 | 67 | |
68 | - public function findRemoved($id, bool $abort = true): ?EntityContract |
|
68 | + public function findRemoved ($id, bool $abort = true): ?EntityContract |
|
69 | 69 | { |
70 | 70 | $entity = $this->findAllRemoved() |
71 | 71 | ->andWhere('id', '=', $id) |
@@ -80,14 +80,14 @@ discard block |
||
80 | 80 | abort(404, 'Registro não encontrado'); |
81 | 81 | } |
82 | 82 | |
83 | - public function createEntity(): EntityContract |
|
83 | + public function createEntity (): EntityContract |
|
84 | 84 | { |
85 | 85 | $entityName = $this->getEntityName(); |
86 | 86 | |
87 | 87 | return new $entityName(); |
88 | 88 | } |
89 | 89 | |
90 | - public function remove(EntityContract $entity): EntityContract |
|
90 | + public function remove (EntityContract $entity): EntityContract |
|
91 | 91 | { |
92 | 92 | $this->getEntityManager() |
93 | 93 | ->remove($entity); |