Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320130

Summary: How to customized PHP Code Format like Java Code Formatter
Product: z_Archived Reporter: Sanjay Rakholiya <sanjayr>
Component: PDTAssignee: PHP Core <php.core-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: aneganov, cyrille37, dewayneneal94, eclipse, jacek.pospychala, kubo, martin.eisengardt, natalia.bartol, omax, robert, silviya, sylvain.lecoy, ustimenko.alexander
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:
Bug Depends on: 407768    
Bug Blocks: 381650    

Description Sanjay Rakholiya CLA 2010-07-16 13:09:34 EDT
Build Identifier: 20100617-1415

I want to customized PHP code format like java code formatter. I have also facing problem with PHP code format.

Code Before Format :

<?php
if($checkCondition)
    echo 'Condition True';
else
    echo 'Condition False';
?>

Code After Format :

<?php
if($checkCondition)
echo 'Condition True';
else
echo 'Condition False';
?>

How to retain original code format with indent in control structures ?

Reproducible: Always

Steps to Reproduce:
1. In Preferences -> Java -> Code Style -> Formatter having add/edit code format option to customize coding style. 
2. In Preferences -> PHP -> Code Style -> Formatter no any option like java.
3.
Comment 1 Sylvain Lecoy CLA 2010-10-11 19:08:38 EDT
There is a very nice dropin that allows php code customization:

http://de.sourceforge.jp/projects/pdt-tools/downloads/47343/jp.sourceforge.pdt_tools.formatter.prototype_0.96.2.jar/

This should be integrated in PDT :-)

It would be a very very nice feature!
Comment 2 Cyrille CLA 2010-10-14 04:09:43 EDT
If there is no UI for customizing the php formatter, is there some files where we can change some behaviors ?

Regards
cyrille
Comment 3 Cyrille CLA 2010-10-14 04:36:15 EDT
> There is a very nice dropin that allows php code customization:
> 
> http://de.sourceforge.jp/projects/pdt-tools/downloads/47343/jp.sourceforge.pdt_tools.formatter.prototype_0.96.2.jar/
> 

I'm using this plugin with:
 Eclipse IDE for PHP Developers
  EPP PHP Feature
   PHP Development Tools (PDT) SDK Feature 2.2.1
It works fine !

We're waiting for this formatter inside PDT !

Cheers
Cyrille
Comment 4 Tilman G CLA 2012-01-13 20:28:42 EST
The original sourceforge project of the plugin seems dead but someone was so nice to put the files on
https://github.com/dmeybohm/Eclipse-PHP-Formatter
and the plugin still works! Finally code formatting!

For years now Java developers have had so many nice convenience features, like code generation (getter/setter), great refactoring features, and detailed code-formatting options. I wanna say I have seen these features already at least in 2006 when I stopped working with Java, or even earlier. In 2012 PHP developers still have to live with more or less the same features as 5 years ago.

Sorry for the rant, but can this plugin please be integrated, updated and maintained in the official PDT package, or something similar be added!
Comment 5 Sanjay Rakholiya CLA 2012-03-08 22:59:02 EST
Updated PDT code formatter plugin.

http://en.sourceforge.jp/downloads/users/0/888/pdt_tools.formatter_1.2.5.zip

We are eagerly waiting to in-built integrate this plugin with official PDT package. Its very very useful plugin for PDT.

