Verified Commit 4f05cd9b authored by Alan Poulain's avatar Alan Poulain
Browse files

Add PHP-CS-Fixer, Makefile, EditorConfig and update documentation

parent 7e8d4ad4
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.json]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[*.php]
indent_style = space
indent_size = 4
[*.xml]
indent_style = space
indent_size = 4
[*.{yaml,yml}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false
[.php_cs{,.dist}]
indent_style = space
indent_size = 4
[composer.json]
indent_style = space
indent_size = 4
......@@ -23,3 +23,8 @@ ssh_password
###< symfony/framework-bundle ###
web/\.htaccess
###> friendsofphp/php-cs-fixer ###
/.php_cs
/.php_cs.cache
###< friendsofphp/php-cs-fixer ###
<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('var')
;
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder)
;
# -- Setup ——
SHELL = bash
PROJECT = app
EXEC_PHP = php
SYMFONY = $(EXEC_PHP) bin/console
COMPOSER = composer
NPM = npm
GULP = gulp
DOCKER = docker-compose
.DEFAULT_GOAL = help
.PHONY: assets
## —— Gogocarto Makefile ——
help: ## Outputs this help screen
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
## —— Composer ————————————
composer-install: composer.lock ## Install Composer vendors according to the current composer.lock file
$(COMPOSER) install
update: composer.json ## Update vendors according to the composer.json file
$(COMPOSER) update
## —— Symfony —————————————
sf: ## List all Symfony commands
$(SYMFONY)
cc: ## Clear the cache
$(SYMFONY) ca:cl
warmup: ## Warmump the cache
$(SYMFONY) cache:warmup
fix-perms: ## Fix permissions of all var files
chown -R www-data var/cache
chown -R www-data var/log
chown -R www-data var/sessions
chown -R www-data web/uploads
install-assets: ## Install the assets
$(SYMFONY) assets:install web/ --symlink
purge: ## Purge cache and logs
rm -rf var/cache/* var/log/*
## —— npm —————————————————
npm-install: package-lock.json ## Install npm vendors according to the current package-lock.json file
$(NPM) install
build-assets: ## Build the assets
$(GULP) build
## —— Docker ——————————————
build: docker/docker-compose.yml ## Build Docker images
$(DOCKER) -f docker/docker-compose.yml build --pull
up: docker/docker-compose.yml ## Start the Docker hub
$(DOCKER) -f docker/docker-compose.yml up -d
stop: docker/docker-compose.yml ## Stop the Docker hub
$(DOCKER) -f docker/docker-compose.yml stop
down: docker/docker-compose.yml ## Down the Docker hub
$(DOCKER) -f docker/docker-compose.yml down --remove-orphans
shell: docker/docker-compose.yml ## Start shell inside Docker
$(DOCKER) -f docker/docker-compose.yml exec gogocarto $(SHELL)
## —— Project —————————————
commands: ## Display all commands in the project namespace
$(SYMFONY) list $(PROJECT)
init: install assets load-fixtures fix-perms ## Initialize the project
install: composer-install npm-install ## Install vendors
assets: install-assets build-assets ## Install and build the assets
load-fixtures: ## Create the DB schema, generate DB classes and load fixtures
$(SYMFONY) doctrine:mongodb:schema:create
$(SYMFONY) doctrine:mongodb:generate:hydrators
$(SYMFONY) doctrine:mongodb:generate:proxies
$(SYMFONY) doctrine:mongodb:fixtures:load -n
## —— Tests ———————————————
test: phpunit.xml ## Launch unit tests
./bin/phpunit --stop-on-failure
## —— Coding Standards ————
cs-fix: ## Run php-cs-fixer and fix the code
./vendor/bin/php-cs-fixer fix src/
## —— Deploy & Prod ———————
deploy: ## Deploy the project
$(SHELL) ./update_gogocarto.sh
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4d8e65247d9b2d6008538476ff83637c",
"content-hash": "bdc9f7eaa23c803a31795e2fac5b599f",
"packages": [
{
"name": "alcaeus/mongo-php-adapter",
......@@ -10089,6 +10089,111 @@
}
],
"packages-dev": [
{
"name": "composer/semver",
"version": "1.5.1",
"source": {
"type": "git",
"url": "https://github.com/composer/semver.git",
"reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/semver/zipball/c6bea70230ef4dd483e6bbcab6005f682ed3a8de",
"reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de",
"shasum": ""
},
"require": {
"php": "^5.3.2 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.5 || ^5.0.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Semver\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nils Adermann",
"email": "naderman@naderman.de",
"homepage": "http://www.naderman.de"
},
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
},
{
"name": "Rob Bast",
"email": "rob.bast@gmail.com",
"homepage": "http://robbast.nl"
}
],
"description": "Semver library that offers utilities, version constraint parsing and validation.",
"keywords": [
"semantic",
"semver",
"validation",
"versioning"
],
"time": "2020-01-13T12:06:48+00:00"
},
{
"name": "composer/xdebug-handler",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/composer/xdebug-handler.git",
"reference": "cbe23383749496fe0f373345208b79568e4bc248"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/xdebug-handler/zipball/cbe23383749496fe0f373345208b79568e4bc248",
"reference": "cbe23383749496fe0f373345208b79568e4bc248",
"shasum": ""
},
"require": {
"php": "^5.3.2 || ^7.0 || ^8.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8"
},
"type": "library",
"autoload": {
"psr-4": {
"Composer\\XdebugHandler\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "John Stevenson",
"email": "john-stevenson@blueyonder.co.uk"
}
],
"description": "Restarts a process without Xdebug.",
"keywords": [
"Xdebug",
"performance"
],
"time": "2019-11-06T16:40:04+00:00"
},
{
"name": "easycorp/easy-log-handler",
"version": "v1.0.9",
......@@ -10139,6 +10244,146 @@
],
"time": "2019-10-24T07:13:31+00:00"
},
{
"name": "friendsofphp/php-cs-fixer",
"version": "v2.16.1",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git",
"reference": "c8afb599858876e95e8ebfcd97812d383fa23f02"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/c8afb599858876e95e8ebfcd97812d383fa23f02",
"reference": "c8afb599858876e95e8ebfcd97812d383fa23f02",
"shasum": ""
},
"require": {
"composer/semver": "^1.4",
"composer/xdebug-handler": "^1.2",
"doctrine/annotations": "^1.2",
"ext-json": "*",
"ext-tokenizer": "*",
"php": "^5.6 || ^7.0",
"php-cs-fixer/diff": "^1.3",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0",
"symfony/event-dispatcher": "^3.0 || ^4.0 || ^5.0",
"symfony/filesystem": "^3.0 || ^4.0 || ^5.0",
"symfony/finder": "^3.0 || ^4.0 || ^5.0",
"symfony/options-resolver": "^3.0 || ^4.0 || ^5.0",
"symfony/polyfill-php70": "^1.0",
"symfony/polyfill-php72": "^1.4",
"symfony/process": "^3.0 || ^4.0 || ^5.0",
"symfony/stopwatch": "^3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0",
"justinrainbow/json-schema": "^5.0",
"keradus/cli-executor": "^1.2",
"mikey179/vfsstream": "^1.6",
"php-coveralls/php-coveralls": "^2.1",
"php-cs-fixer/accessible-object": "^1.0",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.1",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1",
"phpunitgoodpractices/traits": "^1.8",
"symfony/phpunit-bridge": "^4.3 || ^5.0",
"symfony/yaml": "^3.0 || ^4.0 || ^5.0"
},
"suggest": {
"ext-mbstring": "For handling non-UTF8 characters in cache signature.",
"php-cs-fixer/phpunit-constraint-isidenticalstring": "For IsIdenticalString constraint.",
"php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "For XmlMatchesXsd constraint.",
"symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible."
},
"bin": [
"php-cs-fixer"
],
"type": "application",
"autoload": {
"psr-4": {
"PhpCsFixer\\": "src/"
},
"classmap": [
"tests/Test/AbstractFixerTestCase.php",
"tests/Test/AbstractIntegrationCaseFactory.php",
"tests/Test/AbstractIntegrationTestCase.php",
"tests/Test/Assert/AssertTokensTrait.php",
"tests/Test/IntegrationCase.php",
"tests/Test/IntegrationCaseFactory.php",
"tests/Test/IntegrationCaseFactoryInterface.php",
"tests/Test/InternalIntegrationCaseFactory.php",
"tests/TestCase.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Dariusz Rumiński",
"email": "dariusz.ruminski@gmail.com"
}
],
"description": "A tool to automatically fix PHP code style",
"time": "2019-11-25T22:10:32+00:00"
},
{
"name": "php-cs-fixer/diff",
"version": "v1.3.0",
"source": {
"type": "git",
"url": "https://github.com/PHP-CS-Fixer/diff.git",
"reference": "78bb099e9c16361126c86ce82ec4405ebab8e756"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-CS-Fixer/diff/zipball/78bb099e9c16361126c86ce82ec4405ebab8e756",
"reference": "78bb099e9c16361126c86ce82ec4405ebab8e756",
"shasum": ""
},
"require": {
"php": "^5.6 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.23 || ^6.4.3",
"symfony/process": "^3.3"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kore Nordmann",
"email": "mail@kore-nordmann.de"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "SpacePossum"
}
],
"description": "sebastian/diff v2 backport support for PHP5.6",
"homepage": "https://github.com/PHP-CS-Fixer",
"keywords": [
"diff"
],
"time": "2018-02-15T16:58:55+00:00"
},
{
"name": "symfony/debug-bundle",
"version": "v4.4.4",
......@@ -10292,6 +10537,65 @@
],
"time": "2020-01-08T17:29:02+00:00"
},
{
"name": "symfony/polyfill-php70",
"version": "v1.13.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php70.git",
"reference": "af23c7bb26a73b850840823662dda371484926c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/af23c7bb26a73b850840823662dda371484926c4",
"reference": "af23c7bb26a73b850840823662dda371484926c4",
"shasum": ""
},
"require": {
"paragonie/random_compat": "~1.0|~2.0|~9.99",
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.13-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Php70\\": ""
},
"files": [
"bootstrap.php"
],
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"time": "2019-11-27T13:56:44+00:00"
},
{
"name": "symfony/profiler-pack",
"version": "v1.0.4",
......
......@@ -8,7 +8,7 @@ PHP
- Folder: UperCamelCase
- Classes: UpperCamelCase
HTML (twig templates), JavaScript/TypeScript and CSS
HTML (Twig templates), JavaScript/TypeScript and CSS
- Folder: dashed-case
- Filenames: dashed-case
......@@ -20,31 +20,40 @@ JavaScript
HTML/CSS
- Classes-and-ids: dashed-case
Curly Bracket
-------------
PHP
---
To fix code style in PHP, run:
```shell
make cs-fix
```
JavaScript
----------
### Curly Bracket
Line return after functionName and parameters:
```
myFunction(myParameter)
{
// stuffs
// stuffs
}
```
Or inline function declaration `function() { return foo; }`
Code Indentation
----------------
### Code Indentation
Always use 3 spaces for indentation of code blocks
Always use 3 spaces for indentation of code blocks.
Spaces Around Operators
-----------------------
### Spaces Around Operators
Always put spaces around operators ( = + - * / ), and after commas:
```
var x = y + z;
var values = ["Volvo", "Saab", "Fiat"];
const x = y + z;
const values = ["Volvo", "Saab", "Fiat"];
```
......@@ -33,23 +33,7 @@ git clone https://gitlab.adullact.net/pixelhumain/GoGoCarto.git
cd GoGoCarto/
```
### Installing Dependencies
PHP dependencies (Symfony, bundles...)
```shell
composer install
```
Workflow dependencies (compiling SASS and JavaScript)
```shell
npm install gulp
npm install
```
Start
-----
### Initialize the Project
Create an `.env.local` file containing:
......@@ -57,57 +41,37 @@ Create an `.env.local` file containing:
MONGODB_URL=mongodb://localhost:27017
```
Dump assets:
```shell
php bin/console assets:install --symlink web
```
First build of JavaScript and CSS:
Execute the command:
```shell
gulp build
make init
```
Start watching for file change (automatic recompile):
It will:
- install the dependencies
- install and build the assets
- load the fixtures
```shell
gulp watch
```
Generate Database
-----------------
Go to Symfony console: `http://localhost/GoGoCarto/web/_console`
Run the followings command:
Now initialize your project with the following route:
```shell
doctrine:mongodb:schema:create
doctrine:mongodb:generate:hydrators
doctrine:mongodb:generate:proxies
doctrine:mongodb:fixtures:load
```
`http://localhost/GoGoCarto/web/project/initialize`
The last command will generate a basic configuration.
Start
-----
Then generate if necessary random points on the map:
Start watching for file changes (automatic recompilation):
```shell
app:elements:generate 200
gulp watch
```
Now initialize your project with the following route:
`http://localhost/GoGoCarto/web/project/initialize`
Updating your Install
---------------------
Each time you want to update GoGoCarto, run the following script: