Validating inputs in the constructor Let's take the following example. Even if the number of parameters is acceptable, I find that the code block is too long.

Are these validations at the right place? Is there a better approach in such cases?

public function __construct(
    array $config,
    EntityManager $em,
    EventDispatcherInterface $dispatcher
) {
    $this-&gt;em = $em;
    $this-&gt;dispatcher = $dispatcher;
    if (isset($config['endPoint'])) {
        $this-&gt;endpoint = $config['endPoint'];
    } else {
        throw new ConfigurationException();
    }
    if (isset($config['partnerLogin']) &amp;&amp; isset($config['partnerPass'])) {
        $this-&gt;partnerLogin = $config['partnerLogin'];
        $this-&gt;partnerPass = $config['partnerPass'];
    } else {
        throw new MissingCredentialsException();
    }
    if (isset($config['account_id'])) {
        $this-&gt;ids['account_id'] = $config['account_id'];
    } else {
        throw new MissingCredentialsException();
    }
    if (isset($config['user_id'])) {
        $this-&gt;ids['account_id'] = $config['account_id'];
    } else {
        throw new MissingCredentialsException();
    }
    $this-&gt;apiClient = $this-&gt;createApiClient();
}
I would probably create a separate validateConfig() method on the class, such that your code might look like:

public function __construct(
    array $config,
    EntityManager $em,
    EventDispatcherInterface $dispatcher
) {
    $this-&gt;validateConfig($config);  
    $this-&gt;em = $em;
    $this-&gt;dispatcher = $dispatcher;
    $this-&gt;endpoint = $config['endPoint'];
    // set other config-driven properties here
    $this-&gt;apiClient = $this-&gt;createApiClient();
}

protected function validateConfig($config) {
    if (!isset($config['endPoint'])) {
        throw new ConfigurationException();
    }
    if (!isset(
        $config['partnerLogin'],
        $config['partnerPass'],
        $config['account_id'],
        $config['user_id']
    ) {
        throw new MissingCredentialsException();
    }
}


However, that might not be getting you where you ultimately would like to go.  I would suggest that with a config with as many "properties" (your array keys) as you have, that you might consider creating an actual config class to be passed to constructor. This would allow you to type hint against the object type and place logic for validating the config into its own class.  This class would then be 100% assured the dependencies it needs in its constructor are met.

This approach could easily be achieved without much change to the calling code.  Instead of something like:

$object = new YourClass($config, $em, $dispatcher);


You could simply do:

$object = new YourClass(
    new YourClassConfig($array),
    $em,
    $dispatcher
);


Also, if you are going through the trouble of validating dependencies in this manner, is only looking for presence of an array value being set going far enough to make sure your object is set up in proper state? What if these values are set to empty strings or other non-sensical values for your context?