Jump to content

Prestashop auto code completion for PHPStorm IDE solution


Recommended Posts

I have been working some time now with Prestashop and before some months switched to develop with PHPStorm, the best and most complete PHP IDE out there.

 

Unfortunately, I had always issues with code completion in Prestashop, which is based on how Prestashop uses the override class model. One example: 

 

The code for the class "Cart" that is instantiated as object is residing in the core file classes/Cart.php, the core class however is not named "Cart" but "CartCore". Only when a class is overriden, it is named "Cart" and inherited from "CartCore" and as that, an IDE can create this association only by that time. Additionally, Prestashop's PHPDoc is incomplete and where it exists, the wrong return classes are sometimes specified etc. 

 

To ease my development with Prestashop and PHPStorm and make code completion work a great way nearly everywhere, since I couldn't find the slightest solution anywhere, I went into creating an "extension" that helps achieve that. 

 

You can download it here and integrate it into your PHPStorm project the way it is described and you will have immediately code completion for almost any instantiated class, $this variables and more. 

 

https://github.com/dkarvounaris/PHPStorm-CC-PrestaShop

 

It's not covering 100% yet, but is nearly complete and should have everything that is daily required.

 

Please let me know if there is something to improve it. Contributions are welcomed too. 

 

I hope, this will be helpful to many. 

Edited by innovacy (see edit history)
  • Like 12
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
  • 3 months later...

Hi

 

I'm looking for such extension, unfortunatly github does not work.

 

Could you republish it somewhere else or send by email ?

 

Regards

 

David

 

Hi David?

 

Why isn't it working for you? Try again maybe, it works for me.

 

Here is a direct link to the zip file: https://github.com/dkarvounaris/PHPStorm-CC-PrestaShop/archive/master.zip

 

Please let me know if this one works, before I upload it somewhere else.

 

Best Regards,

Dimitri

Link to comment
Share on other sites

Btw, here is an alternative way, that might be preferred by some, to use it in PHPStorm, as the autocompletion support won't be in your project view and you can have it in a central location more project-independent, making updates in all your projects possibly easier.

 

In PHPStorm go under File -> Settings -> PHP. There click on the "+" under "Include Path" and add the folder in which you have stored the sources.

Edited by innovacy (see edit history)
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 3 weeks later...
  • 2 weeks later...
  • 3 months later...

Hi,
 
I wrote my own version. It supports every classes from PrestaShop into only one file.
 
You can have a look and GitHub: https://github.com/julienbourdeau/PhpStorm-PrestaShop-Autocomplete
 
Thanks to @innovacy for research and original idea.

 

I'll keep this project up to date since I use PhpStorm. Feedback is very much appreciated.

Explanation in French are also available (follow the link on GitHub)

 

Julien

  • Like 1
Link to comment
Share on other sites

Hello Julien!

 

I really enjoy, that my idea has been helpful to you and so many others and thank you that you referenced my work!

 

When I first wrote it, I thought about creating one file with all classes. And it seemed simpler that way. However, there was reasons why I finally went with the idea of creating separate files.

 

My solution allows to set one of these files as "text only" in PHPStorm and that way deactivate selectively the autocompletion through these files specific by each project. This might be useful in cases, when someone needs/wants to make it part of the project and receives the "Multiple declarations" warning, as example because he might have already overwritten the class. I like to have this luxury to deal per project without modifying the autocompletion files.

 

Additionally, I'm going a bit further, fixing some errors that have existed in Prestashop's source at some point (or might still), that could selectively make autocomplete fail, like in cases of a return value that is used, because it's PHPDoc declaration was wrong. One such example is "Collection" and "PrestashopCollection".

 

It contains also the one or other additional PHPDoc fix. Ultimately, I have been submitting fixes to the Prestashop repository for these.

 

I would like if developers keep contributing and using my solution, as I believe it is still a very useful extension for those working extensively in several Prestashop projects. I'm keeping it up to date when there needs something to be updated or someone contributes.

 

Btw, I like your README, feels more straightforward in yours. Maybe I should rework mine ;)

 

Dimitri

 

https://github.com/dkarvounaris/PHPStorm-CC-PrestaShop

Edited by innovacy (see edit history)
  • Like 1
Link to comment
Share on other sites

Hi Innovacy,

 

I don't handle override indeed, since I work mostly on the core I didn't have this issue yet. I guess people will have to comment/remove lines in the file. I'll try to find a better idea.

 

If you fix phpdoc declaration, feel free to make a pull request, we'll be happy to accept it. It will help a lot of people :)

 

 

Julien

Link to comment
Share on other sites

@innovacy

 

Hi, which PHPDoc comments are you going to fix? I was recently thinking about contributing fixed PHPDocs too. For example proper PHPDoc as

 AdminControllerCore, protected $object

 would be very useful; 

/*@var ObjectModel */
Link to comment
Share on other sites

@gytske

Well, don't wait for my fixes, just go on and submit to the Prestashop repository what you think should be fixed, so anyone profits asap.

 

@Julien

I have submitted several fixes in the past, which was accepted. I also have several other core fixes or improvements laying around, just didn't find the time yet to check through them all again, filter (as some might be in the meanwhile obsolete) and prepare them properly for the official repository, planning to do it soon though. 

Link to comment
Share on other sites

  • 4 weeks later...

Hello,

 

I added these classes some year before, for same reasons (autocompletion), as you can see in these commits from 2011/2012 :

https://github.com/PrestaShop/PrestaShop/commit/c1c857b586bfac3ba956eafccd6a9e75be5d4c0c

https://github.com/PrestaShop/PrestaShop/commit/0210a5af36814c7b3422ea5d0474ac3d9553b6c8

https://github.com/PrestaShop/PrestaShop/commit/11a180175c4db40995b77f8def1c09ff2e5fd868

https://github.com/PrestaShop/PrestaShop/commit/5464c1d0ae9d50142429e3068145ff01dc489562

 

The other reason was to show developpers how to override the code in a "clean" way.

 

Sadly, Remi removed them in this commit https://github.com/PrestaShop/PrestaShop/commit/0cd10335271a9ef9f353a4d965313e812174a98b for bad reasons (IMO).

 

So I'm sad when I read "Thanks to innovacy for research and original idea." :( (Well I'm kidding, I'm not sad, but it hurts a bit my feelings :D)

 

PS : PHPStorm FTW !

Link to comment
Share on other sites

Hi Raphaël,
 
I'm not sure PrestaShop should override every classes (his own code especially) just for an IDE.

 

If a developer he's looking for a clean way to override PrestaShop's behavior, he should just check out the doc (http://doc.prestashop.com/display/PS16/Overriding+default+behaviors)

 

@innovacy introduced a way to add it as an external library, which seems perfect to me.

 

Best regards,

Link to comment
Share on other sites

Hi Raphaël,

 

I'm not sure PrestaShop should override every classes (his own code especially) just for an IDE.

 

If a developer he's looking for a clean way to override PrestaShop's behavior, he should just check out the doc (http://doc.prestashop.com/display/PS16/Overriding+default+behaviors)

 

@innovacy introduced a way to add it as an external library, which seems perfect to me.

 

Best regards,

Hi Julien,

 

yes but 3 years ago, people were not aware about the override feature, so it was a part of the education plan. But this argument is now invalid I agree :)

 

Don't forget that PrestaShop is using eval() without these files, and eval() = satan :ph34r:

Edited by Raphaël Malié (see edit history)
Link to comment
Share on other sites

  • 6 months later...
×
×
  • Create New...