Skip to content

Commit

Permalink
set phpstan static check to 7 and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sagautam5 committed Apr 7, 2024
1 parent c443f95 commit c8172cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Entities/District.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getDistrictsWithMunicipalities()
public function getDistrictsByProvince($provinceId)
{
return array_values(array_filter($this->items, function ($item) use ($provinceId) {
return ($item->province_id == $provinceId);
return property_exists($item, 'province_id') && ($item->province_id == $provinceId);
}));
}

Expand Down
10 changes: 5 additions & 5 deletions src/Entities/Municipality.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function allMunicipalities()
public function getMunicipalitiesByDistrict($districtId)
{
return array_values(array_filter($this->items, function ($item) use ($districtId) {
return ($item->district_id == $districtId);
return property_exists($item, 'district_id') && ($item->district_id == $districtId);
}));
}

Expand All @@ -72,7 +72,7 @@ public function getMunicipalitiesByDistrict($districtId)
public function getMunicipalityByCategory($categoryId)
{
return array_values(array_filter($this->items, function ($item) use ($categoryId) {
return ($item->category_id == $categoryId);
return property_exists($item, 'category_id') && ($item->category_id == $categoryId);
}));
}

Expand All @@ -87,7 +87,7 @@ public function getMunicipalityByProvince($provinceId)
$district = new District();
$districts = $district->getDistrictsByProvince($provinceId);
$municipalities = array_map(function ($item) {
return $this->getMunicipalitiesByDistrict($item->id);
return $this->getMunicipalitiesByDistrict($item->id ?? 0);
}, $districts);

return array_merge(...$municipalities);
Expand Down Expand Up @@ -154,14 +154,14 @@ public function wards($id)

if($this->lang == 'np'){

$totalWards = Helper::numericEnglish($municipality->wards);
$totalWards = Helper::numericEnglish($municipality->wards ?? 1);

$wards = range(1, $totalWards);
$wards = array_map(function ($item){
return Helper::numericNepali($item);
}, $wards);
}else{
$wards = range(1, $municipality->wards);
$wards = range(1, $municipality->wards ?? 1);
}
return $wards;
}
Expand Down

0 comments on commit c8172cc

Please sign in to comment.