0

In the following code the @return is underlined red. I have it expecting an interface to be returned because that is what all of the different Vendor adapters implement.

 /**
 * VendorFactory constructor.
 * @param Model $model
 * @return \Traders\Interfaces\VendorAdapterInterface
 */
public function __construct(Model $model)
{
    return $this->createAdapter($model);
}

This is the code for the createAdapter which does not have the @return underlined in red.

/**
 * @param Model $model
 * @return \Traders\Interfaces\VendorAdapterInterface
 */
public function createAdapter(Model $model)
{
    $type = str_replace('App\Models\\', '', get_class($model)).'s';
    $fqcn = '\Traders\Adapters\\'.$type.'\\'.ucfirst(strtolower($model->name));
    return new $fqcn($model);
}

I have tried doing the /** docblock and letting PHPStorm enter what it believes is the return value and it just keeps giving me

@return mixed
3
  • Because $fqcn is a variable, in this case. You're not actually giving it a concrete class. Ignore storm and leave it as is or create a factory. Commented Oct 18, 2016 at 13:16
  • 4
    Wait what.. return in a constructor ? Commented Oct 18, 2016 at 13:23
  • thanks Pete that wasn't supposed to be the constructor rather an initialize method. Commented Oct 18, 2016 at 13:34

1 Answer 1

1

Your problem is the return in the constructor. Constructors do not take return values, they get executed when an instance of that class is instantiated.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks my bad wasn't supposed to be in the constructor should have been the initialize method :)
Glad to help! To be fair, i think that technically you can actually set return values on __construct functions (because they are just as normal functions) and use them like $ret = $obj->__construct(). Anyway, that's considered a bad practice and is unadvised.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.