Skip to content

Commit

Permalink
Release/1.3.0 (#8)
Browse files Browse the repository at this point in the history
* refactor: Improves strict typing and tests.
  • Loading branch information
gustavofreze authored Oct 8, 2024
1 parent 58e8564 commit d16444a
Show file tree
Hide file tree
Showing 58 changed files with 727 additions and 481 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
- name: Run tests
env:
XDEBUG_MODE: coverage
run: composer unit-test
run: composer tests
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL author="Gustavo Freze" \
org.label-schema.vcs-url="https://github.com/gustavofreze/points-of-interest/blob/main/Dockerfile" \
org.label-schema.schema-version="1.0"

ARG FLYWAY_VERSION=10.10.0
ARG FLYWAY_VERSION=10.19.0

RUN apk --no-cache add curl mysql-client openjdk21-jre tar \
&& mkdir -p /opt/flyway \
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ PWD := $(shell pwd -L)
PHP_IMAGE := gustavofreze/php:8.2
APP_RUN := docker run -u root --rm -it --network=host -v ${PWD}:/app -w /app ${PHP_IMAGE}

FLYWAY_IMAGE := flyway/flyway:10.10.0
FLYWAY_IMAGE := flyway/flyway:10.19.0
FLYWAY_RUN := docker run --rm -v ${PWD}/db/mysql/migrations:/flyway/sql --env-file=config/local.env --link points-of-interest-adm --network=points-of-interest_default ${FLYWAY_IMAGE}
MIGRATE_DB := ${FLYWAY_RUN} -locations=filesystem:/flyway/sql -schemas=poi_adm

.DEFAULT_GOAL := help

.PHONY: start configure test review fix-style show-coverage clean migrate-database clean-database help
.PHONY: start configure test review fix-style show-reports clean migrate-database clean-database help

start: ## Start Docker compose services
@docker-compose up -d --build
Expand All @@ -25,7 +25,7 @@ review: ## Run code review
fix-style: ## Fix code style
@${APP_RUN} composer fix-style

show-coverage: ## Open code coverage reports in browser
show-reports: ## Open code coverage reports in browser
@sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html

migrate-database: ## Run database migrations
Expand All @@ -41,7 +41,7 @@ help: ## Display this help message
@grep -E '^(configure|start|migrate-database|clean-database):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Testing"
@grep -E '^(test|show-coverage):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@grep -E '^(test|show-reports):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Code review "
@grep -E '^(review|fix-style):.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* [Instalação](#installation)
- [Repositório](#repository)
- [Configuração](#configure)
* [Úteis](#useful)
* [FAQ](#faq)

<div id="overview"></div>
Expand Down Expand Up @@ -63,9 +62,9 @@ retornar os seguintes POIs:

URLs de acesso:

| Ambiente | DNS |
|:---------|:---------------------------------------|
| `Local` | http://points-of-interest.localhost:81 |
| Ambiente | DNS |
|:---------|:------------------------------------|
| `Local` | http://points-of-interest.localhost |

### Cadastrar POI

Expand Down
31 changes: 13 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"prefer-stable": true,
"minimum-stability": "stable",
"keywords": [
"backend-br",
"points-of-interest"
],
"authors": [
Expand All @@ -33,44 +34,38 @@
},
"require": {
"php": "^8.2",
"slim/psr7": "^1.6",
"slim/psr7": "^1.7",
"slim/slim": "4.11.0",
"doctrine/dbal": "^3.6",
"respect/validation": "^2.2",
"php-di/slim-bridge": "^3.3",
"tiny-blocks/http": "^3.1",
"tiny-blocks/collection": "^1.1",
"tiny-blocks/serializer": "^3.2",
"tiny-blocks/value-object": "^2.0",
"doctrine/dbal": "^3.9",
"respect/validation": "^2.3",
"php-di/slim-bridge": "^3.4",
"tiny-blocks/http": "^3",
"tiny-blocks/collection": "^1",
"tiny-blocks/serializer": "^3",
"tiny-blocks/value-object": "^3",
"ext-pdo": "*"
},
"require-dev": {
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1",
"phpunit/phpunit": "^11",
"infection/infection": "^0.29",
"squizlabs/php_codesniffer": "^3.10"
},
"scripts": {
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --exclude --ignore-violations-on-exit",
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
"test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests",
"test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4",
"test-no-coverage": "phpunit --no-coverage",
"test-mutation-no-coverage": "infection --only-covered --min-msi=100 --threads=4",
"review": [
"@phpcs",
"@phpmd"
"@phpmd",
"@phpstan"
],
"tests": [
"@test",
"@test-mutation"
],
"tests-no-coverage": [
"@test-no-coverage",
"@test-mutation-no-coverage"
],
"tests-file-no-coverage": [
"@test-no-coverage"
]
}
}
4 changes: 3 additions & 1 deletion config/nginx/nginx.conf → config/nginx/site.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
server {
listen 80;

root /var/www/html/public;
index index.php index.html;

Expand All @@ -19,4 +21,4 @@ server {
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
}
}
}
23 changes: 14 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
points-of-interest:
build:
Expand Down Expand Up @@ -29,29 +27,36 @@ services:

nginx:
container_name: nginx
image: nginx:1.23.0
image: nginx:1.27-alpine
restart: always
depends_on:
- points-of-interest
volumes:
- ./public:/var/www/html
- ./config/nginx/nginx.conf:/etc/nginx/conf.d/site.conf
- ./config/nginx/site.conf:/etc/nginx/conf.d/site.conf
labels:
- "traefik.enable=true"
- "traefik.http.routers.nginx.entrypoints=http"
- "traefik.http.routers.nginx.rule=Host(`points-of-interest.localhost`)"

reverse-proxy:
container_name: reverse-proxy
image: traefik:v2.8.1
image: traefik:3.2
restart: always
container_name: reverse-proxy
command:
- "--log.level=INFO"
- "--accesslog=true"
- "--api.insecure=true"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--entrypoints.http.address=:80"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.http.address=:81"
ports:
- "81:81"
- "80:80"
- "8080:8080"
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik.localhost`)"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- /var/run/docker.sock:/var/run/docker.sock:ro
9 changes: 3 additions & 6 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
},
"mutators": {
"@default": true,
"ArrayItem": false,
"RoundingFamily": false,
"UnwrapArrayMap": false,
"PublicVisibility": false,
"ArrayItemRemoval": false,
"IncrementInteger": false,
"CastInt": false,
"CastArray": false,
"CastString": false,
"MethodCallRemoval": false
},
"phpUnit": {
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
paths:
- src
level: 9
tmpDir: report/phpstan
ignoreErrors:
- '#Parameter ...#'
- '#with generic#'
- '#Cannot cast mixed#'
- '#extends generic class#'
- '#no value type specified in iterable type array#'
reportUnmatchedIgnoredErrors: false
2 changes: 2 additions & 0 deletions src/Domain/Exceptions/NameCannotBeEmpty.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Exceptions;

use DomainException;
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Exceptions/NegativeCoordinate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Exceptions;

use DomainException;
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Exceptions/NegativeDistance.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Exceptions;

use DomainException;
Expand Down
8 changes: 5 additions & 3 deletions src/Domain/Models/Coordinate.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Models;

use PointsOfInterest\Domain\Exceptions\NegativeCoordinate;
use TinyBlocks\Vo\ValueObject;
use TinyBlocks\Vo\ValueObjectAdapter;
use TinyBlocks\Vo\ValueObjectBehavior;

final readonly class Coordinate implements ValueObject
{
use ValueObjectAdapter;
use ValueObjectBehavior;

public function __construct(public int $value)
{
Expand All @@ -34,6 +36,6 @@ public function squared(): Coordinate

public function squareRoot(): Coordinate
{
return new Coordinate(value: round(sqrt($this->value)));
return new Coordinate(value: (int)round(sqrt($this->value)));
}
}
6 changes: 4 additions & 2 deletions src/Domain/Models/Distance.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Models;

use PointsOfInterest\Domain\Exceptions\NegativeDistance;
use TinyBlocks\Vo\ValueObject;
use TinyBlocks\Vo\ValueObjectAdapter;
use TinyBlocks\Vo\ValueObjectBehavior;

final readonly class Distance implements ValueObject
{
use ValueObjectAdapter;
use ValueObjectBehavior;

public function __construct(public int $value)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Domain/Models/Name.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Models;

use PointsOfInterest\Domain\Exceptions\NameCannotBeEmpty;
use TinyBlocks\Vo\ValueObject;
use TinyBlocks\Vo\ValueObjectAdapter;
use TinyBlocks\Vo\ValueObjectBehavior;

final readonly class Name implements ValueObject
{
use ValueObjectAdapter;
use ValueObjectBehavior;

public function __construct(public string $value)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Models/PointOfInterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace PointsOfInterest\Domain\Models;

use TinyBlocks\Vo\ValueObject;
use TinyBlocks\Vo\ValueObjectAdapter;
use TinyBlocks\Vo\ValueObjectBehavior;

final readonly class PointOfInterest implements ValueObject
{
use ValueObjectAdapter;
use ValueObjectBehavior;

public function __construct(public Name $name, public Coordinate $xCoordinate, public Coordinate $yCoordinate)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Models/PointsOfInterest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Models;

use TinyBlocks\Collection\Collection;
Expand Down
6 changes: 4 additions & 2 deletions src/Domain/Models/ReferencePoint.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Models;

use TinyBlocks\Vo\ValueObject;
use TinyBlocks\Vo\ValueObjectAdapter;
use TinyBlocks\Vo\ValueObjectBehavior;

final readonly class ReferencePoint implements ValueObject
{
use ValueObjectAdapter;
use ValueObjectBehavior;

public function __construct(public Coordinate $xCoordinate, public Coordinate $yCoordinate)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Ports/Outbound/Points.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace PointsOfInterest\Domain\Ports\Outbound;

use PointsOfInterest\Domain\Models\PointOfInterest;
Expand Down
Loading

0 comments on commit d16444a

Please sign in to comment.