Skip to content

Commit

Permalink
Add return types to repository behavior methods [WEB-2961]
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiltri committed Dec 9, 2024
1 parent a9c2a09 commit 7be994b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/Libraries/Api/Models/BaseApiModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function setAppends(array $appends)
*
* @return array
*/
public function getFillable()
public function getFillable(): array
{
return $this->fillable;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/Behaviors/Handle3DModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function handle3DModel($object, $fields, $fieldName = 'aic_3d_model')
}
}

private function getFormFieldsFor3DModel($object, $fields, $fieldName = 'aic_3d_model')
private function getFormFieldsFor3DModel($object, $fields, $fieldName = 'aic_3d_model'): array
{
// Render the 3d model field in repeater block
if (
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/Behaviors/HandleApiBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait HandleApiBlocks
{
protected function getBlockBrowsers($block)
protected function getBlockBrowsers($block): array
{
return collect($block['content']['browsers'])->mapWithKeys(function ($ids, $relation) use ($block) {
try {
Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/Behaviors/HandleApiBrowsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ protected function getApiBrowsers()
})->values();
}

public function afterSaveHandleApiBrowsers($object, $fields)
public function afterSaveHandleApiBrowsers($object, $fields): void
{
foreach ($this->getApiBrowsers() as $browser) {
$this->updateBrowserApiRelated($object, $fields, $browser['browserName']);
}
}

public function getFormFieldsHandleApiBrowsers($object, $fields)
public function getFormFieldsHandleApiBrowsers($object, $fields): array
{
foreach ($this->getApiBrowsers() as $browser) {
$fields['browsers'][$browser['browserName']] = $this->getFormFieldsForBrowserApi($object, $browser['relation'], $browser['model'], $browser['routePrefix'], $browser['titleKey'], $browser['moduleName']);
Expand Down
8 changes: 4 additions & 4 deletions app/Repositories/Behaviors/HandleApiRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait HandleApiRelations
* and it creates new models per each new relation as we don't have both ends of the polymorphic relation
* This is done this way so we can reuse the same functions and table for all API browsers.
*/
public function updateBrowserApiRelated($object, $fields, $relationship, $positionAttribute = 'position')
public function updateBrowserApiRelated($object, $fields, $relationship, $positionAttribute = 'position'): void
{
$relatedElementsWithPosition = [];

Expand All @@ -40,7 +40,7 @@ public function updateBrowserApiRelated($object, $fields, $relationship, $positi
$object->{$relationship}()->attach($relatedElementsWithPosition);
}

public function updateMultiBrowserApiRelated($object, $fields, $relationship, $typeUsesApi)
public function updateMultiBrowserApiRelated($object, $fields, $relationship, $typeUsesApi): void
{
// WEB-2272: check if we dont leave some stale data in database by not deleting apiElements
// Remove all associations
Expand Down Expand Up @@ -87,7 +87,7 @@ public function updateMultiBrowserApiRelated($object, $fields, $relationship, $t
* This way we don't have to redesign the browser.
*
*/
public function getFormFieldsForBrowserApi($object, $relation, $apiModel, $routePrefix = null, $titleKey = 'title', $moduleName = null)
public function getFormFieldsForBrowserApi($object, $relation, $apiModel, $routePrefix = null, $titleKey = 'title', $moduleName = null): array
{
// Get all datahub_id's
$ids = $object->{$relation}->pluck('datahub_id')->toArray();
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getFormFieldsForBrowserApi($object, $relation, $apiModel, $route
})->values()->toArray();
}

public function getFormFieldsForMultiBrowserApi($object, $browser_name, $apiModelsDefinitions, $typeUsesApi)
public function getFormFieldsForMultiBrowserApi($object, $browser_name, $apiModelsDefinitions, $typeUsesApi): array
{
$results = collect();

Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/Behaviors/HandleAuthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

trait HandleAuthors
{
public function afterSaveHandleAuthors($object, $fields)
public function afterSaveHandleAuthors($object, $fields): void
{
$this->updateBrowser($object, $fields, 'authors');
}

public function getFormFieldsHandleAuthors($object, $fields)
public function getFormFieldsHandleAuthors($object, $fields): array
{
$fields['browsers']['authors'] = $this->getFormFieldsForBrowser($object, 'authors', 'collection');

Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/Behaviors/HandleExperienceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait HandleExperienceModule
{
public function updateExperienceModule($object, $fields, $relation, $model = null, $fieldName = null)
public function updateExperienceModule($object, $fields, $relation, $model = null, $fieldName = null): void
{
if ($model === 'ExperienceImage') {
$morphKey = 'imagable';
Expand Down Expand Up @@ -76,7 +76,7 @@ public function updateExperienceModule($object, $fields, $relation, $model = nul
}
}

public function getExperienceModule($object, $fields, $relation, $model = null, $fieldName = null)
public function getExperienceModule($object, $fields, $relation, $model = null, $fieldName = null): array
{
$repeaters = [];
$repeatersFields = [];
Expand Down
4 changes: 2 additions & 2 deletions app/Repositories/Behaviors/HandleFeaturedRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
trait HandleFeaturedRelated
{
public function afterSaveHandleFeaturedRelated($object, $fields)
public function afterSaveHandleFeaturedRelated($object, $fields): void
{
$this->updateMultiBrowserApiRelated($object, $fields, 'sidebar_items', [
'articles' => false,
Expand All @@ -21,7 +21,7 @@ public function afterSaveHandleFeaturedRelated($object, $fields)
]);
}

public function getFormFieldsHandleFeaturedRelated($object, $fields)
public function getFormFieldsHandleFeaturedRelated($object, $fields): array
{
$fields['browsers']['sidebar_items'] = $this->getFormFieldsForMultiBrowserApi($object, 'sidebar_items', [
'exhibitions' => [
Expand Down

0 comments on commit 7be994b

Please sign in to comment.