ServiceLocator::lookup()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 16
ccs 0
cts 12
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * \AppserverIo\Appserver\PersistenceContainer\ServiceLocator
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/appserver
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Appserver\PersistenceContainer;
22
23
use AppserverIo\Psr\EnterpriseBeans\EnterpriseBeansException;
24
use AppserverIo\Psr\EnterpriseBeans\ServiceContextInterface;
25
use AppserverIo\Psr\EnterpriseBeans\ServiceResourceLocatorInterface;
26
27
/**
28
 * The service locator implementation.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2015 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io/appserver
34
 * @link      http://www.appserver.io
35
 */
36
class ServiceLocator implements ServiceResourceLocatorInterface
37
{
38
39
    /**
40
     * Tries to lookup the service with the passed identifier.
41
     *
42
     * @param \AppserverIo\Psr\EnterpriseBeans\ServiceContextInterface $serviceContext    The service context instance
43
     * @param string                                                   $serviceIdentifier The identifier of the service to be looked up
44
     * @param array                                                    $args              The arguments passed to the service providers constructor
45
     *
46
     * @return \AppserverIo\Psr\EnterpriseBeans\ServiceProviderInterface The requested service provider instance
47
     * @throws \AppserverIo\Psr\EnterpriseBeans\EnterpriseBeansException Is thrown if the requested server can't be lookup up
48
     * @see \AppserverIo\Psr\EnterpriseBeans\ServiceResourceLocatorInterface::lookup()
49
     */
50
    public function lookup(ServiceContextInterface $serviceContext, $serviceIdentifier, array $args = array())
51
    {
52
53
        // first check if the service is available
54
        if ($serviceContext->getServices()->has($serviceIdentifier) === false) {
55
            throw new EnterpriseBeansException(
56
                sprintf(
57
                    'Requested service %s to handle %s is not available',
58
                    $serviceContext->getIdentifier(),
0 ignored issues
show
Bug introduced by
The method getIdentifier() does not exist on AppserverIo\Psr\Enterpri...ServiceContextInterface. It seems like you code against a sub-type of said class. However, the method does not exist in AppserverIo\Psr\Enterpri...ServiceContextInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
                    $serviceContext->/** @scrutinizer ignore-call */ 
59
                                     getIdentifier(),
Loading history...
59
                    $serviceIdentifier
60
                )
61
            );
62
        }
63
64
        // return the initialized service instance
65
        return $serviceContext->getServices()->get($serviceIdentifier);
66
    }
67
}
68