Skip to content

Commit 5b70498

Browse files
committed
chore: scaffold project with initial files
0 parents  commit 5b70498

26 files changed

+6782
-0
lines changed

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/.github export-ignore
2+
/.hooks export-ignore
3+
/coverage export-ignore
4+
/sandbox export-ignore
5+
/tests export-ignore
6+
.gitattributes export-ignore
7+
.gitignore export-ignore
8+
.phpcs.cache export-ignore
9+
.phpunit.result.cache export-ignore
10+
compose.yml export-ignore
11+
Dockerfile export-ignore
12+
Makefile export-ignore
13+
phpcs.xml export-ignore
14+
phpstan.neon export-ignore
15+
phpunit.xml export-ignore

.github/ci/pr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
const REGEX = '/^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test): (?!\b\w+(s|ed|ing)\b)[a-z].+/u';
7+
$title = $argv[1] ?? '';
8+
9+
echo sprintf('Title: %s%s', $title, PHP_EOL);
10+
echo sprintf('RegEx: %s%s', REGEX, PHP_EOL);
11+
12+
if (!preg_match(REGEX, $title)) {
13+
fwrite(STDERR, "Error: title does not follow the required pattern.\n");
14+
exit(1);
15+
}
16+
17+
echo "Title is valid.\n";
18+
exit(0);

.github/workflows/base.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
checks:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: checkout repo
15+
uses: actions/checkout@v4
16+
17+
- name: cache dependencies
18+
uses: actions/cache@v4
19+
with:
20+
path: ./vendor
21+
key: ${{ github.sha }}
22+
23+
- name: build app
24+
run: make start
25+
26+
- name: validate dependencies
27+
run: make composer c=validate
28+
29+
- name: install dependencies
30+
run: make composer c=install
31+
32+
- name: audit dependencies
33+
run: make composer c=audit
34+
35+
- name: run lint
36+
run: make lint
37+
38+
- name: run tests
39+
run: make test-cov
40+
41+
- name: upload coverage
42+
uses: codecov/codecov-action@v5
43+
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}
45+
fail_ci_if_error: true
46+
47+
- name: upload test results
48+
if: ${{ !cancelled() }}
49+
uses: codecov/test-results-action@v1
50+
with:
51+
file: ./coverage/junit.xml
52+
token: ${{ secrets.CODECOV_TOKEN }}
53+
fail_ci_if_error: true

.github/workflows/pr.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
types: [ opened, edited, reopened, synchronize ]
6+
7+
jobs:
8+
checks:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: checkout repo
13+
uses: actions/checkout@v4
14+
15+
- name: cache vendor folder
16+
uses: actions/cache@v4
17+
with:
18+
path: ./vendor
19+
key: ${{ github.sha }}
20+
21+
- name: build app
22+
run: make start
23+
24+
- name: validate pull request
25+
run: |
26+
make php args=".github/ci/pr '${{ github.event.pull_request.title }}'"

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
###> IDEs ###
2+
.idea
3+
###< IDEs ###
4+
5+
###> composer ###
6+
vendor
7+
###< composer ###
8+
9+
###> phpunit/phpunit ###
10+
coverage
11+
.phpunit.result.cache
12+
###< phpunit/phpunit ###
13+
14+
###> squizlabs/php_codesniffer ###
15+
.phpcs.cache
16+
###< squizlabs/php_codesniffer ###

.hooks/pre-commit

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
echo "###> Pre commit hook started"
4+
5+
PHP_CS="vendor/bin/phpcs"
6+
PHP_STAN="vendor/bin/phpstan"
7+
HAS_PHP_CS=false
8+
HAS_PHP_STAN=false
9+
10+
CHANGED_PHP_FILES=$(git diff --name-only --diff-filter=d | grep \\.php)
11+
12+
if [ -x $PHP_CS ]; then
13+
HAS_PHP_CS=true
14+
fi
15+
16+
if [ -x $PHP_STAN ]; then
17+
HAS_PHP_STAN=true
18+
fi
19+
20+
if $HAS_PHP_CS; then
21+
echo "Running PHPCS..."
22+
for FILE in $CHANGED_PHP_FILES
23+
do
24+
docker-compose exec app $PHP_CS $FILE
25+
if [ $? != 0 ]; then
26+
exit 1;
27+
fi
28+
done
29+
else
30+
echo "PHPCS not installed."
31+
fi
32+
33+
if $HAS_PHP_STAN; then
34+
echo "Running PHPStan..."
35+
ERRORS=$(docker-compose exec -T app $PHP_STAN analyse --error-format=raw $CHANGED_PHP_FILES 2> /dev/null);
36+
if [ "$ERRORS" != "" ]; then
37+
echo $ERRORS
38+
exit 1;
39+
fi
40+
else
41+
echo "PHPStan not installed."
42+
fi
43+
44+
echo "###< Pre commit hook finished"

