I'm using GrumPhp to sniff my commit in my symfony project: https://github.com/phpro/grumphp
Here is my config:
parameters:
git_dir: .
bin_dir: vendor/bin
tasks:
phpcsfixer:
config_file: ~
config: sf23
fixers: [psr2, symfony, indentation]
level: psr2
verbose: true
My question is:
Is there a way for Grumphp to automatically run php-cs-fixer when I commiting?
Yes there is!
https://github.com/phpro/grumphp/blob/master/doc/tasks.md
Since your post is a bit older here is the new updated doc, but you can still use version one! https://github.com/phpro/grumphp/blob/master/doc/tasks/php_cs_fixer2.md
You could try out this configuration but it's phpcsfixer version2!:
# grumphp.yml
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
hooks_dir: ~
hooks_preset: local
stop_on_failure: false
ignore_unstaged_changes: false
process_async_limit: 10
process_async_wait: 1000
process_timeout: 60
ascii:
failed: grumphp-grumpy.txt
succeeded: grumphp-happy.txt
tasks:
phpcsfixer2:
allow_risky: false
cache_file: ~
config: ~
rules: ['#Symfony']
using_cache: true
path_mode: ~
verbose: true
Your config looks fine, what's the output ?
Do you have the cs fixer installed and configured the grumPHP config to the path of your CS fixer?
https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage
GrumPHP always run php-cs-fixer with the --dry-run argument and this behavior is not configurable. You can read why here: https://github.com/phpro/grumphp/issues/110
But there's a way to automatically run php-cs-fixer: you have to install GrumPHP Extra Tasks and replace phpcsfixer2 with php_cs_auto_fixerv2 in your "grumpphp.yml" file.
Be aware that as of today GrumPHP Extra Tasks is not compatible with the latest version of GrumPHP but up to 0.17.2.
Related
If you've worked with Laravel and Lando together, you probably know that Lando gives you its own artisan shortcut. So instead of having to run lando php artisan ..., you can run lando artisan ....
However, when I do that, I get this error:
Could not open input file: /app/./../artisan
This forces me to have to run lando php artisan to run any artisan commands, and that does work fine. So far, this is all that's going wrong with my project in Lando. Everything else is running smoothly.
Here's what my lando config looks like:
name: laravel-project
recipe: laravel
config:
php: '7.4'
composer_version: '2.0.12'
database: mysql:8.0
services:
appserver:
webroot: public
xdebug: true
config:
php: .vscode/php.ini
node:
type: node:14
tooling:
node:
service: node
yarn:
service: node
Also, this does look a bit different from Lando's sample config on their website. This is because I was trying to configure xdebug according to their "Using Lando with VSCode" instructions (see Lando rc.2+ version).
Appreciate any help figuring this weird issue out. It's not debilitating, but it does get in the way when I forget the workaround.
Other notes:
"webroot" is set to "public" because that's where the public-facing directory is for a Laravel app. The example Lando config for Laravel has this part wrong and it causes the project root to be visible to the browser.
I got it working. I moved the webroot key back under the top-level config. Not sure what the difference is, but as long as it works... I guess the only thing I really need to specify in the appserver service is the Xdebug settings.
name: laravel-project
recipe: laravel
config:
php: '7.4'
composer_version: '2.0.12'
webroot: public
database: mysql:8.0
services:
appserver:
xdebug: true
config:
php: .vscode/php.ini
node:
type: node:14
tooling:
node:
service: node
yarn:
service: node
For some reason grumphp not working for me as expected.
First of all my project directory structure is:
.git/
devops/
app/
src/
confing/
bin/
vendor/
grumphp.yml
phpcs.xml
...
so I in the git repo I have some docker related files in the devops folder, and symfony app int the app folder, also in app folder I have grumphp and all linters configs.
I want to run grumphp from inside of the docker container when I commit some changes to check if my code is correct.
Here is my grumphp.yml
grumphp:
environment:
variables:
GRUMPHP_PROJECT_DIR: "."
GRUMPHP_GIT_WORKING_DIR: "../"
GRUMPHP_BIN_DIR: "vendor/bin/"
GRUMPHP_GIT_REPOSITORY_DIR: "../.git/"
git_hook_variables:
EXEC_GRUMPHP_COMMAND: docker exec php-fpm
stop_on_failure: false
ignore_unstaged_changes: false
hide_circumvention_tip: false
process_timeout: 6
tasks:
composer: ~
phpcs:
standard: phpcs.xml
ignore_patterns: [./var/*, ./public/*, ./config/*, ./bin/*]
phpcsfixer2:
config: .php_cs
phpstan:
autoload_file: ./bin/.phpunit/phpunit-9.0.1-0/vendor/autoload.php
memory_limit: "-1"
git_commit_message:
allow_empty_message: false
enforce_capitalized_subject: false
enforce_no_subject_punctuations: false
enforce_no_subject_trailing_period: true
enforce_single_lined_subject: true
type_scope_conventions: []
max_body_width: 0
max_subject_width: 72
matchers:
Must contain JIRA issue number: /^(Merge)|([A-Z_0-9]+-[0-9]+)/
case_insensitive: true
multiline: true
additional_modifiers: ''
yamllint:
whitelist_patterns: [ ]
ignore_patterns:
- /^vendor\/(.*)/
object_support: false
exception_on_invalid_type: false
parse_constant: false
parse_custom_tags: false
testsuites:
pre-commit:
tasks:
- composer
- phpcs
- phpcsfixer2
- phpstan
- yamllint
- git_commit_message
and when I'm running vendor/bin/grumphp git:init from inside of the docker container, pre-commit file generated in the .git/hooks directory, generated pre-commit file content:
#!/bin/sh
#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#
# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false -c diff.noprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)
# Grumphp env vars
export GRUMPHP_GIT_WORKING_DIR="$(git rev-parse --show-toplevel)"
# Run GrumPHP
(cd "app/" && printf "%s\n" "${DIFF}" | docker exec php-fpm 'vendor/phpro/grumphp/bin/grumphp' 'git:pre-commit' '--skip-success-output')
SO what is the issue?
When I run git commit having php files with a broken styles, grumphp telling that all is fine and allowing me to commit this files, but when I run vendor/bin/grumphp run from inside of the container all working fine and I see list of all the issues I need to fix.
So why all linters checks passing on commit when they should not, but when I'm running vendor/bin/grumphp run it's working as expected?
I'm not sure but I think it somehow related to my directory structure, I have .git in the root of repository, but symfony and grumphp.yml in the app directory.
Thanks in advance!
Created new project with appengine-starter-symfony-project (https://github.com/GoogleCloudPlatform/appengine-symfony-starter-project) and tried to run app/server as follows:
composer run-script server --timeout=0
Error recived:
// Clearing the cache for the dev environment with debug
// false
[Symfony\Component\Cache\Exception\CacheException]
Memcached >= 2.2.0 is required
Running PHP Version 7.2.8 on Xampp (Win 10) and cant see a php_memcache in ext folder.
Indeed, this is the expected behavior. If you take a look inside of config.yml you will see the following:
services:
memcache:
class: Memcache
session.handler.memcache:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcacheSessionHandler
arguments:
- "#memcache"
- { prefix: ~, expiretime: ~ }
Basically, you cache is dependent on Memchace. You can either tweak around and switch to some other vendor or install the appropriate DLL.
Hope this helps a bit...
I try use dredd with symfony on windows PC.
i do next:
i create folder dredd in symfony poject
app
dredd
src
vendor
e.t.c
in symfony composer.json i add
"ddelnano/dredd-hooks-php":"dev"
Next step, i create this dredd.yml
dry-run: null
hookfiles: ./hooks.php
language: php
sandbox: false
server: null
server-wait: 3
init: false
custom:
apiaryApiKey: 'apikey '
apiaryApiName: 'apiname'
names: false
only: []
reporter: apiary
output: []
header: []
sorted: false
user: user:pass
inline-errors: true
details: true
method: []
color: true
level: info
timestamp: true
silent: false
path: []
hooks-worker-timeout: 5000
hooks-worker-connect-timeout: 1500
hooks-worker-connect-retry: 500
hooks-worker-after-connect-wait: 100
hooks-worker-term-timeout: 5000
hooks-worker-term-retry: 500
hooks-worker-handler-host: localhost
hooks-worker-handler-port: 61321
config: ./dredd.yml
blueprint: test.apib
endpoint: 'someendpoint'
and another needed file.
and dredd response
error: PHP hooks handler command not found: dredd-hooks-php Install
php hooks handler by running: $ composer require
ddelnano/dredd-hooks-php --dev
Why it does not work? What am I doing wrong?
P.S. sorry for my english.
As of now, Dredd is not officially supported on Windows. However, it should install and should work well as far as you don't need other than JavaScript hooks. Any other hooks do not work at the moment.
Support for Windows is on the roadmap though - https://github.com/apiaryio/dredd/issues/204
When i run the command
php app/console translation:extract en --enable-extractor=jms_i18n_routing
i get the following error:
[JMS\TranslationBundle\Exception\InvalidArgumentException]
The directory where translations are must be set.
this is the bundle configuration:
jms_i18n_routing:
default_locale: it
locales: [it, en]
strategy: prefix
cookie:
enabled: false
What is wrong with that?
You can fix this by using the --dir option to define the directory where your translations are when running your translation:extractcommand.
From the documentation,
For dumping, the bundle provides you with a console command which you
can use to update your translation files, or also just to preview all
changes that have been made.
Updating Files:
php app/console translation:extract de --dir=./src/ --output-dir=./app/Resources/translations
i had to use the following command
php app/console translation:extract en --enable-extractor=jms_i18n_routing --bundle="AcmeFooBundle" --domain="routes"