Php cs fixer phpstorm windows

realrashid / Install PHP-CS-Fixer.md

There’s no php-cs-fixer.bat, and that executablePath wouldn’t work unless the environment variable PATH is updated. This gist is lacking a lot of information.

C:\Users\rasho\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat
it exists !
it’s working in my case.

share your issue what issue are you facing and your os info.

We need a full step by step instructions on how to install php cs fixer in windows, including the fact that PHP needs to be installed (how, where, what to set up) then exactly what to do next. No luck for me so far. So hard to find good info.

Is there a way to get it to work without having to install composer. I just want to format some php, not have the whole composer thing

I extracted both php and php-cs-fixer on the same folder without installing composer.

I then added this lines to my config file and php-cs-fixer is working:
«php.validate.executablePath»: «C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php.exe»,
«php.executablePath»: «C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php.exe»,
«php-cs-fixer.executablePath»: «C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php-cs-fixer-v2.phar»,
«php-cs-fixer.executablePathWindows»: «C:\Users\jaime\php-7.2.7-Win32-VC15-x64\php-cs-fixer-v2.phar»,

When you install composer globally the php-cs-fixer.bat file will be available in your Roaming\Composer\vendor\bin directory. From there you can go in phpstorm and under Languages and Frameworks ->PHP -> Quality Tools -> PHP CS Fixer -> click the . and set the directory path to your .bat file and you then set it in Editor->Inspections->Quality Tools->PHP CS Fixer Validation. Apply the settings and click ok and you should be good.

settings.json file
«php-cs-fixer.executablePath»: «%USERPROFILE%\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat»,
«php-cs-fixer.executablePathWindows»: «%USERPROFILE%\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat»,
«php-cs-fixer.config»: «%USERPROFILE%\\.vscode\\.php_cs»,

There’s no php-cs-fixer.bat, and that executablePath wouldn’t work unless the environment variable PATH is updated. This gist is lacking a lot of information.

Same here and I don’t know what to do.

On Fri, Apr 10, 2020, 1:32 PM kareemadesola ***@***.***> wrote: ***@***.**** commented on this gist. —————————— There’s no php-cs-fixer.bat, and that executablePath wouldn’t work unless the environment variable PATH is updated. This gist is lacking a lot of information. Same here and I don’t know what to do. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub , or unsubscribe .

This is work just fine on my Windows. Thank’s a lot btw.

I usually use Local by Flywheel on Windows, and I did not install PHP locally.
In that case, it seems that you need to install PHP separately.

The first step is to go to
https://www.php.net/downloads
from the «Windows downlaods» link at to install PHP in C:\php.

Finally, add the following lines to settings.json and it works fine.

 "[php]": < "editor.defaultFormatter": "junstyle.php-cs-fixer" >, // "php.executablePath": "C:/php/php.exe", "php.validate.executablePath": "C:/php/php.exe", "php-cs-fixer.onsave": true, "php-cs-fixer.executablePath": "~/.vscode/php-cs-fixer-v3.phar", 

I usually use Local by Flywheel on Windows, and I did not install PHP locally. In that case, it seems that you need to install PHP separately.

The first step is to go to https://www.php.net/downloads from the «Windows downlaods» link at to install PHP in C:\php.

Next, download php-cs-fixer-v3.phar from the following link and place it in ~/.vscode/. https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/installation.rst

Finally, add the following lines to settings.json and it works fine.

 "[php]": < "editor.defaultFormatter": "junstyle.php-cs-fixer" >, // "php.executablePath": "C:/php/php.exe", "php.validate.executablePath": "C:/php/php.exe", "php-cs-fixer.onsave": true, "php-cs-fixer.executablePath": "~/.vscode/php-cs-fixer-v3.phar", 

This is the one that worked for me, thanks!!

On Sun, Mar 27, 2022, 5:31 AM LuisCardeBu ***@***.***> wrote: ***@***.**** commented on this gist. —————————— I usually use Local by Flywheel on Windows, and I did not install PHP locally. In that case, it seems that you need to install PHP separately. The first step is to go to https://www.php.net/downloads from the «Windows downlaods» link at to install PHP in C:\php. Next, download php-cs-fixer-v3.phar from the following link and place it in ~/.vscode/. https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/installation.rst Finally, add the following lines to settings.json and it works fine. «[php]»: < "editor.defaultFormatter": "junstyle.php-cs-fixer" >, // «php.executablePath»: «C:/php/php.exe», «php.validate.executablePath»: «C:/php/php.exe», «php-cs-fixer.onsave»: true, «php-cs-fixer.executablePath»: «~/.vscode/php-cs-fixer-v3.phar», This is the one that worked for me, thanks!! — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you authored the thread.Message ID:

You can’t perform that action at this time.

Источник

Php cs fixer phpstorm windows

Как отформатировать код в PhpStorm используя PHP CS Fixer

Как отформатировать код в PhpStorm используя PHP CS Fixer

Начиная с версии 5.8 Laravel включает файл .styleci.yml , который содержит инструкции для форматирования кода в соответствии с правилами пресета Laravel. Проблема в том, что такое форматирование возможно при пуше изменений, но не локальной машине. Я уже рассказывал, как использовать CodeSniffer, но, к сожалению, этот инструмент не включает всех нужных правил. Обратимся к PHP CS Fixer.

