Skip to content

Commit

Permalink
Improve code static analisis (#58)
Browse files Browse the repository at this point in the history
* Improve code static analisis

* Fix cs
  • Loading branch information
jordisala1991 authored May 31, 2020
1 parent 3eca307 commit 4607a56
Show file tree
Hide file tree
Showing 31 changed files with 2,639 additions and 430 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ APP_SECRET=ThisTokenIsNotSoSecretChangeIt

DATABASE_URL=mysql://symfony:symfony@mysql/symfony

MAILER_URL=null://localhost
MAILER_URL=smtp://mailhog:1025
MAILER_FROM=noreply@localhost
MAILER_BCC=[]
3 changes: 2 additions & 1 deletion .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.3']
php: ['7.4']
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
Expand All @@ -28,6 +28,7 @@ jobs:
- run: composer install --prefer-dist --no-progress --no-interaction --no-scripts
- run: composer php-cs-fixer -- --dry-run --format=checkstyle | cs2pr
- run: composer phpstan -- --error-format=checkstyle | cs2pr
- run: composer psalm -- --threads=$(nproc) --output-format=github
- run: composer normalize --dry-run
- run: composer lint-yaml
- run: composer lint-twig
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ $finder = Finder::create()
return Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'header_comment' => ['header' => "\n"],
'native_function_invocation' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
Expand Down
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
UNAME := $(shell uname)

AUTOLOAD = vendor/autoload.php
CERTS_DIR = .certs
DOCKER_COMPOSE = docker-compose
DOCKER_COMPOSE_FLAGS = -f docker/docker-compose.yaml -f docker/docker-compose-dev.yaml --env-file docker/.env
MKCERT = mkcert

docker-compose = $(DOCKER_COMPOSE) $(DOCKER_COMPOSE_FLAGS) $1
docker-exec = $(call docker-compose,exec -T app /bin/bash -c "$1")

.PHONY: up composer build halt destroy ssh certs provision composer-install \
composer-normalize phpstan php-cs-fixer phpunit phpunit-coverage database

# Docker
up: compose $(AUTOLOAD)

compose: $(CERTS_DIR)
ifeq ($(UNAME), Darwin)
SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock $(call docker-compose,up -d)
else
$(call docker-compose,up -d)
endif

build: halt
$(call docker-compose,build)

halt:
$(call docker-compose,stop)

destroy:
$(call docker-compose,down --remove-orphans)

ssh:
$(call docker-compose,exec app /bin/bash)

$(CERTS_DIR):
$(MAKE) certs

certs:
mkdir -p $(CERTS_DIR)
$(MKCERT) -install
$(MKCERT) -cert-file $(CERTS_DIR)/certificate.pem -key-file $(CERTS_DIR)/certificate-key.pem localhost

# App
$(AUTOLOAD):
$(MAKE) provision

provision: composer-install database

composer-install:
$(call docker-exec,composer install --optimize-autoloader)

composer-normalize:
$(call docker-exec,composer normalize)

phpstan:
$(call docker-exec,composer phpstan)

php-cs-fixer:
$(call docker-exec,composer php-cs-fixer)

database:
$(call docker-exec,console doctrine:database:drop --no-interaction --force)
$(call docker-exec,console doctrine:database:create --no-interaction)
# $(call docker-exec,console doctrine:database:import docker/dump.sql)
$(call docker-exec,console doctrine:migrations:migrate --no-interaction)
23 changes: 12 additions & 11 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;

if (false === \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the ' . \PHP_SAPI . ' SAPI' . \PHP_EOL;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the ' . PHP_SAPI . ' SAPI' . PHP_EOL;
}

\set_time_limit(0);
set_time_limit(0);

require \dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__DIR__) . '/vendor/autoload.php';

if (!\class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
\putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
putenv('APP_ENV=' . $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
\putenv('APP_DEBUG=' . $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
putenv('APP_DEBUG=' . $_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

require \dirname(__DIR__) . '/config/bootstrap.php';
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');

if ($_SERVER['APP_DEBUG']) {
\umask(0000);
umask(0000);

if (\class_exists(Debug::class)) {
if (class_exists(Debug::class)) {
Debug::enable();
}
}
Expand Down
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
"doctrine/orm": "2.7.3",
"friendsofsymfony/ckeditor-bundle": "1.2.0",
"friendsofsymfony/user-bundle": "2.1.2",
"sonata-project/admin-bundle": "3.67.0",
"sonata-project/admin-bundle": "3.68.0",
"sonata-project/block-bundle": "3.18.5",
"sonata-project/core-bundle": "3.19.1",
"sonata-project/doctrine-orm-admin-bundle": "3.17.1",
"sonata-project/easy-extends-bundle": "2.5.0",
"sonata-project/formatter-bundle": "4.1.3",
"sonata-project/media-bundle": "3.24.0",
"sonata-project/user-bundle": "4.5.3",
"symfony/dotenv": "5.0.8",
"symfony/dotenv": "5.1.0",
"symfony/flex": "1.7.1",
"symfony/framework-bundle": "4.4.8",
"symfony/framework-bundle": "4.4.9",
"symfony/monolog-bundle": "3.5.0",
"symfony/security-bundle": "4.4.8",
"symfony/security-bundle": "4.4.9",
"symfony/swiftmailer-bundle": "3.4.0",
"symfony/twig-bundle": "4.4.8",
"symfony/twig-bundle": "4.4.9",
"symfony/yaml": "5.1.0",
"twig/twig": "2.12.5"
},
Expand All @@ -41,8 +41,10 @@
"phpstan/phpstan": "0.12.25",
"phpstan/phpstan-doctrine": "0.12.13",
"phpstan/phpstan-symfony": "0.12.6",
"symfony/debug-bundle": "5.0.8",
"symfony/web-profiler-bundle": "5.0.8"
"symfony/debug-bundle": "5.1.0",
"symfony/web-profiler-bundle": "5.0.9",
"vimeo/psalm": "3.11.5",
"weirdan/doctrine-psalm-plugin": "0.11.1"
},
"extra": {
"symfony": {
Expand All @@ -63,11 +65,12 @@
"@auto-scripts"
],
"auto-scripts": {
"assets:install %PUBLIC_DIR% --symlink": "symfony-cmd"
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"lint-twig": "bin/console lint:twig templates",
"lint-yaml": "bin/console lint:yaml config src translations --parse-tags",
"php-cs-fixer": "php-cs-fixer fix --ansi --verbose",
"phpstan": "phpstan analyse --no-progress"
"phpstan": "phpstan analyse --no-progress",
"psalm": "psalm --stats"
}
}
Loading

0 comments on commit 4607a56

Please sign in to comment.