CONTRIBUTING.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Contributing
2+
3+
Contributors are always welcome! We want to make contributing to this project as easy and transparent as possible, whether it's:
4+
5+
- Reporting a bug
6+
- Discussing the current state of the code
7+
- Submitting a fix
8+
- Proposing new features
9+
- Becoming a maintainer
10+
11+
## All code changes happen through pull requests
12+
13+
Pull requests are the best way to propose changes to the codebase. The ideal way to create a PR is:
14+
15+
1. Fork the repo and create your branch from the main version branch.
16+
2. If you've added code that should be tested, add tests.
17+
3. Ensure the test suite passes.
18+
4. Make sure your code lints.
19+
5. Issue that pull request!
20+
21+
## Any contributions you make will be under the MIT Software License
22+
23+
In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.
24+
25+
## Report bugs using issues
26+
27+
We use GitHub issues to track public bugs. Report a bug by opening a new issue. It's that simple!
28+
29+
## Write bug reports with detail, background, and sample code
30+
31+
**Great Bug Reports** tend to have:
32+
33+
- A quick summary and/or background
34+
- Steps to reproduce
35+
- Be specific!
36+
- Give sample code if you can.
37+
- What you expected would happen
38+
- What actually happens
39+
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
40+
41+
[This is an example](https://stackoverflow.com/q/12488905/180626) of a bug report that is just enough.
42+
43+
## Use a consistent coding style
44+
45+
Having a code well styled and organized is one of our top priorities. So we ask to follow the standards already in the code base, always based on [PSRs](https://www.php-fig.org/psr/).
46+
47+
## License
48+
49+
By contributing, you agree that your contributions will be licensed under its MIT License.
50+
51+
## References
52+
53+
This document was adapted from [these open-source contribution guidelines](https://gist.github.com/briandk/3d2e8b3ec8daf5a27a62).

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM php:8.3-cli-alpine
2+
3+
WORKDIR /app
4+
5+
RUN apk add --no-cache \
6+
git \
7+
unzip \
8+
libzip-dev
9+
10+
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS linux-headers \
11+
&& pecl install xdebug \
12+
&& docker-php-ext-enable xdebug \
13+
&& apk del -f .build-deps
14+
15+
COPY --from=composer /usr/bin/composer /usr/bin/composer
16+
17+
RUN git config --global --add safe.directory /app
18+
19+
CMD ["tail", "-f", "/dev/null"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Eduardo Marques
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Executables (host)
2+
DOCKER_COMPOSE = docker compose
3+
4+
# Docker containers
5+
APP_CONTAINER = $(DOCKER_COMPOSE) exec app
6+
7+
# Executables
8+
PHP = $(APP_CONTAINER) php
9+
COMPOSER = $(APP_CONTAINER) composer
10+
11+
# Misc
12+
.DEFAULT_GOAL = help
13+
14+
## 👷 Makefile
15+
help: ## Outputs this help screen
16+
@grep '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed 's/\[32m##/[33m/'
17+
18+
## 🐳 Docker
19+
build: ## Builds the Docker images
20+
@$(DOCKER_COMPOSE) --progress=plain build --pull --no-cache
21+
22+
up: ## Start the Docker cluster
23+
@$(DOCKER_COMPOSE) up
24+
25+
start: ## Start the Docker cluster in detached mode (no logs)
26+
@$(DOCKER_COMPOSE) up --detach
27+
28+
stop: ## Stop the Docker cluster
29+
@$(DOCKER_COMPOSE) stop
30+
31+
down: ## Stop and remove the Docker cluster
32+
@$(DOCKER_COMPOSE) down --remove-orphans --volumes
33+
34+
logs: ## Show live logs
35+
@$(DOCKER_COMPOSE) logs --tail=0 --follow
36+
37+
ps: ## Show containers' statuses
38+
@$(DOCKER_COMPOSE) ps
39+
40+
sh: ## Connect to the app container
41+
@$(APP_CONTAINER) sh
42+
43+
php: ## Run PHP on app container, pass the parameter "args=" to append arguments (example: make php args='script.php')
44+
@$(PHP) ${args}
45+
46+
## ✅ Code Quality
47+
hooks: ## Enable Git hooks
48+
git config --local core.hooksPath .hooks/
49+
50+
phpcs: ## Run PHP Code Sniffer
51+
@$(APP_CONTAINER) vendor/bin/phpcs
52+
53+
phpcs-fix: ## Run PHP Code Sniffer (fix)
54+
@$(APP_CONTAINER) vendor/bin/phpcbf
55+
56+
phpstan: ## Run PHPStan
57+
@$(APP_CONTAINER) vendor/bin/phpstan
58+
59+
lint: phpcs phpstan ## Run PHP Code Sniffer and PHPStan
60+
61+
test: ## Run all tests, pass the parameter "args=" to append arguments (example: make test args='--filter=file.php')
62+
@$(DOCKER_COMPOSE) exec app vendor/bin/phpunit --testdox ${args}
63+
64+
test-cov: ## Run all tests and generate coverage report
65+
@$(DOCKER_COMPOSE) exec -e XDEBUG_MODE=coverage app vendor/bin/phpunit --testdox --coverage-clover coverage/clover/clover.xml --coverage-html coverage/html --log-junit coverage/junit.xml
66+
67+
cov: test-cov cov-report ## Generate and open test coverage report
68+
69+
cov-report: ## Open test coverage report
70+
open coverage/html/index.html
71+
72+
## 🧙 Composer
73+
composer: ## Run Composer, pass the parameter "c=" to run a given command (example: make composer c='req vendor/package')
74+
@$(COMPOSER) $(c)

0 commit comments

Comments
 (0)