Skip to content

Commit

Permalink
Merge pull request #15 from RonasIT/dpankratov/disable-typization
Browse files Browse the repository at this point in the history
Dpankratov/disable typization
  • Loading branch information
DenTray authored Nov 10, 2021
2 parents fce98a8 + 01e66f3 commit 4316647
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
39 changes: 20 additions & 19 deletions src/Traits/EntityControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,13 @@ public function updateMany($where, array $data, bool $updatedRecordsAsResult = t
$fields = $this->forceMode ? $modelClass::getFields() : $this->model->getFillable();
$entityData = Arr::only($data, $fields);

$unUpdatedIds = [];
$this->chunk($limit, function ($items) use (&$unUpdatedIds) {
$unUpdatedIds = array_merge($unUpdatedIds, Arr::pluck($items, 'id'));
$idsToUpdate = [];

$this->chunk($limit, function ($items) use (&$idsToUpdate) {
$idsToUpdate = array_merge($idsToUpdate, Arr::pluck($items, 'id'));
}, $where);

$updatedRowsCount = $this->updateByList($unUpdatedIds, $entityData);
$updatedRowsCount = $this->updateByList($idsToUpdate, $entityData);

if (!$updatedRecordsAsResult) {
return $updatedRowsCount;
Expand All @@ -231,7 +232,7 @@ public function updateMany($where, array $data, bool $updatedRecordsAsResult = t
*
* @return array
*/
public function update($where, array $data): array
public function update($where, array $data)
{
$item = $this->getQuery($where)->first();

Expand Down Expand Up @@ -278,11 +279,11 @@ public function count($where = [])
return $this->getQuery($where)->count();
}

public function get(array $where = []): array
public function get(array $where = [])
{
$result = $this->getQuery($where)->get();

$this->hideUnHideFields($result);
$this->applyHidingShowingFieldsRules($result);

return $result->toArray();
}
Expand All @@ -301,7 +302,7 @@ public function getOrCreate($data)
return $entities;
}

public function first(array $where = []): array
public function first($where = [])
{
$entity = $this->getQuery($where)->first();

Expand All @@ -311,12 +312,12 @@ public function first(array $where = []): array
->toArray();
}

public function findBy(string $field, $value): array
public function findBy(string $field, $value)
{
return $this->first([$field => $value]);
}

public function find($id): array
public function find($id)
{
return $this->first([$this->primaryKey => $id]);
}
Expand Down Expand Up @@ -344,7 +345,7 @@ public function firstOrCreate($where, array $data = [])
* @param array|integer|string $where
* @return integer count of deleted rows
*/
public function delete($where): int
public function delete($where)
{
$query = $this->getQuery($where);

Expand Down Expand Up @@ -377,7 +378,7 @@ public function onlyTrashed($enable = true): self
return $this;
}

public function restore($where): int
public function restore($where)
{
return $this->getQuery($where)->onlyTrashed()->restore();
}
Expand All @@ -388,7 +389,7 @@ public function chunk($limit, $callback, $where = [])
->getQuery($where)
->orderBy($this->primaryKey)
->chunk($limit, function ($items) use ($callback) {
$this->hideUnHideFields($items);
$this->applyHidingShowingFieldsRules($items);

$callback($items->toArray());
});
Expand All @@ -401,7 +402,7 @@ public function chunk($limit, $callback, $where = [])
* @param string|null $field condition field, primary key is default value
* @return integer count of deleted rows
*/
public function deleteByList(array $values, $field = null): int
public function deleteByList(array $values, $field = null)
{
$field = (empty($field)) ? $this->primaryKey : $field;

Expand All @@ -416,7 +417,7 @@ public function deleteByList(array $values, $field = null): int
}
}

public function restoreByList($values, $field = null): array
public function restoreByList($values, $field = null)
{
$field = (empty($field)) ? $this->primaryKey : $field;

Expand All @@ -427,14 +428,14 @@ public function restoreByList($values, $field = null): array

$entities = $query->get();

$this->hideUnHideFields($entities);
$this->applyHidingShowingFieldsRules($entities);

$query->restore();

return $entities->toArray();
}

public function getByList(array $values, $field = null): array
public function getByList(array $values, $field = null)
{
$field = (empty($field)) ? $this->primaryKey : $field;

Expand All @@ -443,7 +444,7 @@ public function getByList(array $values, $field = null): array
->whereIn($field, $values)
->get();

$this->hideUnHideFields($result);
$this->applyHidingShowingFieldsRules($result);

return $result->toArray();
}
Expand All @@ -455,7 +456,7 @@ public function countByList(array $values, $field = null): int
return $this->getQuery()->whereIn($field, $values)->count();
}

public function updateByList(array $values, $data, $field = null): int
public function updateByList(array $values, $data, $field = null)
{
$field = (empty($field)) ? $this->primaryKey : $field;

Expand Down
6 changes: 5 additions & 1 deletion src/Traits/FixturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ public function getJsonResponse()
return json_decode($response, true);
}

public function assertEqualsFixture($fixture, $data)
public function assertEqualsFixture($fixture, $data, bool $exportMode = false)
{
if ($exportMode) {
$this->exportJson($fixture, $data);
}

$this->assertEquals($this->getJsonFixture($fixture), $data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/SearchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getModifiedPaginator($paginator)
{
$collection = $paginator->getCollection();

$this->hideUnHideFields($collection);
$this->applyHidingShowingFieldsRules($collection);

return $paginator->setCollection($collection);
}
Expand Down Expand Up @@ -341,7 +341,7 @@ protected function calculatePerPage($total)
return config('defaults.items_per_page', 1);
}

protected function hideUnHideFields(&$collection)
protected function applyHidingShowingFieldsRules(&$collection)
{
if (Application::VERSION >= '5.8') {
$collection->makeHidden($this->hiddenAttributes)->makeVisible($this->visibleAttributes);
Expand Down

0 comments on commit 4316647

Please sign in to comment.