# Template file for 'php-codesniffer'
pkgname=php-codesniffer
_pkgname=PHP_CodeSniffer
version=3.5.8
revision=1
wrksrc="${_pkgname}-${version}"
build_style=fetch
hostmakedepends="tar php"
depends="php"
short_desc="Tokenizes PHP files and detects violations of coding standards"
maintainer="reback00 <reback00@protonmail.com>"
license="BSD-3-Clause"
homepage="https://github.com/squizlabs/PHP_CodeSniffer"
distfiles="https://github.com/squizlabs/${_pkgname}/archive/${version}.tar.gz"
checksum="012918447718067242aabd7669d54aceb91e78bdd928366744d629b6ae5fbe44"

do_extract() {
	tar -xf "$XBPS_SRCDISTDIR/$pkgname-$version/$version.tar.gz" -C "$XBPS_BUILDDIR"
}

do_configure() {
	# Disable phar.readonly on PHP config. It allows to create .phar files.
	# It is enabled by default as a security feature. There is no other way to
	# disable it other than setting it on system .ini file. Details:
	# https://stackoverflow.com/a/35120728
	mkdir -p /etc/php/conf.d/
	echo -e "[Phar]\nphar.readonly = Off" > /etc/php/conf.d/phar_build.ini
}

do_build() {
	php -d extension=phar.so scripts/build-phar.php
}

do_install() {
	vbin phpcs.phar phpcs
	vbin phpcbf.phar phpcbf

	vlicense licence.txt
}
