mmoreram / php-formatter

PHP Formatter is a PHP developer friendly set of tools
MIT License
166 stars 17 forks source link

Format php code stored in string #23

Closed rizrmd closed 7 years ago

rizrmd commented 8 years ago

How do i format php code stored in string?

viscat commented 8 years ago

+1

matt-usurp commented 7 years ago

I recently took a look at the tests and found that sorting a string would be this easy:

https://github.com/mmoreram/php-formatter/blob/master/tests/PHPFormatter/Sorter/UseSorterTest.php#L64

I am guessing its exactly the same for header formatting, so may I suggest you take a look at the tests yourself? Logically it needs to be tested somehow so thats where I would go first.

mmoreram commented 7 years ago

closing as @matt-usurp already answered it properly :)

rizrmd commented 7 years ago

Maybe we should put it on docs, since this functionality will be used often.

On Sat, Nov 26, 2016 at 6:33 PM, Marc Morera notifications@github.com wrote:

closing as @matt-usurp https://github.com/matt-usurp already answered it properly :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mmoreram/php-formatter/issues/23#issuecomment-263058575, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHtXVjU1zwIEMwTWDtrosUasyzOtd5kks5rCBkMgaJpZM4JD2Ug .

-- Thanks, Rizky

onet4 commented 2 years ago

The above link is dead. Would be nice to see examples.

rizrmd commented 2 years ago

This should be the link: https://github.com/mmoreram/php-formatter/blob/master/tests/PHPFormatter/Fixer/UseSortFixerTest.php

onet4 commented 2 years ago

Thanks but it's hard to figure out how to use it.

$code = file_get_contents( __DIR__ .'/test-code.php' );
use Mmoreram\PHPFormatter\Fixer\UseSortFixer;
use Mmoreram\PHPFormatter\Fixer\StrictFixer;
$useSortFixer = new UseSortFixer();
print_r($useSortFixer->fix($code));
$strictFixer  = new StrictFixer(true);
print_r($strictFixer->fix($code));

But this doesn't seem to fix anything, especially indents.