Skip to content

howto - add type hinting to phpstorms generated setter method

A colleague of me forwarded me this super cool solution/template to remove one of the little annoying corners of the great PHPStorm IDE (beside the sad fact, that it is closed source software of course).
The template is fixing the problem with the generated setter methods and the missing type hinting.

Open PhpStorm's Preferences and "File and Code Templates" menu, under the "Code" tab there's an option called "PHP Setter Method". Modify it to look like this:
#set($typeHintText = "$TYPE_HINT ")

First we check against a blacklist of primitive and other common types used in documentation.

set($nonTypeHintableTypes = ["", "string", "int", "mixed", "number", "void", "object", "real", "double", "float", "resource", "null", "bool", "boolean"])

foreach($nonTypeHintableType in $nonTypeHintableTypes)

#if ($nonTypeHintableType == $TYPE_HINT)
    #set($typeHintText = "")
#end

end

This is important because PSR-5 is coming soon, and will allow documentation of types with syntax like SplStack

if (!$TYPEHINT.matches('^((\)?[a-zA-Z\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+)+$'))

#set($typeHintText = "")

end

Next, we check if this is using the array syntax like "MyClass[]", and type hint it as a plain array

if ($TYPE_HINT.endsWith("[]"))

#set($typeHintText = "array ")

end

/** * @param ${TYPEHINT} $${PARAMNAME} */ public ${STATIC} function set${NAME}($typeHintText$${PARAM_NAME}) {

if (${STATIC} == "static")

self::$${FIELD_NAME} = $${PARAM_NAME};

else

$this->${FIELD_NAME} = $${PARAM_NAME};

end

}


source
File Template Variables

Translate to de es fr it pt ja

Version 1.0.0 of Jetbrains PhpStorm Installer for (Debian) Linux released

I started getting tired of installing phpstorm by hand again and again. Did I mention that installing is the same as updating?.
Since the ide is for php, of course I wrote the installer in php.

# simple install or update
php phpstorm.php path/to/linux/php/version.tar.gz 

# install or update and change group
#   good if you created a "developer" group on your system
php phpstorm.php path/to/linux/php/version.tar.gz your_group_name

I hope you are going to enjoy it.

Translate to de es fr it pt ja

Arch Linux PHPStorm (JetBrains) OpenJDK Update and No Font

I had updated my arch linux as usual and got an update for openJDK.

java -version
java version "1.7.060"
OpenJDK Runtime Environment (IcedTea 2.5.0) (Arch Linux build 7.u60
2.5.0-2-x86_64)
OpenJDK 64-Bit Server VM (build 24.60-b09, mixed mode)

After that, I started my phpstorm (I am working with the window manager i3wm and the screen looks strange. Everything was there, except for the fonts - I could not read anything (and I am not that cool to code without seeing the code :D-).
After log of tryouts, I found a simple and suitable solution.
sudo echo "-Dawt.useSystemAAFontSettings=gasp" > /usr/share/phpstorm/bin/phpstorm64.vmoptions

This has resolved the issue on my machine. There are some hints available, but I needed only one line, hope it suits your needs too.

Translate to de es fr it pt ja

extended support for InteiilJ IDEA (means also phpstorm) for notion window manager

Just found the following block in the /etc/notion/cfgkludges.lua file (arch linux).

-- InteiilJ IDEA - I wonder whether we should do this for *all* sun-awt-X11-XWindowPeer windows
defwinprop {
    class = "jetbrains-idea-ce",
    instance = "sun-awt-X11-XWindowPeer",
    transientmode = "current",
}
defwinprop {
    class = "jetbrains-idea-ce",
    instance = "sun-awt-X11-XDialogPeer",
    transientmode = "current",
}
defwinprop {
    class = "jetbrains-idea",
    instance = "sun-awt-X11-XWindowPeer",
    transientmode = "current",
}
defwinprop {
    class = "jetbrains-idea",
    instance = "sun-awt-X11-XDialogPeer",
    transient_mode = "current",
}

Looks like they found a reason why working with phpstorm in notion was not that easy.

Translate to de es fr it pt ja