title: Is it possible for PhpStorm to infer the return type of this method?
body: <p>I imagine I might need to add a special annotation somewhere, but I'm crossing my fingers that PhpStorm is smart enough to resolve return types given awkward inheritance patterns.</p>
  
  <p>For example, I have some code that resembles this:</p>
  
  <pre><code>&lt;?php
  
  class Collection extends \ArrayObject
  {
      public function __construct(array $items)
      {
          foreach ($items as $key =&gt; $value) {
              if (isset(static::$requiredType) &amp;&amp; !$item instanceof static::$requiredType)
                  $this-&gt;offsetSet($key, $value);
          }
      }
  
      public function getFirst()
      {
          return $this-&gt;offsetGet(0);
      }
  }
  
  class MessageCollection extends Collection
  {
      protected static $requiredType = 'Message';
  }
  
  class UserCollection extends Collection
  {
      protected static $requiredType = 'User';
  }
  </code></pre>
  
  <p>I'd like it if when I call <code>UserCollection::getFirst()</code> it inferred that a <code>User</code> was returned, while when I call <code>MessageCollection::getFirst()</code> it inferred that a <code>Message</code> was returned. Is there some annotation I could put in somewhere to achieve this result? </p>
  
  <p>My first thought was something like this:</p>
  
  <pre><code>    /**
       * @return Message|User|XXXX|YYYY|ZZZZ|AAAA|BBBB|CCCC|DDDD
       */
      public function getFirst()
      {
          return $this-&gt;offsetGet(0);
      }
  </code></pre>
  
  <p>but I imagine that would get a little ridiculous to the point of being useless as I add more collection classes.</p>