Compatible with: IntelliJ IDEA PhpStorm
May 09, 2018
44 050
Intellij/Phpstorm PHP plugin to allow a dynamic return type from ALL method/function calls, not just static methods.
It can use either the instance type of the passed parameter, string lookup or ::class. It can also use masking and custom javascript callbacks to massage the return type to enable aliasing.
Internal signature resolution has been completely reworked to allow better chaining/stability of results. It should also play nicely with other plugin service providers etc. It can be configured for :
  • Instance method calls
  • Static method calls
  • Function calls
Full documentation with examples on github page for custom manipulation with rhino javascript versus the old mask methodology can be found here :-

Demo environment which is used to verify edge case are catered for ( example dynamicReturnTypeMeta.json etc. ) can be found here :-

Accepts the following to calculate return type
  • Parameter object instance( eg. new \DOMDocument() as a parameter instance value will infer a
    DOMDocument will be returned )
  • Parameter string type ( eg. '\DOMDocument' as a parameter string value will infer a DOMDocument
    will be returned )
  • Class constants that resolve to __CLASS__ will resolve similar to the ::class feature in 5.5 behaves.
Configuration Example dynamicReturnTypeMeta.json configuration in project root
"methodCalls": [
"class": "\\Phockito",
"method": "mock",
"position": 0
"class": "\\Phockito",
"method": "verify",
"position": 0
"class": "\\Phockito",
"method": "maskExample",
"position": 0
"mask": "Test%sModel"
"functionCalls": [
"function": "\\verify",
"position": 0
"function": "\\mock",
"position": 0
"function": "\\maskExample",
"position": 0
"mask": "Test%sModel"

Position is the parameter index to infer the return type from.
Classes and function names must be fully qualified with a leading \ as per example.
Static method calls should behave the same as instance calls.

Download plugin

Recent change notes

  • Make PhpTypeProvider3 compatible
    Fix array access on providers for basic cases.
  • Fix class constants lookup to keep compatible
    Note chaining off other plugin containers is currently broken in EAP
  • Fix static variable lookups as parameters
  • Fix lookups as parameters to script engines etc
  • Needed to remove parameter from internal function lookup as it was breaking namespaced function resolution. Regression test case has been added for this here locatable by ifInNameSpacedShouldBeMaskedMock.
2.0.8 2.0.7 2.0.6
  • Fix https://github.com/pbyrne84/DynamicReturnTypePlugin/issues/56. Constants are now looked up prior to the
    script engine.
    **NOTE** Leading \ is now stripped off the class name as it is passed to the script engine as sometimes it would
    be there and other times it would not so it should be more consistent now.
  • Fix index out of bounds.
  • Fixed masks causing issues with ::class as a parameter. This means the following mask types now work as expected.

    1. Masks that combine with a fixed type.

    2. Masks that convert to a list.
2.0.4 2.0.3 2.0.2
  • Fix ::class resolution in 141.1619
2.0.1 1.1.7
    Fixed https://github.com/pbyrne84/DynamicReturnTypePlugin/issues/39 as field is not always a field implementation so casts to interface now
    Fixed https://github.com/pbyrne84/DynamicReturnTypePlugin/issues/36 as internal kotlin to java interop was buggy
  • Allow configuration of script engines by environment variables to set paths to groovy(IDEA_GROOVY_JAR_PATH) and nashorn(IDEA_JAVASCRIPT_JAR_PATH). For javascript nashorn.jar is required for java 8 installs. For groovy groovy-all-2.2.1.jar is required. This path is only called if it cannot create using default classpath.
  • Multiple types assigned with masks
  • Alias : to \ in string parameters
  • Enable list handling in masks ( use %s[] - only handles strings( not xxx:class ) for now )
  • Fix class constant issues
  • Fix thread safety on script/config paths
  • Fix script loading race condition
1.1.2 1.1.1 1.1.0 1.0.9 1.0.8
  • Compiled with java 1.6 for compatibility
  • Fixed issues with global functions called with no leading backslash in namespaces playing with signatures and breaking completion
  • Fix ::class for php 5.5