Skip to content

Commit

Permalink
lock code quality at level 5 for tests and set 6 for src
Browse files Browse the repository at this point in the history
  • Loading branch information
sagautam5 committed Apr 7, 2024
1 parent d5b5a9e commit c443f95
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 66 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ jobs:

- name: Run PHPUnit tests
run: vendor/bin/phpunit

- name: Run PhpStan Analyse Code
run: vendor/bin/phpstan analyse --level=6 src

- name: Run PhpStan Analyse Code
run: vendor/bin/phpstan analyse --level=4 src tests
run: vendor/bin/phpstan analyse --level=5 tests
30 changes: 14 additions & 16 deletions src/Entities/BaseEntity.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


namespace Sagautam5\LocalStateNepal\Entities;


abstract class BaseEntity
{
/**
Expand All @@ -24,13 +22,13 @@ abstract class BaseEntity
/**
* Filter data by key value pair
*
* @param $key
* @param $value
* @param $data
* @param string $key
* @param string $value
* @param array<object> $data
* @param bool $exact
* @return array
* @return array<object>
*/
protected function filter($key, $value, $data, $exact = false)
protected function filter($key, $value, $data, $exact = false): array
{
return array_values(array_filter($data, function ($item) use ($key, $value, $exact) {
return ($exact ? ($item->$key == $value ? true:false) :(is_int(strpos($item->$key, $value)) ? true:false));
Expand All @@ -42,27 +40,27 @@ protected function filter($key, $value, $data, $exact = false)
*
* @return string
*/
public function getLanguage()
public function getLanguage(): string
{
return $this->lang;
}

/**
* @return mixed
* @return array<string>
*/
public function getKeys()
public function getKeys(): array
{
return $this->keys;
}

/**
* Recursive Search Data
*
* @param $params
* @param array $items
* @return array|mixed
* @param array<mixed> $params
* @param array<object> $items
* @return array<object>
*/
public function recursiveSearch($params, $items = [])
public function recursiveSearch($params, $items = []): array
{
$items = $items ? $items : $this->items;

Expand All @@ -78,9 +76,9 @@ public function recursiveSearch($params, $items = [])
*
* @param string $key
* @param int $order
* @return mixed
* @return array<mixed>
*/
public function sortBy($key = 'name', $order = SORT_ASC)
public function sortBy($key = 'name', $order = SORT_ASC): array
{
$keys = array_column($this->items, $key);

Expand Down
10 changes: 5 additions & 5 deletions src/Entities/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function allCategories()
/**
* Find category by id
*
* @param $id
* @param int $id
* @return object|null
*/
public function find($id)
Expand All @@ -57,7 +57,7 @@ public function find($id)
/**
* Find category by short code
*
* @param $short_code
* @param string $short_code
* @return object|null
*/
public function findByShortCode($short_code)
Expand All @@ -70,10 +70,10 @@ public function findByShortCode($short_code)
/**
* Search Categories
*
* @param $key
* @param $value
* @param string $key
* @param string $value
* @param bool $exact
* @return array
* @return array<object>
*/
public function search($key, $value, $exact = false)
{
Expand Down
18 changes: 9 additions & 9 deletions src/Entities/District.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function allDistricts()
/**
* Get districts with municipalities
*
* @return array
* @return array<object>
* @throws LoadingException
*/
public function getDistrictsWithMunicipalities()
Expand All @@ -69,8 +69,8 @@ public function getDistrictsWithMunicipalities()
/**
* Get districts by province id
*
* @param $provinceId
* @return array|mixed|null
* @param int $provinceId
* @return array<object>|null
*/
public function getDistrictsByProvince($provinceId)
{
Expand All @@ -82,7 +82,7 @@ public function getDistrictsByProvince($provinceId)
/**
* Find district by id
*
* @param $id
* @param int $id
* @return object|null
*/
public function find($id)
Expand All @@ -95,7 +95,7 @@ public function find($id)
/**
* Get district with largest area
*
* @return mixed
* @return object
*/
public function largest()
{
Expand All @@ -113,7 +113,7 @@ public function largest()
/**
* Get district with smallest area
*
* @return mixed
* @return object
*/
public function smallest()
{
Expand All @@ -131,10 +131,10 @@ public function smallest()
/**
* Search Districts
*
* @param $key
* @param $value
* @param string $key
* @param string $value
* @param bool $exact
* @return array
* @return array<object>
*/
public function search($key, $value, $exact = false)
{
Expand Down
30 changes: 18 additions & 12 deletions src/Entities/Municipality.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function allMunicipalities()
/**
* Get municipalities by district id
*
* @param $districtId
* @return array|mixed|null
* @param int $districtId
* @return array<object>|null
*/
public function getMunicipalitiesByDistrict($districtId)
{
Expand All @@ -66,8 +66,8 @@ public function getMunicipalitiesByDistrict($districtId)
/**
* Get municipalities by category id
*
* @param $categoryId
* @return array
* @param int $categoryId
* @return array<object>
*/
public function getMunicipalityByCategory($categoryId)
{
Expand All @@ -76,6 +76,12 @@ public function getMunicipalityByCategory($categoryId)
}));
}

/**
* Get municipalities by province
*
* @param int $provinceId
* @return array<object>
*/
public function getMunicipalityByProvince($provinceId)
{
$district = new District();
Expand All @@ -90,7 +96,7 @@ public function getMunicipalityByProvince($provinceId)
/**
* Find municipality by id
*
* @param $id
* @param int $id
* @return object|null
*/
public function find($id)
Expand All @@ -103,7 +109,7 @@ public function find($id)
/**
* Get municipality with largest area
*
* @return mixed
* @return object
*/
public function largest()
{
Expand All @@ -121,7 +127,7 @@ public function largest()
/**
* Get municipality with smallest area
*
* @return mixed
* @return object
*/
public function smallest()
{
Expand All @@ -139,8 +145,8 @@ public function smallest()
/**
* Get wards of municipality
*
* @param $id
* @return array
* @param int $id
* @return array<string>
*/
public function wards($id)
{
Expand All @@ -163,10 +169,10 @@ public function wards($id)
/**
* Search Municipalities
*
* @param $key
* @param $value
* @param string $key
* @param string $value
* @param bool $exact
* @return array
* @return array<object>
*/
public function search($key, $value, $exact = false)
{
Expand Down
21 changes: 11 additions & 10 deletions src/Entities/Province.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Province extends BaseEntity
{
/**
* Province constructor.
* @param $lang
* @param string $lang
* @throws LoadingException
*/
public function __construct($lang = 'en')
Expand All @@ -34,7 +34,7 @@ public function __construct($lang = 'en')

/**
* Get list of all provinces
* @return mixed|null
* @return array<object>
*/
public function allProvinces()
{
Expand All @@ -44,7 +44,7 @@ public function allProvinces()
/**
* Find province by id
*
* @param $id
* @param int $id
* @return object|null
*/
public function find($id)
Expand All @@ -56,7 +56,8 @@ public function find($id)

/**
* Get province with largest area
* @return mixed
*
* @return object
*/
public function largest()
{
Expand All @@ -74,7 +75,7 @@ public function largest()
/**
* Get province with smallest area
*
* @return mixed
* @return object
*/
public function smallest()
{
Expand All @@ -92,7 +93,7 @@ public function smallest()
/**
* Get provinces with districts
*
* @return array
* @return array<object>
* @throws LoadingException
*/
public function getProvincesWithDistricts()
Expand All @@ -111,7 +112,7 @@ public function getProvincesWithDistricts()
/**
* Get provinces with districts with municipalities
*
* @return array
* @return array<object>
* @throws LoadingException
*/
public function getProvincesWithDistrictsWithMunicipalities()
Expand Down Expand Up @@ -142,10 +143,10 @@ public function getProvincesWithDistrictsWithMunicipalities()
/**
* Search Provinces
*
* @param $key
* @param $value
* @param string $key
* @param string $value
* @param bool $exact
* @return array
* @return array<object>
*/
public function search($key, $value, $exact = false)
{
Expand Down
16 changes: 8 additions & 8 deletions src/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
class Helper
{
/**
* @var array
* @var array<string>
*/
private static $nepali = ['', '', '', '', '', '', '', '', '', ''];

/**
* @var array
* @var array<string>
*/
private static $english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

/**
* Convert english numeric value to nepali numeric value
*
* @param $value
* @return mixed
* @param string $value
* @return string
*/
public static function numericNepali($value)
public static function numericNepali($value): string
{
for ($i = 0; $i < 10; $i++)
{
Expand All @@ -38,10 +38,10 @@ public static function numericNepali($value)
/**
* Convert nepali numeric value to english numeric value
*
* @param $value
* @return mixed
* @param string $value
* @return string
*/
public static function numericEnglish($value)
public static function numericEnglish($value): string
{
for ($i = 0; $i < 10; $i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Loaders/CategoriesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CategoriesLoader

/**
* CategoriesLoader constructor.
* @param $lang
* @param string $lang
* @throws LoadingException
*/
public function __construct($lang = 'en')
Expand Down
Loading

0 comments on commit c443f95

Please sign in to comment.