Skip to content

Commit

Permalink
Merge pull request #11 from mitelg/add-static-analysis
Browse files Browse the repository at this point in the history
Add CI pipeline and improve code quality
  • Loading branch information
mitelg authored Dec 21, 2018
2 parents 13ffd0f + eaab2da commit 6c08118
Show file tree
Hide file tree
Showing 15 changed files with 1,699 additions and 807 deletions.
5 changes: 0 additions & 5 deletions .githooks/install_hooks.sh

This file was deleted.

156 changes: 0 additions & 156 deletions .githooks/pre-commit

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Based on Symfony 4.1
```sh
$ composer install
```
- create `.env file with `cp .env.dist .env``
- create `.env` file with `cp .env.dist .env`
- make adjustments according to your setup (e.g. DB connection)
```sh
$ php bin/console doctrine:database:create
Expand Down
95 changes: 95 additions & 0 deletions bin/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh

PROJECT=`php -r "echo dirname(dirname(realpath('$0')));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.*`

# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}

for FILE in $SFILES
do
FILES="$FILES $PROJECT/$FILE"
done

if [ "$FILES" != "" ]
then
echo "fix code style and update the commit"
vendor/bin/php-cs-fixer fix --config=.php_cs.dist --quiet --allow-risky=yes -vv $FILES
git add $FILES
fi

if [ "$FILES" != "" ]
then
echo "Static code analysis..."
vendor/bin/phpstan analyse src --level 7 --no-progress
if [ $? != 0 ]
then
echo "Static code analysis failed. Fix the error before commit."
exit 1
fi
fi

if [ "$FILES" != "" ]
then
echo "Checking for insecure libs..."
vendor/bin/security-checker security:check
if [ $? != 0 ]
then
echo "Insecure libraries found. Fix the error before commit."
exit 1
fi
fi

if [ "$FILES" != "" ]
then
echo "Linting Twig templates..."
bin/console lint:twig templates
if [ $? != 0 ]
then
echo "Twig linting failed. Fix the error before commit."
exit 1
fi
fi

if [ "$FILES" != "" ]
then
echo "Linting Yaml files..."
bin/console lint:yaml config
if [ $? != 0 ]
then
echo "Yaml linting failed. Fix the error before commit."
exit 1
fi
fi

if [ "$FILES" != "" ]
then
echo "Linting PHP files..."
vendor/bin/parallel-lint src
if [ $? != 0 ]
then
echo "PHP linting failed. Fix the error before commit."
exit 1
fi
fi

if [ "$FILES" != "" ]
then
echo "Checking for var_dump()s..."
vendor/bin/var-dump-check src --doctrine --symfony
if [ $? != 0 ]
then
echo "Debug outputs found. Fix the error before commit."
exit 1
fi
fi

exit $?
55 changes: 34 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,41 @@
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"doctrine/collections": "1.5.0",
"doctrine/doctrine-bundle": "1.10.0",
"doctrine/doctrine-cache-bundle": "1.3.5",
"doctrine/doctrine-migrations-bundle": "1.3.2",
"doctrine/orm": "2.6.3",
"knplabs/knp-components": "1.3.10",
"knplabs/knp-paginator-bundle": "2.8.0",
"sensio/framework-extra-bundle": "5.2.0",
"symfony/apache-pack": "^1.0",
"symfony/asset": "4.1.4",
"symfony/console": "4.1.4",
"symfony/dotenv": "4.1.4",
"symfony/flex": "1.1.1",
"symfony/form": "4.1.4",
"symfony/framework-bundle": "4.1.4",
"sensio/framework-extra-bundle": "5.2.4",
"symfony/apache-pack": "1.0.1",
"symfony/asset": "4.2.1",
"symfony/config": "4.2.1",
"symfony/console": "4.2.1",
"symfony/dependency-injection": "4.2.1",
"symfony/doctrine-bridge": "4.2.1",
"symfony/dotenv": "4.2.1",
"symfony/flex": "1.1.8",
"symfony/form": "4.2.1",
"symfony/framework-bundle": "4.2.1",
"symfony/http-foundation": "4.2.1",
"symfony/http-kernel": "4.2.1",
"symfony/orm-pack": "1.0.5",
"symfony/translation": "4.1.4",
"symfony/twig-bundle": "4.1.4",
"symfony/validator": "4.1.4",
"symfony/web-server-bundle": "4.1.4",
"symfony/yaml": "4.1.4"
"symfony/routing": "4.2.1",
"symfony/translation": "4.2.1",
"symfony/twig-bundle": "4.2.1",
"symfony/validator": "4.2.1",
"symfony/web-server-bundle": "4.2.1",
"symfony/yaml": "4.2.1"

},
"require-dev": {
"friendsofphp/php-cs-fixer": "2.13.0"
"friendsofphp/php-cs-fixer": "2.13.1",
"jakub-onderka/php-parallel-lint": "1.0.0",
"jakub-onderka/php-var-dump-check": "0.3.0",
"phpstan/phpstan": "0.10.6",
"sensiolabs/security-checker": "^5.0"
},
"config": {
"preferred-install": {
Expand All @@ -37,11 +54,6 @@
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
Expand All @@ -51,11 +63,12 @@
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd",
"security-checker security:check": "script"
},
"post-install-cmd": [
"@auto-scripts",
"./.githooks/install_hooks.sh"
"ln -sf ../../bin/pre-commit.sh .git/hooks/pre-commit"
],
"post-update-cmd": [
"@auto-scripts"
Expand Down
Loading

0 comments on commit 6c08118

Please sign in to comment.