Passed
Pull Request — master (#1108)
by Tim
06:37
created

ParserFactory::createParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * \AppserverIo\Appserver\DependencyInjectionContainer\ParserFactory
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\DependencyInjectionContainer;
22
23
use AppserverIo\Lang\Reflection\ReflectionClass;
24
use AppserverIo\Psr\Application\ManagerInterface;
25
use AppserverIo\Appserver\Core\Api\Node\ParserNodeInterface;
26
27
/**
28
 * Generic factory to create new parser instances from the passed parser configuration.
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 ParserFactory implements ParserFactoryInterface
37
{
38
39
    /**
40
     * Creates and returns a new parser instance from the passed configuration.
41
     *
42
     * @param \AppserverIo\Appserver\Core\Api\Node\ParserNodeInterface $parserNode The parser configuration
43
     * @param \AppserverIo\Psr\Application\ManagerInterface            $manager    The manager the parser is bound to
44
     *
45
     * @return \AppserverIo\Appserver\DependencyInjectionContainer\ParserInterface The parser instance
46
     */
47
    public function createParser(ParserNodeInterface $parserNode, ManagerInterface $manager)
48
    {
49
50
        // create a reflection class from the configured parser type
51
        $reflectionClass = new ReflectionClass($parserNode->getType());
52
53
        // create a new parser instance and pass the configuration and manager to the constructor
54
        return $reflectionClass->newInstanceArgs(array($parserNode, $manager));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $reflectionClass-...$parserNode, $manager)) returns the type AppserverIo\Lang\Object which is incompatible with the documented return type AppserverIo\Appserver\De...ntainer\ParserInterface.
Loading history...
55
    }
56
}
57