Thanks,
Sanjay
Comment 6 Cyrille CLA 2012-04-24 12:46:48 EDT
(In reply to comment #5)
> Updated PDT code formatter plugin.
> 
> http://en.sourceforge.jp/downloads/users/0/888/pdt_tools.formatter_1.2.5.zip
> 
> We are eagerly waiting to in-built integrate this plugin with official PDT
> package. Its very very useful plugin for PDT.
> 
> Thanks,
> Sanjay

Yes it's works fine, and it's a must have plugin !
Thanks a lot !

Best regards
Cyrille.
Comment 7 Robert Gruendler CLA 2012-06-03 17:25:32 EDT
I've contacted the author of the original plugin as he is not maintaining it anymore. The license is EPL and he's fine that the sourcecode is used by other plugins, so i've integrated it into the PDT extensions which i wrote a couple of months ago: https://github.com/pulse00/PDT-Extensions

It comes with a regular updatesite, so installation and updates can be easier maintained.

The only issue i'm having with the formatter is that you can only format the whole document, and not a specific region.

If anyone wants to help with that issue, feel free to send me a pull request on github.
Comment 8 Jacek Pospychala CLA 2012-06-04 03:14:34 EDT
hi Robert,
would you be interested in donating your formatter, or maybe other parts of PDT extensions to core PDT project?
It would be great to have all the best tools for PHP developers in single place.
Comment 9 Robert Gruendler CLA 2012-06-04 03:40:45 EDT
Hi Jacek,

of course. The main reason i started the PDT extensions
was that i missed these features in pdt core.

If they can become part of PDT core, even better.

They would need some review though before merging
them as i'm only working on this in my spare time,
so the state of the project is more or less "Works for me" ;)
Comment 10 Jacek Pospychala CLA 2012-06-04 06:38:53 EDT
great, I still have to try your formatter to tell what next, but in any case we're considering lack of formatter one of key things to work on in next months.
Comment 11 Martin Eisengardt CLA 2012-07-06 03:52:37 EDT
Joining this bug as I have an extension project too. I talked to Roy some months before and (maybe because of changed project lead) some day there way no more feedback.
However I will join Roberts project now and hope that we could work together on several topics :)
Comment 12 Jacek Pospychala CLA 2012-07-06 04:39:57 EDT
to follow up on this topic, Zend also has PHP formatter for our downstream project - Zend Studio. We've been considering donating it to PDT, or dropping out completely in favor of alternative community-driven formatter (e.g. Robert's).
Few weeks back Zhao has run our internal unit tests agains Robert's formatter and found that it's lacking support for PHP 5.4 and some other features, like comments formatting.
So we could either adopt that formatter and rewrite missing features or donate Zend formatter, which has issues on it's own.
I delayed this topic for now, but Natalia, our new (but very experienced) PDT committer is going to focus on formatter topic in mid August&September.

Guys, what's your take on this? How much work are you spending now on your formatter? How much effort do you think it'd be to add PHP 5.4?
I'll try to provide unit tests that we used, to get you on the same page, but this may take few days.
Comment 13 Robert Gruendler CLA 2012-07-06 04:52:45 EDT
The formatter from the PDT extensions is not written by myself, it's taken from atlantos pdt tools http://en.sourceforge.jp/projects/pdt-tools/. 

As he's not maintaining it anymore, i've contacted him and moved the code to my PDT extensions. 

It is not very likely that i'm gonna be actively developing the codebase of the formatter, as it it quite large and my resources are very limited the next few months. I have mainly moved the formatter to the PDT extensions to make at least some formatter available to the PDT community. The problems i am aware of at the moment are:

* Missing PHP 5.4 support
* Missing comment formatting
* Unable to format a region of a document, only the whole document can be formatted


It's great to hear that the PDT team has some resources to focus on this issue, as i think this is really a major drawback in comparison to other IDEs. 

So regarding which formatter to use: You'd be probably better off with the one from Zend-Studio, as it's your own codebase which would make it easier for you to maintain.
Comment 14 Alexander Ustimenko CLA 2012-07-06 05:05:00 EDT
Hi (In reply to comment #13)
> The formatter from the PDT extensions is not written by myself, it's taken from
> atlantos pdt tools http://en.sourceforge.jp/projects/pdt-tools/. 
> 

Robert, do you know it's internal codebase?

Jacek, and you?

It would be ideal
 * to merge them both somehow if they are not completely different,
 * push it as pdt formatter
 * and then add missing features

As I understand, zend`s have test, and atlantos`s -- not. I think both projects have some features, that could be merged. Even a little.

And then we will have in PDT nice built-in formatter :)
Comment 15 Martin Eisengardt CLA 2012-07-06 05:37:28 EDT
I do have some resources to help with merging (and as a high experienced java and eclipse developer I do have some background especially on formatting...)
If you need some help please contact. Someone should first revisit both and list the features so that we could help on certain topics.

