A Makefile example from a php project with support for different code quality tools.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WARNINGS && INFO: | |
# - a "\t" (tab) is needed before the commands, do not use spaces ..." | |
# - a "$" has special meaning in Makefiles, you need to double it to pass it) | |
# - please install/use the "Makefile support"-plugin for PhpStrom :) | |
TEST_ENV ?= local | |
CHECK_FILES ?= . | |
PHPSTAN_LEVEL ?= 3 | |
PHPSTAN_LEVEL_LEGACY ?= 2 | |
# May be useful if you want to test with a different php version | |
# (note that variables can also be overwritten in cli argument) | |
PHP_BIN := `php App/scripts/githooks/get_newest_local_php_version.php` | |
PHP_BIN_NO_DEBUG := -d"xdebug.remote_autostart=0" -d"xdebug.remote_enable=0" -d"xdebug.profiler_enable=0" | |
PHP_BIN_DEBUG := -d"xdebug.remote_autostart=1" -d"xdebug.remote_enable=1" -d"xdebug.profiler_enable=0" | |
# how to run composer (you can also use `$(PHP_BIN) composer.phar` | |
# to make sure composer uses the project's php binary) | |
COMPOSER_BIN := composer | |
# get the current number of CPU cores | |
CPU_CORES := `php App/scripts/githooks/get_processor_cores_number.php` | |
## | |
## Project | |
## | |
## Install and start the project | |
install: config-check start | |
## Stop and start a fresh install of the project | |
reset: stop install | |
.PHONY: start ## Start the project | |
start: | |
(cd App/html/ && php -S localhost:8888 index_wrapper.php > /dev/null 2>&1 &) | |
.PHONY: stop ## Stop the project | |
stop: | |
kill $$(ps aux | grep 'index_wrapper.php' | grep -v "grep" | awk '{print $$2}') | |
.PHONY: clean ## Remove the cache ... | |
clean: | |
rm -rf App/tmp/zend_cache_* | |
## | |
## Project: rules based on files | |
## | |
composer_update: composer.json | |
$(COMPOSER_BIN) update -o | |
composer_lock: composer.json | |
$(COMPOSER_BIN) update --lock --no-scripts --no-interaction | |
composer_install: composer.lock | |
$(COMPOSER_BIN) install | |
## | |
## Utils | |
## | |
.PHONY: regeneratemodules ## Run Regenerate-Modules | |
regeneratemodules: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/scripts/regeneratemodules.php | |
.PHONY: factory_doctype_fixer ## Run Factory-Doctype-Fixer | |
factory_doctype_fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/php-cs-fixer.phar fix --config=App/scripts/githooks/phpcs_factory_doctype_fixer.php | |
.PHONY: xajax_call_fixer ## Run Xajax-Call-Fixer | |
xajax_call_fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/php-cs-fixer.phar fix --config=App/scripts/githooks/phpcs_xajax_call_fixer.php | |
.PHONY: config-check ## Check the config | |
config-check: | |
@if [ \! -f LocalConfig/config.php ]; then \ | |
echo "The LocalConfig/LocalConfig/config.php is not there..." \ | |
exit 1; \ | |
fi | |
.PHONY: stop_chrome ## Stop chromium + driver | |
stop_chrome: | |
pkill chromedriver; \ | |
pkill chromium; \ | |
sleep 1; | |
.PHONY: start_chrome ## Start chromium + driver | |
start_chrome: | |
(cd App/html/ && php -S localhost:8888 index_wrapper.php > /dev/null 2>&1 &); | |
(/usr/lib/chromium-browser/chromedriver --url-base "/wd/hub" > /dev/null 2>&1 &); | |
artefacts: | |
mkdir -p $(ARTEFACTS) | |
## | |
## Tests | |
## | |
.PHONY: test ## Run all tests | |
test: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/codecept_php70.phar \ | |
--env="$(TEST_ENV)" \ | |
--fail-fast \ | |
run | |
.PHONY: test_api ## Run api tests | |
test_api: | |
$(PHP_BIN) $(PHP_BIN_DEBUG) Framework/thirdparty/codecept_php70.phar \ | |
--env="$(TEST_ENV)" \ | |
--fail-fast \ | |
run api | |
.PHONY: test_unit ## Run unit tests | |
test_unit: | |
$(PHP_BIN) $(PHP_BIN_DEBUG) Framework/thirdparty/codecept_php70.phar \ | |
--env="$(TEST_ENV)" \ | |
--fail-fast \ | |
run unit | |
.PHONY: test_acceptance ## Run acceptance tests | |
test_acceptance: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/codecept_php70.phar \ | |
--env="$(TEST_ENV)" \ | |
--fail-fast \ | |
run acceptance | |
## | |
## Quality assurance | |
## | |
ARTEFACTS = tests/_output/build | |
.PHONY: security ## Check security of your dependencies (https://security.sensiolabs.org/) | |
security: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/security-checker.phar security:check | |
.PHONY: phpmetrics ## PhpMetrics (https://www.phpmetrics.org/) | |
phpmetrics: | |
mkdir -p tests/_output/build/phpmetrics/ && \ | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/phpmetrics.phar \ | |
--config="App/scripts/githooks/.phpmetrics.json" \ | |
App,Framework | |
.PHONY: pdepend ## PHP_Depend (https://pdepend.org) | |
pdepend: | |
mkdir -p tests/_output/build/logs/ && \ | |
mkdir -p tests/_output/build/pdepend/ && \ | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/pdepend.phar \ | |
--jdepend-xml=tests/_output/build/logs/jdepend.xml \ | |
--jdepend-chart=tests/_output/build/pdepend/dependencies.svg \ | |
--overview-pyramid=tests/_output/build/pdepend/overview-pyramid.svg \ | |
--ignore Framework/thirdparty,App/thirdparty,Framework/artchiv,App/artchiv \ | |
.PHONY: phpmd ## PHP Mess Detector (https://phpmd.org) | |
phpmd: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_phpmd.php . | |
.PHONY: phpstan_legacy ## PHPStan (https://github.com/phpstan/phpstan) | |
phpstan_legacy: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_phpstan.php "$(CHECK_FILES)" "$(PHPSTAN_LEVEL_LEGACY)" "App/scripts/githooks/phpstan_legacy.neon" | |
.PHONY: phpstan ## PHPStan (https://github.com/phpstan/phpstan) | |
phpstan: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_phpstan.php "$(CHECK_FILES)" "$(PHPSTAN_LEVEL)" "App/scripts/githooks/phpstan.neon" | |
.PHONY: phpcpd ## PHP Copy/Paste Detector (https://github.com/sebastianbergmann/phpcpd) | |
phpcpd: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_phpcpd.php $(CHECK_FILES) | |
.PHONY: php_codesniffer ## PHP_codesniffer (https://github.com/squizlabs/PHP_CodeSniffer) | |
php_codesniffer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_codesniffer.php $(CHECK_FILES) | |
.PHONY: apply-php_codesniffer ## PHP_codesniffer (https://github.com/squizlabs/PHP_CodeSniffer) | |
apply-php_codesniffer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_codesniffer.php $(CHECK_FILES) "INFO: for all files" fix | |
.PHONY: php-cs-fixer ## php-cs-fixer (http://cs.sensiolabs.org) | |
php-cs-fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_codefixer.php $(CHECK_FILES) | |
.PHONY: apply-php-cs-fixer ## apply php-cs-fixer fixes | |
apply-php-cs-fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) App/scripts/githooks/check_code_codefixer.php $(CHECK_FILES) "INFO: for all files" fix | |
.PHONY: apply-php-cs-factory-doc-type-fixer ## apply php-cs-fixer fixes for factory-doctypes | |
apply-php-cs-factory-doc-type-fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/php-cs-fixer.phar fix --config=App/scripts/githooks/phpcs_factory_doctype_fixer.php | |
.PHONY: apply-php-cs-xajax-call-fixer ## apply php-cs-fixer fixes for xajax-calls | |
apply-php-cs-xajax-call-fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/php-cs-fixer.phar fix --config=App/scripts/githooks/phpcs_xajax_call_fixer.php | |
.PHONY: apply-php-cs-final-class-fixer ## apply php-cs-fixer fixes for final-classes | |
apply-php-cs-final-class-fixer: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/php-cs-fixer.phar fix --config=App/scripts/githooks/phpcs_final_class_fixer.php | |
.PHONY: composer-require-checker ## ComposerRequireChecker (https://github.com/maglnet/ComposerRequireChecker) | |
composer-require-checker: | |
$(PHP_BIN) $(PHP_BIN_NO_DEBUG) Framework/thirdparty/composer-require-checker.phar check composer.json | |
.PHONY: eslint ## eslint (https://eslint.org/) | |
eslint: | |
node_modules/.bin/eslint --fix-dry-run App/html/js/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment