Completed
Pull Request — develop (#349)
by ANTHONIUS
06:14
created

InvitationHandlerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 3
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license    MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
10
/** */
11
namespace Organizations\Factory\Controller\Plugin;
12
13
use Interop\Container\ContainerInterface;
14
use Organizations\Controller\Plugin\InvitationHandler;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface;
17
18
/**
19
 * Factory for an InvitationHandler.
20
 *
21
 * @author Mathias Gelhausen <[email protected]>
22
 * @author Anthonius Munthi <[email protected]>
23
 * @since  0.19
24
 */
25
class InvitationHandlerFactory implements FactoryInterface
26
{
27
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
28
    {
29
        /* @var $container \Zend\Mvc\Controller\PluginManager */
30
        $services   = $container->getServiceLocator();
31
        $validator  = $services->get('ValidatorManager')->get('EmailAddress');
32
        $mailer     = $container->get('Mailer');
33
        $translator = $services->get('translator');
34
        $repository = $services->get('repositories')->get('Auth/User');
35
        $generator  = $services->get('Auth/UserTokenGenerator');
36
37
        $plugin = new InvitationHandler();
38
        $plugin->setEmailValidator($validator)
39
            ->setMailerPlugin($mailer)
0 ignored issues
show
Documentation introduced by
$mailer is of type object<Zend\Stdlib\DispatchableInterface>, but the function expects a object<Core\Controller\Plugin\Mailer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
            ->setTranslator($translator)
0 ignored issues
show
Documentation introduced by
$translator is of type object|array, but the function expects a object<Zend\I18n\Translator\Translator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
            ->setUserRepository($repository)
42
            ->setUserTokenGenerator($generator);
0 ignored issues
show
Documentation introduced by
$generator is of type object|array, but the function expects a object<Auth\Service\UserUniqueTokenGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
44
        return $plugin;
45
    }
46
47
    /**
48
     * Creates an InvitationHandler
49
     *
50
     * @param ServiceLocatorInterface $serviceLocator
51
     *
52
     * @return InvitationHandler
53
     */
54
    public function createService(ServiceLocatorInterface $serviceLocator)
55
    {
56
        return $this($serviceLocator,InvitationHandler::class);
57
    }
58
}
59