On top of this I made some suggestions for pdt. I do not know if Zhao or Roy forwarded them and I do not know if we should talk about it in this bug. However Robert and the others will prepare an email on other topics. I am especially working on a maven integration and project templates for various frameworks. And we are in contact with the composer/packagist guys.
Feel free to contact robert and me directly or simply let us talk about it in this bug :)

And finally I am active in the php-fig group (as community member, not as a voter). There are some things that you should revisit. Especially https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md and https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md could result in an alternative profile for the pdt formatting.
There are several frameworks that will commit to the PSRs: http://www.php-fig.org/
Although this won't ever be an "official" php standard at least an option to use the PSR formatting would be welcome.
Comment 16 Alexander Ustimenko CLA 2012-07-06 12:37:38 EDT
(In reply to comment #15)
> I do have some resources to help with merging (and as a high experienced java
> and eclipse developer I do have some background especially on formatting...)
> If you need some help please contact. Someone should first revisit both and
> list the features so that we could help on certain topics.
> ....
> And finally I am active in the php-fig group (as community member, not as a
> voter). There are some things that you should revisit. Especially
> ...
> http://www.php-fig.org/
> Although this won't ever be an "official" php standard at least an option to
> use the PSR formatting would be welcome.

Martin, thank you a lot for your help.

In the meantime any standards could be later presented as some xml-settings/ready patterns, that could be easily preinstalled and/or exchanged.

The main problem as we have now is to find those "Someone should first revisit both" :)
Comment 17 Alexander Ustimenko CLA 2012-07-06 12:42:46 EDT
Btw, does someone knows some central place to store people`s achievements?

For example for code we have github. But where do we fix, that someone spent some effort for community and produce something. Then another people can just say tnx for it.

Modesty is evil & world must know its heroes :)

Everyday we use good products from community, but do we know who gives us them?

I think if something like this will be -- it could be a nice motivation.
Comment 18 Martin Eisengardt CLA 2012-07-06 14:31:14 EDT
Actually I do not have zend studio and do not have access to the code base. So I cannot be the one that "revisits both". I do not know if there is a chance to get the sources of the zend studio codebase of the formatter. Should be someone from zend actually?

Do not know how to store such an achivement.
Comment 19 Alexander Ustimenko CLA 2012-07-06 14:33:03 EDT
(In reply to comment #18)
> Actually I do not have zend studio and do not have access to the code base. So
> I cannot be the one that "revisits both". I do not know if there is a chance to
> get the sources of the zend studio codebase of the formatter. Should be someone
> from zend actually?
> 
> Do not know how to store such an achivement.

Hey, guys from Zend, when will you plan to send formatter code to github?
Comment 20 Robert Gruendler CLA 2012-07-07 07:12:43 EDT
(In reply to comment #17)
> Btw, does someone knows some central place to store people`s achievements?
> 

