AbstractProvisioner::newService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * AppserverIo\Provisioning\AbstractProvisioner
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 2018 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/provisioning
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Provisioning;
22
23
use AppserverIo\Psr\Application\ProvisionerInterface;
24
use AppserverIo\Psr\ApplicationServer\ContextInterface;
25
use AppserverIo\Provisioning\Configuration\ProvisionerConfigurationInterface;
26
27
/**
28
 * Abstract base class that provides basic provisioning functionality.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2018 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/provisioning
34
 * @link      http://www.appserver.io
35
 */
36
abstract class AbstractProvisioner implements ProvisionerInterface
37
{
38
39
    /**
40
     * The initial context instance.
41
     *
42
     * @var \AppserverIo\Psr\ApplicationServer\ContextInterface
43
     */
44
    protected $initialContext;
45
46
    /**
47
     * The provisioning service instance.
48
     *
49
     * @var \AppserverIo\Psr\ApplicationServer\ServiceInterface
50
     */
51
    protected $service;
52
53
    /**
54
     * The provisioner node configuration data.
55
     *
56
     * @var \AppserverIo\Provisioning\Configuration\ProvisionerConfigurationInterface
57
     */
58
    protected $provisionerNode;
59
60
    /**
61
     * Contructor to initialize the provisioner instance with the initial context
62
     * and the provision node configuration data.
63
     *
64
     * @param \AppserverIo\Psr\ApplicationServer\ContextInterface                       $initialContext  The initial context instance
65
     * @param \AppserverIo\Provisioning\Configuration\ProvisionerConfigurationInterface $provisionerNode The provisioner node configuration data
66
     */
67
    public function __construct(ContextInterface $initialContext, ProvisionerConfigurationInterface $provisionerNode)
68
    {
69
70
        // add initial context and provisioner node configuration data
71
        $this->initialContext = $initialContext;
72
        $this->provisionerNode = $provisionerNode;
73
74
        // init API service to use
75
        $this->service = $this->newService('AppserverIo\Appserver\Core\Api\ProvisioningService');
76
    }
77
78
    /**
79
     * (non-PHPdoc)
80
     *
81
     * @param string $className The API service class name to return the instance for
82
     *
83
     * @return \AppserverIo\Psr\ApplicationServer\ServiceInterface The service instance
84
     * @see \AppserverIo\Psr\ApplicationServer\ContextInterface::newService()
85
     */
86
    public function newService($className)
87
    {
88
        return $this->getInitialContext()->newService($className);
89
    }
90
91
    /**
92
     * Returns the inital context instance.
93
     *
94
     * @return \AppserverIo\Psr\ApplicationServer\ContextInterface The initial context instance
95
     */
96
    public function getInitialContext()
97
    {
98
        return $this->initialContext;
99
    }
100
101
    /**
102
     * Returns the service instance to use.
103
     *
104
     * @return \AppserverIo\Provisioning\Api\ProvisioningServiceInterface $service The service to use
105
     */
106
    public function getService()
107
    {
108
        return $this->service;
109
    }
110
111
    /**
112
     * Returns the provisioner node configuration data.
113
     *
114
     * @return \AppserverIo\Provisioning\Configuration\ProvisionerConfigurationInterface The provisioner node configuration data
115
     */
116
    public function getProvisionerNode()
117
    {
118
        return $this->provisionerNode;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->provisionerNode returns the type AppserverIo\Provisioning...rConfigurationInterface which is incompatible with the return type mandated by AppserverIo\Psr\Applicat...e::getProvisionerNode() of AppserverIo\Appserver\Co...rovisionerNodeInterface.

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...
119
    }
120
}
121