badoo / phpcf Goto Github PK
View Code? Open in Web Editor NEWPHP Code Formatter
License: MIT License
PHP Code Formatter
License: MIT License
If you have a code like and use phpcbf
do
....
while( $condition == true );
it will be converted to
do {
....
} while( $condition == true ) {
}
The following code makes phpcf produce issues about wrong indent like
Expected no indent, got indent of 2 spaces on line 4
It would be nice if column number is also provided like in other issue types:
Expected one space after class/interface/trait name on line 3 column 8
For ease of using vim quickfix window
<?php
class Ololo {
var
$m =
NULL;
FUNCTION
do_something_marvelous
(
$arg1
, $arg2
)
{
}
}
In phpstorm there is ability to use phpcs (PHP CodeSniffer) to check php code style and highlight statements that does not meet code style rules. Phpstorm has full integration with phpcs (Settings > Language & Frameworks > PHP > Code Sniffer). Can you please make compatible output format of phpcf with phpcs tool to make it possible to use phpcf tool in phpstorm instead of phpcs.
Details:
Во время сборки получаю ошибку /Users/nikita/Desktop/phpcf-php7/phpcf-src/ext/phpcf.c:11:10: fatal error: 'ext/standard/php_smart_str.h' file not found
ОС: os x el capitan 10.11.15
PHP: 7.07
Было бы здорово чтобы оно обрабатывалось также как в PHP - можно было после __halt_compiler(); писать что-то, к чему бы не применялось форматирование.
PHP7 null coalescing operator (??) - stuck in "CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN" state:
cat ternary.php
<?php
$a = $b ?? $c;
$a = 0;
?>
phpcf check -d ternary.php
1 T_OPEN_TAG <?php CTX_PHP
3 T_WHITESPACE \n\n CTX_PHP
3 T_VARIABLE $a CTX_PHP
3 T_WHITESPACE CTX_PHP
3 = = CTX_PHP
3 T_WHITESPACE CTX_PHP
3 T_VARIABLE $b CTX_PHP
3 T_WHITESPACE CTX_PHP
3 ? ? CTX_PHP / CTX_TERNARY_BEGIN
3 ? ? CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
3 T_WHITESPACE CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
3 T_VARIABLE $c CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
3 ; ; CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 T_WHITESPACE \n CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 T_VARIABLE $a CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 T_WHITESPACE CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 = = CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 T_WHITESPACE CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 T_LNUMBER 0 CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
4 ; ; CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
6 T_WHITESPACE \n\n CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN
ternary.php:Internal formatter error: final state must be CTX_PHP or CTX_DEFAULT, got 'CTX_PHP / CTX_TERNARY_BEGIN / CTX_TERNARY_BEGIN'
<?php
class A
{
public function find(): ?array
{
}
}
Internal formatter error: final state must be CTX_PHP or CTX_DEFAULT, got 'CTX_PHP / CTX_CLASS / CTX_CLASS_METHOD_D / CTX_TERNARY_BEGIN'
Tried to use your tool, seem that it works but and when I do a git diff I see a lot of ^M
i++) {^M
I used the tool like this
find . -name "*.php" -exec phpcf apply {} \;
Hi, can i reindent code with phpcf?
Thank you very much for your attention!
Formatting of example like
<?php
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/header.php");
$APPLICATION->SetPageProperty(
"title",
"TItile"
);
$APPLICATION->SetPageProperty("NOT_SHOW_NAV_CHAIN", "Y");
$APPLICATION->SetTitle("Index");
?>
<div class="row">
<div class="col-xs-6 col-sm-4 index_block">
<div class="title_index_block"><span>menu</span></div>
<?php
$APPLICATION->IncludeFile(
$APPLICATION->GetCurDir() . "/include/include.php",
Array(),
Array(
"MODE" => "html",
"NAME" => "Content",
)
);
?>
</div>
causes internal formatter error.
Can phpcf traverse directories or can it only operate on one file each? How to traverse directories?
It is not clear how I can select rules or add own rules. I am not sure if I understand the source.
What exactly is the config file? How do I select which rules to apply? How to define new rules?
Example: how to replace all space indentations with tabs and reflow the code without unneccessary linebreaks?
Thanks!
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/impl/Fsm.php on line 142
Call Stack: 0.0004 397920 1. {main}() /data/data/com.termux/files/home/.local/bin/phpcf:0
0.0274 422712 2. include('phar:///data/data/com.termux/files/home/.local/bin/phpcf/phpcf.php') /data/data/com.termux/files/home/.local/bin/phpcf:2 0.0656 587624 3. Phpcf\Cli\Handler->handle(???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/phpcf.php:10 0.1738 1397672 4. Phpcf\Cli\ActionApply->handle(???, ???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/cli/Handler.php:110
0.1738 1397672 5. Phpcf\Cli\ActionApply->handleInternal(???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/cli/AbstractAction.php:25 0.1739 1398048 6. Phpcf\Formatter->formatFile(???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/cli/ActionApply.php:19
0.1769 2040672 7. Phpcf\Formatter->format(???, ???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/Formatter.php:111
0.1774 2040832 8. Phpcf\Impl\Formatter->format(???, ???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/Formatter.php:253
22.1273 88289056 9. Phpcf\Impl\Formatter->process() phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/impl/Formatter.php:240
33.3083 131321976 10. Phpcf\Impl\Formatter->nextParsedToken() phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/impl/Formatter.php:1934
33.3083 131321976 11. Phpcf\Impl\Formatter->setupContext() phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/impl/Formatter.php:1844
33.3083 131321976 12. Phpcf\Impl\Fsm->transit(???) phar:///data/data/com.termux/files/home/.local/bin/phpcf/src/impl/Formatter.php:1850
Input source code:
<?php
class Foo extends Bar
{
/**
* Execution callback
* @param string $world
* @return string
*/
public function hello($world)
{
return $world;
}
}
Applying formatter:
./phpcf apply ~/Projects/Foo.php
Result:
<?php
class Foo extends Bar
{
/**
* Execution callback
* @param string $world
* @return string
*/
public function hello($world)
{
return $world;
}
}
Expected result:
<?php
class Foo extends Bar
{
/**
* Execution callback
* @param string $world
* @return string
*/
public function hello($world)
{
return $world;
}
}
phpcf complains, to use preg_split() instead of deprecated split() on code that looks like:
$desert['split'] = $banana->split || false;
You likely need to add code that checks for an opening ( parenthesis, to ensure a function.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.