Passed
Push — master ( 47d5af...19bb20 )
by Rob
01:32
created

Factory/Adapter/AbstractImageResizerFactory.php (1 issue)

1
<?php
2
3
namespace Rvdlee\ZfImageResizer\Factory\Adapter;
4
5
use Interop\Container\ContainerInterface;
6
use Zend\ServiceManager\Factory\FactoryInterface;
7
use Zend\Validator\ValidatorChain;
8
9
abstract class AbstractImageResizerFactory implements FactoryInterface
10
{
11
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
12
    {
13
        /** @var array $config */
14
        $config = $container->get('config');
15
16
        $binaryOptions = [];
17
        if (isset($config['rvdlee']['zf-image-resizer']['binary-options'])) {
18
            $binaryOptions = $config['rvdlee']['zf-image-resizer']['binary-options'];
19
        }
20
21
        $validatorChain = [];
22
        if (isset($config['rvdlee']['zf-image-resizer']['validator-chain'])) {
23
            $validatorChainConfigs = $config['rvdlee']['zf-image-resizer']['validator-chain'];
24
25
            $validatorChain = new ValidatorChain();
26
            /** @var array $validatorChainConfig */
27
            foreach ($validatorChainConfigs as $validatorChainConfig) {
28
                if (class_exists($validatorChainConfig['name'])) {
29
                    $validatorConfig = isset($validatorChainConfig['options']) ? $validatorChainConfig['options'] : [];
30
                    $validator = new $validatorChainConfig['name']($validatorConfig);
31
                    $validatorChain->attach($validator);
32
                }
33
            }
34
        }
35
36
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array($binaryOptions, $validatorChain) returns the type array<integer,Zend\Valid...datorChain|array|mixed> which is incompatible with the return type mandated by Zend\ServiceManager\Fact...ryInterface::__invoke() of object.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
37
            $binaryOptions,
38
            $validatorChain
39
        ];
40
    }
41
}