Skip to content

Commit

Permalink
Merge pull request #40 from sagautam5/add-php-stan
Browse files Browse the repository at this point in the history
Add php stan
  • Loading branch information
sagautam5 authored Apr 28, 2024
2 parents d2a6096 + 4989650 commit 03759a1
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 120 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ jobs:
run: composer install --prefer-dist --no-progress --no-interaction

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

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

- name: Run PhpStan Analyse Code
run: vendor/bin/phpstan analyse --level=5 tests
21 changes: 17 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,33 @@ Before filing an issue:
Before submitting a pull request:
- Fetch the phpunit testing dependency by executing following command on root of the project.
```sh
composer update
```- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
composer install
```
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.

- 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.

Set APP_LANG to np and en respectively and run following command for each value of language.
```sh
vendor/bin/phpunit
vendor/bin/phpunit
```
- Make sure contribution align with phpstan standards. You can run following command to ensure this.
```sh
vendor/bin/phpunit analyse --level=8 src/
vendor/bin/phpunit analyse --level=5 tests/

```
<!-- - Make sure unit tests are passed on pipeline after your updates. -->
- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
<!-- - Send pull request to dev branch only. -->

## Docker Option

We have recently added workflow to setup this package with Docker Desktop. You can find guidelines in the following document.

- [Local setup with Docker](./docs/docker/setup.md)

## Requirements

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

- **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.

**Happy coding**!
**Happy coding** !
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM sagautam5/localstates_7.4:v1.0
FROM sagautam5/localstates_8.3:v1.0
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Image Source: [Wikipedia(Administrative divisions of Nepal)](https://simple.wiki
- 7.3
- 7.4

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

- 8.0
- 8.1
Expand All @@ -60,7 +60,11 @@ Example: http://127.0.0.1/local-states-nepal/demo
Demo Video:

https://www.loom.com/share/a8c3d825a9ee41a9817b24645453e979

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.

[Local setup with Docker](./docs/docker/setup.md)

## Support

Currently, This library supports following two languages.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "9.6.*"
"phpunit/phpunit": "9.6.*",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
64 changes: 63 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions docs/docker/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Local setup with Docker

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.
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:


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/)


docker compose up -d


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

[localstates.test](http://localstates.test)

With the following command, we can enter our container.

docker compose exec localstates bash

In order to verify contribution align with php unit tests and php stan standards, you have to execute following commands

vendor/bin/phpunit

vendor/bin/phpstan analyse --level=8 src/

vendor/bin/phpstan analyse --level=5 tests/

## Docker Images

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
fixing by using respective docker image in your setup.

In the `Dockerfile`, you can update the following line with an specific Docker image.

FROM sagautam5/localstates_8.3:v1.0

As you can see,the above image is for PHP 8.3. We have the following Docker images for the respective PHP versions.

- [sagautam5/localstates_7.1:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.1)
- [sagautam5/localstates_7.2:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.2)
- [sagautam5/localstates_7.3:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.3)
- [sagautam5/localstates_7.4:v1.0](https://hub.docker.com/r/sagautam5/localstates_7.4)
- [sagautam5/localstates_8.0:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.0)
- [sagautam5/localstates_8.1:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.1)
- [sagautam5/localstates_8.2:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.2)
- [sagautam5/localstates_8.3:v1.0](https://hub.docker.com/r/sagautam5/localstates_8.3)

After updating `Dockerfile`, you have to recreate the container with the following command:

docker compose up -d --force-recreate

Now, it's ready with an specific version of PHP
34 changes: 16 additions & 18 deletions src/Entities/BaseEntity.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php


namespace Sagautam5\LocalStateNepal\Entities;


abstract class BaseEntity
{
/**
* @var
* @var array<object>
*/
protected $items;

/**
* @var
* @var array<string>
*/
protected $keys;

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
14 changes: 7 additions & 7 deletions src/Entities/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function allCategories()
/**
* Find category by id
*
* @param $id
* @return false|int|string
* @param int $id
* @return object|null
*/
public function find($id)
{
Expand All @@ -57,8 +57,8 @@ public function find($id)
/**
* Find category by short code
*
* @param $short_code
* @return |null
* @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
Loading

0 comments on commit 03759a1

Please sign in to comment.