there's this page here: http://www.eclipse.org/pdt/whois.php which is not really up-to-date ;)
Comment 21 Alexander Ustimenko CLA 2012-07-07 12:45:21 EDT
(In reply to comment #20)
> (In reply to comment #17)
> > Btw, does someone knows some central place to store people`s achievements?
> > 
> 
> there's this page here: http://www.eclipse.org/pdt/whois.php which is not
> really up-to-date ;)

Robert, it's for eclipse project only and there are no people :(

I mean central in our world -- Earth :)
Comment 22 Toshihiro Izumi CLA 2012-07-07 22:54:17 EDT
(In reply to comment #13)
>So regarding which formatter to use: You'd be probably better off with the one
>from Zend-Studio, as it's your own codebase which would make it easier for you
>to maintain.

+1 ;-)

I don't know the formatter of ZendStudio at all, but I think my formatter has no advantages against it.

(In reply to comment #12)
>So we could either adopt that formatter and rewrite missing features or donate
>Zend formatter, which has issues on it's own.

IMO,
primary: donate Zend formatter
secondary: port JDT formatter (even if it is difficult)
lower: adopt community-driven formatter
lowest: adopt my formatter

If Zend formatter is donated, Zend will gain a chance that it will be supported by community, I guess.

--
atlanto
http://blog.goo.ne.jp/atlanto/
Comment 23 Robert Gruendler CLA 2012-07-13 06:44:06 EDT
I didn't have time to look at it in detail, but for the record, i've found another project implementing a formatter:

http://code.google.com/p/pdt-code-formatter/
Comment 24 Jacek Pospychala CLA 2012-07-16 04:50:40 EDT
(In reply to comment #15)
> And finally I am active in the php-fig group (as community member, not as a
> voter). There are some things that you should revisit. Especially
> https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
> and
> https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
> could result in an alternative profile for the pdt formatting.

fyi,
there's bug 381650 open to add PSR-1/2 support in PDT
Comment 25 Alexander Ustimenko CLA 2012-07-16 07:25:22 EDT
(In reply to comment #24)
> (In reply to comment #15)
> > And finally I am active in the php-fig group (as community member, not as a
> > voter). There are some things that you should revisit. Especially
> > https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
> > and
> > https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
> > could result in an alternative profile for the pdt formatting.
> 
> fyi,
> there's bug 381650 open to add PSR-1/2 support in PDT

Jacek, can we make it dependent of this bug? As I see -- you are it's author.
Comment 26 Robert Gruendler CLA 2012-09-24 02:50:22 EDT
I've been looking into the 2 available formatters this weekend. What i can say for now is that the Zend formatter has at least implemented newer PHP features like traits. I needed to extend that yesterday for the one from the PDT extensions plugin.

As the Zend formatter isn't open source, i can't say how easy it is to maintain, but PDT Extension formatter has some huge classes and is not documented, so extending it takes a while.

Anyway, i think it would be great if we could find a solution for this, as other IDEs start shipping support for psr-1 and psr-2 formatters too.
Comment 27 Jacek Pospychala CLA 2012-09-24 03:14:58 EDT
Studio formatter isn't easy to maintain either.
I'm very sorry that there's still no progress on this but we're extremely busy with other things. I'd like to see this issue back on the agenda until the end of the year.
Comment 28 Robert Gruendler CLA 2012-09-24 12:57:49 EDT
Alright, from my point of view the PDT-Extension formatter lacks 2 things at the moment:

1. Region based formatting (from what i can see it requires some substantial effort to implement this)
2. Full support for traits (the precedenseStatement isn't implemented yet).

Until you have more time later this year, i would suggest that we move our formatter to pdtextensions core (maybe move the other stuff from PDT-extensions there too like class wizard etc). I'll go into more details on this in the pdt-extensions mailing list.
Comment 29 john jone CLA 2013-03-12 08:31:52 EDT
There is very nice droping that allow PHP code customize
Comment 30 Jacek Pospychala CLA 2013-04-03 07:08:32 EDT
*** Bug 404802 has been marked as a duplicate of this bug. ***
Comment 31 Natalia Bartol CLA 2013-05-10 13:53:34 EDT
Please take a look: https://bugs.eclipse.org/bugs/show_bug.cgi?id=407768 Zend Studio’s Code Formatter contribution to PDT
Comment 32 Jacek Pospychala CLA 2013-05-17 12:37:58 EDT
folks,

just to let you know, the new formatter for PDT has been already added and is ready to give it a try.
It can be installed from pdt nightly repository at
http://download.eclipse.org/tools/pdt/updates/nightly
Comment 33 Jacek Pospychala CLA 2013-05-24 11:39:48 EDT
Marking this as fixed because new formatted (from Zend) has been added to PDT (see bug 407768).
Comment 34 Sylvia Tancheva CLA 2015-06-08 10:09:26 EDT
Zend formatter was added to PDT. Closing