Skip to content

Commit 910371e

Browse files
committed
Initial import
0 parents  commit 910371e

File tree

107 files changed

+13671
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+13671
-0
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.git* export-ignore
2+
/docs/ export-ignore
3+
/tests/ export-ignore
4+
/.php-cs-fixer.dist.php export-ignore
5+
/CHANGELOG.md export-ignore
6+
/phpstan.dist.neon export-ignore
7+
/phpunit.dist.xml export-ignore

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [smnandre]

.github/workflows/CI.yaml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: "CI"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
cs:
15+
name: "Code style"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: "Git: checkout"
19+
uses: actions/checkout@v4
20+
21+
- name: "PHP: setup 8.4"
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: '8.4'
25+
coverage: none
26+
tools: php-cs-fixer
27+
28+
- name: "Composer: validate"
29+
run: composer validate --strict
30+
31+
- name: "Composer: install"
32+
run: composer install --prefer-dist --no-interaction --no-progress
33+
34+
- name: "Php-CS-Fixer: version"
35+
run: vendor/bin/php-cs-fixer -V
36+
37+
- name: "Php-CS-Fixer: check"
38+
run: vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no
39+
40+
sa:
41+
name: "Static Analysis"
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: "Git: checkout"
45+
uses: actions/checkout@v4
46+
47+
- name: "PHP: setup 8.3"
48+
uses: shivammathur/setup-php@v2
49+
with:
50+
php-version: '8.3'
51+
coverage: none
52+
tools: phpstan
53+
54+
- name: "Composer: install"
55+
run: composer install --prefer-dist --no-interaction --no-progress
56+
57+
- name: "PHPStan: version"
58+
run: vendor/bin/phpstan --version
59+
60+
- name: "PHPStan: analyze"
61+
run: vendor/bin/phpstan analyse src
62+
63+
unit-tests:
64+
name: "Unit Tests (PHP ${{ matrix.php-version }})"
65+
runs-on: ubuntu-latest
66+
strategy:
67+
matrix:
68+
php-version: ['8.3', '8.4']
69+
fail-fast: false
70+
steps:
71+
- name: "Git: checkout"
72+
uses: actions/checkout@v4
73+
74+
- name: "PHP: setup ${{ matrix.php-version }}"
75+
uses: shivammathur/setup-php@v2
76+
with:
77+
php-version: ${{ matrix.php-version }}
78+
coverage: pcov
79+
tools: phpunit
80+
81+
- name: "Composer: install"
82+
run: composer install --prefer-dist --no-interaction --no-progress
83+
84+
- name: "PHPUnit: unit tests"
85+
run: vendor/bin/phpunit --testsuite unit
86+
87+
integration-tests:
88+
name: "Integration Tests (PHP ${{ matrix.php-version }} ${{ matrix.dependencies }})"
89+
runs-on: ubuntu-latest
90+
strategy:
91+
matrix:
92+
include:
93+
- php-version: '8.3'
94+
dependencies: 'low'
95+
- php-version: '8.4'
96+
dependencies: 'high'
97+
fail-fast: false
98+
steps:
99+
- name: "Git: checkout"
100+
uses: actions/checkout@v4
101+
102+
- name: "PHP: setup ${{ matrix.php-version }}"
103+
uses: shivammathur/setup-php@v2
104+
with:
105+
php-version: ${{ matrix.php-version }}
106+
coverage: pcov
107+
tools: phpunit
108+
109+
- name: "Node: setup"
110+
uses: actions/setup-node@v4
111+
with:
112+
node-version: '20'
113+
114+
- name: "Composer: install (${{ matrix.dependencies }})"
115+
run: |
116+
if [ "${{ matrix.dependencies }}" == "low" ]; then
117+
composer update --prefer-lowest --prefer-dist --no-interaction --no-progress
118+
else
119+
composer install --prefer-dist --no-interaction --no-progress
120+
fi
121+
122+
- name: "PHPUnit: version"
123+
run: vendor/bin/phpunit --version
124+
125+
- name: "PHPUnit: all tests with coverage"
126+
run: vendor/bin/phpunit --coverage-clover=coverage.xml
127+
128+
# - name: "Codecov: upload coverage"
129+
# uses: codecov/codecov-action@v5
130+
# if: matrix.php-version == '8.4' && matrix.dependencies == 'high'
131+
# with:
132+
# files: ./coverage.xml
133+
# flags: unittests
134+
# name: codecov-umbrella
135+
# fail_ci_if_error: false

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.phpunit.cache/
2+
/vendor/
3+
/.php-cs-fixer.cache
4+
/composer.lock
5+
/coverage.xml
6+
/phpstan.neon
7+
/phpunit.xml
8+
/.phpunit-coverage/

