[EN] PhpStorm hacks for developers

PhpStorm is the most popular IDE for professional OXID developers.
Here we will collect some useful hacks to tmake your coding experience even better.

configure PHP version and smarty delimiters

this will help PhpStorm find possible compatibility issues in your code and correctly understand OXID’s templates.

  1. open settings and type “php language level”, then select the php version.
  2. go to settings and type “smarty” into the search bar, then select the bottom “smarty” menu item, input oxid’s custom smarty delimiters and uncheck “Smarty 3 whitespace policy”:

    Now you are ready to deal with smarty templates!

resolving dynamic paths

OXID provides multiple functions for retrieving correct paths to different directories, e.g. $oConfig->getModulesDir() for modules directory.
But PhpStorm needs some help to resolve them, otherwise you will see errors like this:

To make this work, you simply need to add a phpdoc @define comment with the relative path from current file’s directory to the modules directory.
E.g. if you are editing file “modules/mymodule/Application/Controller/Mycontroller.php” your relative path would be just going to parent directory 3 times:
/** @define "$oConfig->getModulesDir()" "../../../" */
While this is not the exact value returned by the function, PhpStorm still knows where it will point to.


mapping your _parent classes to the actual oxid classes

when extending OXID classes with modules, you have to use class declaration like this:
class myArticle extends myArticle_parent but since there is no class “myArticle_parent” available, PhpStorm can not resolve methods from parent classes.
To fix this, simply add a new “.ide-helper.php” file to your module, where you map *_parent classes to the actual class you are extending, like this:

<?php
namespace VanillaThunder\DevUtils\Application\Extend;
class Email_parent extends \OxidEsales\Eshop\Core\Email {}
class Language_parent extends \OxidEsales\Eshop\Core\Language {}

code inspections might prevent some stupid situations

lets not lie: we all copy-paste code from stackoverflow and other sources.
Sometimes the code was made for a different php version and might not work in current project or it might even contain some… more substancial issues.
Code inspections will help you identifying problems in code, like version incompatibilities or missing function arguments.
Overall code inspections will improve the quality and maintainability of your code.

You also might want to have a look at this extension: Php Inspections (EA Extended)
It provides some additional useful checks like:

  • duplicated methods, that exist in parent class
  • possible null pointer exceptions
  • undefined classes and methods
    (very useful if you copy-paste older code from this forum into newer OXID versions)
4 Likes

get CSS class names autocompletion

unfortunately PhpStorm does not understand OXID’s oxscript and ‘oxstyle’ tags, so it uses all avaialble stylesheets for populating autocompletion, which is not really helpful:


To fix this, we have to add some “dead” code to our template just to let PhpStorm know, which files we use in this template:
[{if 1 > 2}]<link rel="stylesheet" href="../relative/path/to/your/stylesheet.css">[{/if}]
At the current state of math and human common sense 1 will never be greater than 2, so this code will never appear in templates, but PhpStorm is OK with that.