Skip to content

Commit 2300c97

Browse files
committed
Scaffold
1 parent 0c1660a commit 2300c97

File tree

26 files changed

+253
-8672
lines changed

26 files changed

+253
-8672
lines changed

.devcontainer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dockerComposeFile": "compose.yaml",
3+
"service": "php",
4+
"workspaceFolder": "/workspace"
5+
}

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Put env variables defaults here
2+
# Override locally in gitignored .env.local
3+
PHP_IMAGE_VERSION=8.2

.github/workflows/check.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Check
2+
3+
on:
4+
workflow_dispatch: ~
5+
push:
6+
branches: [main, '*.*.x']
7+
pull_request: ~
8+
9+
concurrency:
10+
group: check-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
code-style:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
- run: make fixer-check rector-check
19+
20+
composer:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v6
24+
- run: make composer-validate composer-normalize-check deps-analyze
25+
26+
phpstan:
27+
runs-on: ubuntu-latest
28+
strategy: &strategy
29+
fail-fast: false
30+
matrix:
31+
php: [ 8.2, 8.3, 8.4, 8.5 ]
32+
deps: [ lowest, highest ]
33+
steps:
34+
- uses: actions/checkout@v6
35+
- run: PHP_IMAGE_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} phpstan
36+
37+
test:
38+
runs-on: ubuntu-latest
39+
strategy: *strategy
40+
steps:
41+
- uses: actions/checkout@v6
42+
- run: PHP_IMAGE_VERSION=${{ matrix.php }} make install-${{ matrix.deps }} test
43+
44+
# infect:
45+
# runs-on: ubuntu-latest
46+
# steps:
47+
# - uses: actions/checkout@v6
48+
# - run: make infect

.github/workflows/check.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/tools/**/vendor/
21
/var/
32
/vendor/
3+
/.env.local
44
/.php-cs-fixer.php
5+
/compose.override.yaml
56
/phpstan.neon
67
/phpunit.xml
7-
/psalm.xml

Makefile

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
SHELL := /bin/bash
2+
3+
DOCKER ?= docker
4+
DOCKER_COMPOSE ?= $(DOCKER) compose $(shell test -f .env.local && echo '--env-file .env --env-file .env.local')
5+
export CONTAINER_USER ?= $(shell id -u):$(shell id -g)
6+
7+
RUN ?= $(if $(INSIDE_DEVCONTAINER),,$(DOCKER_COMPOSE) run --rm php)
8+
COMPOSER ?= $(RUN) composer
9+
10+
##
11+
## Project
12+
## -----
13+
14+
var:
15+
mkdir var
16+
17+
vendor: composer.json $(wildcard composer.lock)
18+
@if [ -f vendor/.lowest ]; then $(MAKE) install-lowest; else $(MAKE) install-highest; fi
19+
20+
i: install-highest
21+
install-highest: ## Install highest Composer dependencies
22+
$(COMPOSER) install
23+
@rm -f vendor/.lowest
24+
@touch vendor
25+
.PHONY: i install-highest
26+
27+
install-lowest: ## Install lowest Composer dependencies
28+
$(COMPOSER) update --prefer-lowest --prefer-stable
29+
@touch vendor/.lowest
30+
@touch vendor
31+
.PHONY: install-lowest
32+
33+
up: ## Docker compose up
34+
$(DOCKER_COMPOSE) up --remove-orphans --build --detach $(ARGS)
35+
.PHONY: up
36+
37+
down: ## Docker compose down
38+
$(DOCKER_COMPOSE) down --remove-orphans $(ARGS)
39+
.PHONY: down
40+
41+
dc: docker-compose
42+
docker-compose: ## Run docker compose command: `make dc CMD=start`
43+
$(DOCKER_COMPOSE) $(CMD)
44+
.PHONY: dc docker-compose
45+
46+
c: composer
47+
composer: ## Run Composer command: `make c CMD=start`
48+
$(COMPOSER) $(CMD)
49+
.PHONY: c composer
50+
51+
run: ## Run a command using the php container: `make run CMD='php --version'`
52+
$(RUN) $(CMD)
53+
.PHONY: run
54+
55+
t: terminal
56+
terminal: var ## Start a terminal inside the php container
57+
@$(if $(INSIDE_CONTAINER),echo 'Already inside docker container.'; exit 1,)
58+
$(DOCKER_COMPOSE) run --rm $(ARGS) php bash
59+
.PHONY: t terminal
60+
61+
rescaffold:
62+
$(DOCKER) run \
63+
--volume .:/project \
64+
--user $(CONTAINER_USER) \
65+
--interactive --tty --rm \
66+
--pull always \
67+
ghcr.io/phpyh/scaffolder:latest \
68+
--user-name-default '$(shell git config user.name 2>/dev/null || whoami 2>/dev/null)' \
69+
--user-email-default '$(shell git config user.email 2>/dev/null)' \
70+
--package-project-default '$(shell basename $$(pwd))'
71+
git add --all 2>/dev/null || true
72+
.PHONY: rescaffold
73+
74+
##
75+
## Tools
76+
## -----
77+
78+
fixer: var ## Fix code style using PHP-CS-Fixer
79+
$(RUN) php-cs-fixer fix --diff --verbose $(ARGS)
80+
.PHONY: fixer
81+
82+
fixer-check: var ## Check code style using PHP-CS-Fixer
83+
$(RUN) php-cs-fixer fix --diff --verbose --dry-run $(ARGS)
84+
.PHONY: fixer-check
85+
86+
rector: var ## Fix code style using Rector
87+
$(RUN) rector process $(ARGS)
88+
.PHONY: rector
89+
90+
rector-check: var ## Check code style using Rector
91+
$(RUN) rector process --dry-run $(ARGS)
92+
.PHONY: rector-check
93+
94+
phpstan: var vendor ## Analyze code using PHPStan
95+
$(RUN) phpstan analyze --memory-limit=1G $(ARGS)
96+
.PHONY: phpstan
97+
98+
test: var vendor up ## Run tests using PHPUnit
99+
$(RUN) vendor/bin/phpunit $(ARGS)
100+
.PHONY: test
101+
102+
infect: var vendor up ## Run mutation tests using Infection
103+
$(RUN) infection --show-mutations $(ARGS)
104+
.PHONY: infect
105+
106+
deps-analyze: vendor ## Analyze project dependencies using Composer dependency analyser
107+
$(RUN) composer-dependency-analyser $(ARGS)
108+
.PHONY: deps-analyze
109+
110+
composer-validate: ## Validate composer.json
111+
$(COMPOSER) validate $(ARGS)
112+
.PHONY: composer-validate
113+
114+
composer-normalize: ## Normalize composer.json
115+
$(COMPOSER) normalize --no-check-lock --no-update-lock --diff $(ARGS)
116+
.PHONY: composer-normalize
117+
118+
composer-normalize-check: ## Check that composer.json is normalized
119+
$(COMPOSER) normalize --diff --dry-run $(ARGS)
120+
.PHONY: composer-normalize-check
121+
122+
fix: fixer rector composer-normalize ## Run all fixing recipes
123+
.PHONY: fix
124+
125+
check: fixer-check rector-check composer-validate composer-normalize-check deps-analyze phpstan test ## Run all project checks
126+
.PHONY: check
127+
128+
# -----------------------
129+
130+
help:
131+
@awk ' \
132+
BEGIN {RS=""; FS="\n"} \
133+
function printCommand(line) { \
134+
split(line, command, ":.*?## "); \
135+
printf "\033[32m%-28s\033[0m %s\n", command[1], command[2]; \
136+
} \
137+
/^[0-9a-zA-Z_-]+: [0-9a-zA-Z_-]+\n[0-9a-zA-Z_-]+: .*?##.*$$/ { \
138+
split($$1, alias, ": "); \
139+
sub(alias[2] ":", alias[2] " (" alias[1] "):", $$2); \
140+
printCommand($$2); \
141+
next; \
142+
} \
143+
$$1 ~ /^[0-9a-zA-Z_-]+: .*?##/ { \
144+
printCommand($$1); \
145+
next; \
146+
} \
147+
/^##(\n##.*)+$$/ { \
148+
gsub("## ?", "\033[33m", $$0); \
149+
print $$0; \
150+
next; \
151+
} \
152+
' $(MAKEFILE_LIST) && printf "\033[0m"
153+
.PHONY: help
154+
155+
.DEFAULT_GOAL := help

compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
php:
3+
# noinspection ComposeUnknownValues
4+
image: ghcr.io/phpyh/php:${PHP_IMAGE_VERSION:?Make sure `PHP_IMAGE_VERSION` is declared in `.env`}
5+
user: ${CONTAINER_USER:-}
6+
environment:
7+
INSIDE_DEVCONTAINER: true
8+
HISTFILE: /workspace/var/.docker_history
9+
COMPOSER_CACHE_DIR: /workspace/var/.composer_cache
10+
tty: true
11+
volumes:
12+
- .:/workspace:cached
13+
working_dir: /workspace

composer.json

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"symfony/polyfill-php83": "^1.33"
1919
},
2020
"require-dev": {
21-
"bamarni/composer-bin-plugin": "^1.8.2",
2221
"nette/php-generator": "^4.2.0",
2322
"phpunit/phpunit": "^11.5.42",
2423
"symfony/finder": "^7.3.5",
@@ -40,36 +39,7 @@
4039
}
4140
},
4241
"config": {
43-
"allow-plugins": {
44-
"bamarni/composer-bin-plugin": true
45-
},
46-
"bump-after-update": "dev",
47-
"platform": {
48-
"php": "8.2"
49-
},
42+
"lock": false,
5043
"sort-packages": true
51-
},
52-
"extra": {
53-
"bamarni-bin": {
54-
"bin-links": false,
55-
"forward-command": true,
56-
"target-directory": "tools"
57-
}
58-
},
59-
"scripts": {
60-
"analyse-deps": "tools/composer-dependency-analyser/vendor/bin/composer-dependency-analyser",
61-
"fixcs": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff --verbose",
62-
"generate": [
63-
"@php generator/generate.php",
64-
"tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --quiet",
65-
"git add ."
66-
],
67-
"infection": "tools/infection/vendor/bin/infection --show-mutations",
68-
"normalize": "@composer bin composer-normalize normalize --diff ../../composer.json",
69-
"phpstan": "tools/phpstan/vendor/bin/phpstan analyze --memory-limit=-1",
70-
"pre-command-run": "mkdir -p var",
71-
"psalm": "tools/psalm/vendor/bin/psalm --show-info --no-diff --no-cache",
72-
"rector": "tools/rector/vendor/bin/rector process",
73-
"test": "phpunit"
7444
}
7545
}

0 commit comments

Comments
 (0)