EventManagerFactory::createService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Zend Framework (http://framework.zend.com/)
4
 *
5
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7
 * @license   http://framework.zend.com/license/new-bsd New BSD License
8
 */
9
10
namespace Abacaphiliac\Zend\EventManager\PluginManager;
11
12
use Zend\EventManager\EventManager;
13
use Zend\EventManager\SharedEventManagerInterface;
14
use Zend\ServiceManager\AbstractPluginManager;
15
use Zend\ServiceManager\Exception\ServiceNotFoundException;
16
use Zend\ServiceManager\FactoryInterface;
17
use Zend\ServiceManager\ServiceLocatorInterface;
18
19
class EventManagerFactory implements FactoryInterface
20
{
21
    /**
22
     * Create an EventManager instance
23
     *
24
     * Creates a new EventManager instance, seeding it with a shared instance
25
     * of SharedEventManager.
26
     *
27
     * @param  ServiceLocatorInterface $serviceLocator
28
     * @return EventManager
29
     * @throws ServiceNotFoundException
30
     */
31 4
    public function createService(ServiceLocatorInterface $serviceLocator)
32
    {
33 4
        if ($serviceLocator instanceof AbstractPluginManager) {
34 3
            $serviceLocator = $serviceLocator->getServiceLocator();
35 3
        }
36
        
37
        /** @var SharedEventManagerInterface $sharedEventManager */
38 4
        $sharedEventManager = $serviceLocator->get('SharedEventManager');
39
        
40 4
        $em = new EventManager();
41 4
        $em->setSharedManager($sharedEventManager);
0 ignored issues
show
Deprecated Code introduced by
The method Zend\EventManager\EventManager::setSharedManager() has been deprecated with message: This method is deprecated with 2.6.0, and will be removed in 3.0.0. See {@link https://github.com/zendframework/zend-eventmanager/blob/develop/doc/book/migration/removed.md} for details.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
42 4
        return $em;
43
    }
44
}
45