Конфигурация, приведённая в данном материале является результатом пересмотра каждого правила вышеупомянутого пресета, и использования соответствий PHP CS Fixer. Кроме того, я добавил некоторые правила из Symfony. Например, мне не хочется видеть бесполезную директиву use , а также бесполезные else и return . При этом docblock-и читабельнее, когда они сгруппированы. Поехали.

1. Устанавливаем PHP CS Fixer глобально:

$ composer global require friendsofphp/php-cs-fixer

Убедитесь, что в Вашей переменной PATH указан каталог двоичных файлов Composer-а. Размещение каталога зависит от платформы. Пример для некоторых систем Unix:

$ export PATH="$PATH:$HOME/.composer/vendor/bin"

2. Создаём в корневой директории проекта файл .php_cs.dist и копируем в него следующий код:

exclude(['bootstrap', 'node_modules', 'public', 'storage', 'vendor']) ->notPath('*') ->in(__DIR__); return PhpCsFixer\Config::create() ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => true, 'blank_line_after_namespace' => true, 'blank_line_after_opening_tag' => true, 'blank_line_before_return' => true, 'braces' => true, 'cast_spaces' => true, 'class_attributes_separation' => true, 'class_definition' => true, 'concat_space' => ['spacing' => 'none'], 'declare_equal_normalize' => ['space' => 'none'], 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => ['closure_function_spacing' => 'one'], 'function_typehint_space' => true, 'heredoc_to_nowdoc' => true, 'include' => true, 'increment_style' => ['style' => 'post'], 'linebreak_after_opening_tag' => true, 'list_syntax' => ['syntax' => 'short'], 'lowercase_cast' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, 'magic_constant_casing' => true, 'magic_method_casing' => true, 'method_argument_space' => true, 'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'], 'native_function_casing' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_closing_tag' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_blank_lines' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => true, 'no_multiline_whitespace_around_double_arrow' => true, 'no_short_bool_cast' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_around_offset' => true, 'no_spaces_inside_parenthesis' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_unneeded_control_parentheses' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, 'ordered_imports' => ['sort_algorithm' => 'length'], 'php_unit_fqcn_annotation' => true, 'phpdoc_align' => ['align' => 'vertical'], 'phpdoc_indent' => true, 'phpdoc_inline_tag' => true, 'phpdoc_no_access' => true, 'phpdoc_no_package' => true, 'phpdoc_no_useless_inheritdoc' => true, 'phpdoc_order' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, 'psr4' => true, 'self_accessor' => true, 'short_scalar_cast' => true, 'simplified_null_return' => true, 'single_blank_line_at_eof' => true, 'single_blank_line_before_namespace' => true, 'single_class_element_per_statement' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'space_after_semicolon' => true, 'standardize_not_equals' => true, 'switch_case_semicolon_to_colon' => true, 'switch_case_space' => true, 'ternary_operator_spaces' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => false, 'visibility_required' => true, 'whitespace_after_comma_in_array' => true, ]) ->setFinder($finder); 

Разбирать каждое правило не буду, поскольку всё описано в официальной документации. Но на всякий случай замечу, что одни и те же правила могут иметь разные названия в StyleCI и PHP CS Fixer. Их не так уж и много, но всё же есть.

3. Добавим в .gitignore файл .php_cs.cache . На данный момент такого файла в проекте не существует, но он будет создаваться после каждого запуска fixer-а, и «тащить» его в репозиторий нет никакого смысла.

4. Открываем консоль, запускаем команду

5. Открываем PhpStorm Settings -> Tools -> External Tools и нажимаем на знак + в левом верхнем углу:

Заполняем поля, как на скрине ниже (в поле Program вставляем путь, скопированный на шаге 4):

Затем нажимаем Ok и затем Apply . Переходим в Settings -> Languages & Frameworks -> PHP -> Quality Tools :

Открываем вкладку PHP CS Fixer в правой части окна и кликаем на кнопке с многоточием справа от поля Configuration :

В открывшемся окне нажимаем на иконке директории справа от поля PHP CS Fixer path и снова выбираем пусть к установленному на Вашей машине бинарному файлу php-cs-fixer. Проверить, правилен ли путь, можно кнопкой Validate — внизу окна должно появиться соответствующее сообщение:

Нажимаем Apply и потом Ok .

Следующий шаг — «пояснить», где находится файл кофиграции. Заходим в Settings -> Editor -> Inspections и отмечаем чекбокс PHP -> Quality Tools -> PHP CS Fixer validation :

Если правила позволяют (а в нашем случае это так), ставим галочку напротив Allow risky rules , кликаем на значок обновления справа от поля Ruleset и выбираем из списка Custom :

Там же нажимаем на кнопку с многоточием. В открывшемся окне Custom Coding Standard выбираем путь к файлу .php_cs.dist в корне проекта:

Подтверждаем выбор нажав Ok и затем Apply.

Всё, что осталось — назначить горячие клавиши. Открываем Settings -> Keymap и создаём шорткат для php-cs-fixer:

Как использовать:
  1. Для форматирования текущего файла используйте комбинацию горячих клавиш, которая была создана на предыдущем шаге.
  2. Для форматирования всех файлов* проекта откройте консоль, перейдите в корень проекта и запустите команду php-cs-fixer fix.

*Не будут отформатированы файлы, которые мы исключили в методах exclude и notPath в файле конфигурации .php_cs.dist

Источник

Читайте также:  Svg filter color css
Оцените статью