.php-cs-fixer.dist.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
4+
5+
$finder = (new PhpCsFixer\Finder())
6+
->in(__DIR__);
7+
8+
return (new PhpCsFixer\Config())
9+
->setParallelConfig(ParallelConfigFactory::detect())
10+
->setRiskyAllowed(true)
11+
->setRules([
12+
'@PSR12' => true,
13+
'@Symfony' => true,
14+
'declare_strict_types' => true,
15+
])
16+
->setFinder($finder);

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-present Simon André
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: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
.PHONY: about qa sa cs fix lint test help phpunit phpstan php-cs-fixer phpcsfixer
2+
3+
.DEFAULT_GOAL := help
4+
5+
ARGS ?=
6+
PHP_CMD ?= php
7+
8+
get_args = $(if $(filter-out $1,$(MAKECMDGOALS)),$(filter-out $1,$(MAKECMDGOALS)),$(ARGS))
9+
10+
define run_cmd
11+
@echo "[·] \033[2m$(1) $(2)\033[0m\n"
12+
@start_time=$$(date +%s.%N); \
13+
$(1) $(2); \
14+
exit_code=$$?; \
15+
end_time=$$(date +%s.%N); \
16+
elapsed_time=$$(echo "$$end_time - $$start_time" | bc | awk '{printf "%.2f", $$1}'); \
17+
command="$(1) $(2)"; \
18+
if [ $$exit_code -eq 0 ]; then \
19+
printf "\n[\033[32m✓\033[0m] \033[2m%s\033[0m\033[116G\033[2m[\033[0m\033[32m%s\033[0m \033[2mseconds\033[0m\033[2m]\033[0m\n" "$$command" "$$elapsed_time"; \
20+
else \
21+
printf "\n[\033[31m✗\033[0m] \033[2m%s\033[0m\033[116G\033[2m[\033[0m\033[31m%s\033[0m \033[2mseconds\033[0m\033[2m]\033[0m\n" "$$command" "$$elapsed_time"; \
22+
fi
23+
endef
24+
25+
define php_cmd
26+
$(call run_cmd,$(PHP_CMD) $(1),$(2))
27+
endef
28+
29+
GIT_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "dev-main")
30+
PHP_VERSION := $(shell php -r 'echo PHP_VERSION;' 2>/dev/null || echo "n/a")
31+
PROJECT_NAME := TWIG METRICS
32+
REPO_URL := https://github.com/smnandre/twig-metrics
33+
34+
about:
35+
@echo "┌───────────────────────────── 🌿 ────────────────────────────────┐"; \
36+
printf "│%*s\033[38;5;113m%s\033[0m \033[38;5;252m%s\033[0m%*s│\n" 26 "" "TWIG " "METRICS" 26 ""; \
37+
echo "│ │"; \
38+
printf "│ %-63s │\n" "$(REPO_URL)"; \
39+
echo "│ │"; \
40+
printf "│ %-9s \033[36m%-21s\033[0m %-9s \033[36m%-21s\033[0m │\n" "Author:" "Simon André" "Version:" "$(GIT_VERSION)"; \
41+
printf "│ %-9s \033[36m%-20s\033[0m %-9s \033[36m%-21s\033[0m │\n" "License:" "MIT " "PHP: " "$(PHP_VERSION)"; \
42+
echo "└─────────────────────────────────────────────────────────────────┘"
43+
44+
warning:
45+
@echo ""
46+
@echo " \033[33m⚠︎\033[0m \033[2mThis Makefile is intended for \033[0;0mTwig Metrics \033[33mdevelopment\033[2m.\033[0m"
47+
@echo " \033[2mIt includes tools and commands for quality checks and tests.\033[0m"
48+
@echo " \033[2mEnd users \033[0mdo not\033[2m need to run these commands.\033[0m"
49+
@echo ""
50+
51+
help: about
52+
@echo ""
53+
@echo " Usage:"
54+
@echo " \033[33mmake \033[38;5;113mphpunit\033[0m\033[33m ARGS=\"\033[38;5;113m--testdox\033[33m\"\033[0m"
55+
@echo ""
56+
@echo " Tools:"
57+
@echo " make \033[38;5;113mphpunit\033[0m Run PHPUnit\033[0m"
58+
@echo " make \033[38;5;113mphpstan\033[0m Run PHPStan\033[0m"
59+
@echo " make \033[38;5;113mphp-cs-fixer\033[0m Run PHP-CS-Fixer\033[0m"
60+
@echo ""
61+
@echo " Commands:"
62+
@echo " make \033[38;5;113mfix\033[0m Run fixers (\033[32mphp-cs-fixer\033[0m)"
63+
@echo " make \033[38;5;113mlint\033[0m Run linters (\033[32mphp-cs-fixer\033[0m)"
64+
@echo " make \033[38;5;113mtest\033[0m Run tests (\033[32mphpunit\033[0m)"
65+
@echo " make \033[38;5;113msa\033[0m Run static analysis (\033[32mphpstan\033[0m)"
66+
@echo ""
67+
@echo " All-in:"
68+
@echo " make \033[92mqa\033[0m Run \033[32mfix\033[0m, \033[32mlint\033[0m, \033[32msa\033[0m, \033[32mtest\033[0m"
69+
@make warning
70+
71+
phpcsfixer:
72+
$(call php_cmd,vendor/bin/php-cs-fixer fix,$(call get_args,$@))
73+
74+
php-cs-fixer:
75+
@$(MAKE) phpcsfixer ARGS="$(ARGS)"
76+
77+
cs:
78+
@$(MAKE) lint
79+
80+
phpstan:
81+
$(call php_cmd,vendor/bin/phpstan analyse -- src,$(call get_args,$@))
82+
83+
phpunit:
84+
$(call php_cmd,vendor/bin/phpunit,$(call get_args,$@))
85+
86+
fix:
87+
@$(MAKE) phpcsfixer ARGS="--diff"
88+
89+
lint:
90+
@$(MAKE) phpcsfixer ARGS="--diff --dry-run"
91+
92+
sa:
93+
@$(MAKE) phpstan
94+
95+
test:
96+
@$(MAKE) phpunit
97+
98+
qa:
99+
@$(MAKE) fix
100+
@$(MAKE) lint
101+
@$(MAKE) sa
102+
@$(MAKE) test
103+
104+
%:
105+
@:

0 commit comments

Comments
 (0)