Skip to content

Commit 03759a1

Browse files
authored
Merge pull request #40 from sagautam5/add-php-stan
Add php stan
2 parents d2a6096 + 4989650 commit 03759a1

21 files changed

+255
-120
lines changed

.github/workflows/ci.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ jobs:
2020
run: composer install --prefer-dist --no-progress --no-interaction
2121

2222
- name: Run PHPUnit tests
23-
run: vendor/bin/phpunit
23+
run: vendor/bin/phpunit
24+
25+
- name: Run PhpStan Analyse Code
26+
run: vendor/bin/phpstan analyse --level=8 src
27+
28+
- name: Run PhpStan Analyse Code
29+
run: vendor/bin/phpstan analyse --level=5 tests

CONTRIBUTING.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,33 @@ Before filing an issue:
3434
Before submitting a pull request:
3535
- Fetch the phpunit testing dependency by executing following command on root of the project.
3636
```sh
37-
composer update
38-
```- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
37+
composer install
38+
```
39+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
3940

4041
- Create and test the feature/issue and make sure it doesn't affect codebase by running full tests by executing following console command for two different environment variables.
4142

4243
Set APP_LANG to np and en respectively and run following command for each value of language.
4344
```sh
44-
vendor/bin/phpunit
45+
vendor/bin/phpunit
46+
```
47+
- Make sure contribution align with phpstan standards. You can run following command to ensure this.
48+
```sh
49+
vendor/bin/phpunit analyse --level=8 src/
50+
vendor/bin/phpunit analyse --level=5 tests/
51+
4552
```
4653
<!-- - Make sure unit tests are passed on pipeline after your updates. -->
4754
- Check the codebase to ensure that your feature doesn't already exist.
4855
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
4956
<!-- - Send pull request to dev branch only. -->
5057

58+
## Docker Option
59+
60+
We have recently added workflow to setup this package with Docker Desktop. You can find guidelines in the following document.
61+
62+
- [Local setup with Docker](./docs/docker/setup.md)
63+
5164
## Requirements
5265

5366
If the project maintainer has any additional requirements, you will find them listed here.
@@ -61,4 +74,4 @@ If the project maintainer has any additional requirements, you will find them li
6174

6275
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
6376

64-
**Happy coding**!
77+
**Happy coding** !

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM sagautam5/localstates_7.4:v1.0
1+
FROM sagautam5/localstates_8.3:v1.0

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Image Source: [Wikipedia(Administrative divisions of Nepal)](https://simple.wiki
3434
- 7.3
3535
- 7.4
3636

37-
Current **dev-master** has been tested on following php versions.
37+
Current **v2.0.0** has been tested on following php versions.
3838

3939
- 8.0
4040
- 8.1
@@ -60,7 +60,11 @@ Example: http://127.0.0.1/local-states-nepal/demo
6060
Demo Video:
6161

6262
https://www.loom.com/share/a8c3d825a9ee41a9817b24645453e979
63+
64+
Additionally, you can setup with Docker and visit [localstates.test](http://localstates.test) to view the demo. Here is guideline for setting up with Docker.
6365

66+
[Local setup with Docker](./docs/docker/setup.md)
67+
6468
## Support
6569

6670
Currently, This library supports following two languages.

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"php": ">=8.0"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "9.6.*"
16+
"phpunit/phpunit": "9.6.*",
17+
"phpstan/phpstan": "^1.10"
1718
},
1819
"autoload": {
1920
"psr-4": {

composer.lock

+63-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docker/setup.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Local setup with Docker
2+
3+
In order to make contribution and bug reporting easier, we have recently Dockerized this package so that contributors can setup, run tests and view demo locally in just a few steps.
4+
You can clone this repository on your computer. Assuming you have docker desktop configured in your computer, you just have to run the following command:
5+
6+
7+
If Docker Desktop is not installed on your computer, you can setup Docker Desktop from th official docs [Docker Desktop](https://docs.docker.com/desktop/)
8+
9+
10+
docker compose up -d
11+
12+
13+
On successful execution of the above command, you will have a Docker container `localstates` and `nginx` configuration too. You can access demo by visiting the following url
14+
15+
[localstates.test](http://localstates.test)
16+
17+
With the following command, we can enter our container.
18+
19+
docker compose exec localstates bash
20+
21+
In order to verify contribution align with php unit tests and php stan standards, you have to execute following commands
22+
23+
vendor/bin/phpunit
24+
25+
vendor/bin/phpstan analyse --level=8 src/
26+
27+
vendor/bin/phpstan analyse --level=5 tests/
28+
29+
## Docker Images
30+
31+
We have uploaded docker images for various version of the php. If you find bug related to specific version of the php, then you can report the bug or contribute on bug
32+
fixing by using respective docker image in your setup.
33+
34+
In the `Dockerfile`, you can update the following line with an specific Docker image.
35+
36+
FROM sagautam5/localstates_8.3:v1.0
37+
38+
As you can see,the above image is for PHP 8.3. We have the following Docker images for the respective PHP versions.
39+
40+
- [sagautam5/localstates_7.1:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.1)
41+
- [sagautam5/localstates_7.2:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.2)
42+
- [sagautam5/localstates_7.3:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.3)
43+
- [sagautam5/localstates_7.4:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.4)
44+
- [sagautam5/localstates_8.0:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.0)
45+
- [sagautam5/localstates_8.1:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.1)
46+
- [sagautam5/localstates_8.2:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.2)
47+
- [sagautam5/localstates_8.3:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.3)
48+
49+
After updating `Dockerfile`, you have to recreate the container with the following command:
50+
51+
docker compose up -d --force-recreate
52+
53+
Now, it's ready with an specific version of PHP

src/Entities/BaseEntity.php

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<?php
22

3-
43
namespace Sagautam5\LocalStateNepal\Entities;
54

6-
75
abstract class BaseEntity
86
{
97
/**
10-
* @var
8+
* @var array<object>
119
*/
1210
protected $items;
1311

1412
/**
15-
* @var
13+
* @var array<string>
1614
*/
1715
protected $keys;
1816

@@ -24,13 +22,13 @@ abstract class BaseEntity
2422
/**
2523
* Filter data by key value pair
2624
*
27-
* @param $key
28-
* @param $value
29-
* @param $data
25+
* @param string $key
26+
* @param string $value
27+
* @param array<object> $data
3028
* @param bool $exact
31-
* @return array
29+
* @return array<object>
3230
*/
33-
protected function filter($key, $value, $data, $exact = false)
31+
protected function filter($key, $value, $data, $exact = false): array
3432
{
3533
return array_values(array_filter($data, function ($item) use ($key, $value, $exact) {
3634
return ($exact ? ($item->$key == $value ? true:false) :(is_int(strpos($item->$key, $value)) ? true:false));
@@ -42,27 +40,27 @@ protected function filter($key, $value, $data, $exact = false)
4240
*
4341
* @return string
4442
*/
45-
public function getLanguage()
43+
public function getLanguage(): string
4644
{
4745
return $this->lang;
4846
}
4947

5048
/**
51-
* @return mixed
49+
* @return array<string>
5250
*/
53-
public function getKeys()
51+
public function getKeys(): array
5452
{
5553
return $this->keys;
5654
}
5755

5856
/**
5957
* Recursive Search Data
6058
*
61-
* @param $params
62-
* @param array $items
63-
* @return array|mixed
59+
* @param array<mixed> $params
60+
* @param array<object> $items
61+
* @return array<object>
6462
*/
65-
public function recursiveSearch($params, $items = [])
63+
public function recursiveSearch($params, $items = []): array
6664
{
6765
$items = $items ? $items : $this->items;
6866

@@ -78,9 +76,9 @@ public function recursiveSearch($params, $items = [])
7876
*
7977
* @param string $key
8078
* @param int $order
81-
* @return mixed
79+
* @return array<mixed>
8280
*/
83-
public function sortBy($key = 'name', $order = SORT_ASC)
81+
public function sortBy($key = 'name', $order = SORT_ASC): array
8482
{
8583
$keys = array_column($this->items, $key);
8684

src/Entities/Category.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public function allCategories()
4444
/**
4545
* Find category by id
4646
*
47-
* @param $id
48-
* @return false|int|string
47+
* @param int $id
48+
* @return object|null
4949
*/
5050
public function find($id)
5151
{
@@ -57,8 +57,8 @@ public function find($id)
5757
/**
5858
* Find category by short code
5959
*
60-
* @param $short_code
61-
* @return |null
60+
* @param string $short_code
61+
* @return object|null
6262
*/
6363
public function findByShortCode($short_code)
6464
{
@@ -70,10 +70,10 @@ public function findByShortCode($short_code)
7070
/**
7171
* Search Categories
7272
*
73-
* @param $key
74-
* @param $value
73+
* @param string $key
74+
* @param string $value
7575
* @param bool $exact
76-
* @return array
76+
* @return array<object>
7777
*/
7878
public function search($key, $value, $exact = false)
7979
{

0 commit comments

Comments
 (0)