Skip to content

Instantly share code, notes, and snippets.

@phpdave11
Created August 12, 2019 14:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave11/412893f8366cab0afa85e81a7a66bd72 to your computer and use it in GitHub Desktop.
Save phpdave11/412893f8366cab0afa85e81a7a66bd72 to your computer and use it in GitHub Desktop.
php code validation with phpnsc, php-cs-fixer, phpcpd, phpmd, and phpstan
{
"@Symfony": true,
"@PSR2": true,
"array_syntax": {
"syntax": "short"
},
"hash_to_slash_comment": true,
"heredoc_to_nowdoc": true,
"modernize_types_casting": true,
"multiline_comment_opening_closing": true,
"multiline_whitespace_before_semicolons": true,
"native_function_invocation": false,
"new_with_braces": false,
"no_useless_else": false,
"no_useless_return": true,
"not_operator_with_successor_space": true,
"ordered_class_elements": true,
"ordered_imports": true,
"pow_to_exponentiation": true,
"simplified_null_return": true,
"ternary_to_null_coalescing": true,
"yoda_style": false,
"void_return": false,
"concat_space": {
"spacing": "one"
}
}
{
"vendor" : "App",
"folders" : {
"root" : "./src/",
"include" : [""],
"exclude" : []
},
"filetypes" : {
"include" : [".php"],
"exclude" : [".config.php"]
},
"output" : [{
"class": "rg\\tools\\phpnsc\\CheckstyleOutput",
"parameter": "/tmp/phpnsc.xml"
},{
"class": "rg\\tools\\phpnsc\\ConsoleOutput",
"parameter": ""
}]
}
parameters:
excludes_analyse:
- %rootDir%/../../../src/Migrations
ignoreErrors:
- '#Call to an undefined method Doctrine\\Common\\Persistence\\ObjectManager::getConnection\(\)#'
#!/usr/bin/env bash
BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
echo "[INFO] PHP Name Space Checker"
$BASEDIR/vendor/rg/phpnsc/phpnsc run $BASEDIR/phpnsc.json
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo "[ERROR] phpnsc returned errors."
exit 1
fi
echo "[INFO] PHP Coding Standards Fixer"
$BASEDIR/vendor/bin/php-cs-fixer fix $BASEDIR/src --allow-risky=yes --rules="$(cat $BASEDIR/php-cs-fixer.json)" --stop-on-violation --dry-run --using-cache=no
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo "[ERROR] php-cs-fixer found code that does not adhere to specified coding standard rules."
echo ""
echo "To fix this, run the following command:"
echo ""
echo "vendor/bin/php-cs-fixer fix $BASEDIR/src --allow-risky=yes --using-cache=no --rules=\"\$(cat $BASEDIR/php-cs-fixer.json)\""
exit 1
fi
echo "[INFO] PHP Copy/Paste Detector"
$BASEDIR/vendor/sebastian/phpcpd/phpcpd $BASEDIR/src
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo "[ERROR] phpcpd found duplicate code."
exit 1
fi
echo "[INFO] PHP Mess Detector"
$BASEDIR/vendor/phpmd/phpmd/src/bin/phpmd $BASEDIR/src --exclude $BASEDIR/src/Migrations text unusedcode
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo "[ERROR] phpmd found unused code."
exit 1
fi
echo "[INFO] PHP Static Analysis Tool"
$BASEDIR/vendor/bin/phpstan analyse $BASEDIR/src --level=4
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo "[ERROR] phpstan found errors."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment