Completed
Pull Request — master (#21)
by Christophe
09:31
created

CloudFactory::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.2963

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 3
cts 9
cp 0.3333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
crap 1.2963
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * This file is part of the XabbuhPandaBundle package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaBundle\Cloud;
13
14 1
@trigger_error('The Xabbuh\PandaBundle\Cloud\CloudFactory class is deprecated since version 1.3 and will be removed in 2.0', E_USER_DEPRECATED);
15
16
use Xabbuh\PandaClient\Api\AccountManagerInterface;
17
use Xabbuh\PandaClient\Api\Cloud;
18
use Xabbuh\PandaClient\Api\HttplugClient;
19
use Xabbuh\PandaClient\Transformer\TransformerRegistryInterface;
20
21
/**
22
 * Factory to create Cloud instances.
23
 *
24
 * @author Christian Flothmann <[email protected]>
25
 *
26
 * @deprecated since version 1.3, to be removed in 2.0
27
 */
28
class CloudFactory implements CloudFactoryInterface
29
{
30
    /**
31
     * The account manager being used to manage all configured Accounts
32
     * @var AccountManagerInterface
33
     */
34
    private $accountManager;
35
36
    /**
37
     * Factory for creating model transformers
38
     * @var TransformerRegistryInterface
39
     */
40
    private $transformerRegistry;
41
42 3
    public function __construct(
43
        AccountManagerInterface $accountManager,
44
        TransformerRegistryInterface $transformerFactory
45
    ) {
46 3
        $this->accountManager = $accountManager;
47 3
        $this->transformerRegistry = $transformerFactory;
48 3
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 3
    public function get($cloudId, $accountKey = null)
54
    {
55 3
        $account = $this->accountManager->getAccount($accountKey);
56
57 3
        $httpClient = new HttplugClient();
58
        $httpClient->setCloudId($cloudId);
59
        $httpClient->setAccount($account);
60
61
        $cloud = new Cloud();
62
        $cloud->setHttpClient($httpClient);
63
        $cloud->setTransformers($this->transformerRegistry);
64
65
        return $cloud;
66
    }
67
}
68