TransferManagerRegistry   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 18
dl 0
loc 107
ccs 28
cts 40
cp 0.7
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaultManager() 0 3 1
A getRepository() 0 3 1
A resetManager() 0 6 1
A getManagerForClass() 0 3 1
A setManager() 0 3 1
A getConnections() 0 3 1
A getConnection() 0 7 3
A getManagers() 0 3 1
A getDefaultConnectionName() 0 3 1
A getConnectionNames() 0 3 1
A getDefaultManagerName() 0 3 1
A getManagerNames() 0 3 1
A setClient() 0 3 1
A setDefaultConnection() 0 3 1
A getAliasNamespace() 0 2 1
A getManager() 0 3 1
1
<?php
2
3
namespace Vox\Webservice;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\Common\Persistence\ObjectRepository;
7
8
class TransferManagerRegistry implements ManagerRegistry
9
{
10
    /**
11
     * @var TransferManagerInterface[]
12
     */
13
    private $managers;
14
    
15
    /**
16
     * @var WebserviceClientInterface[]
17
     */
18
    private $clients;
19
    
20
    /**
21
     * @var string
22
     */
23
    private $defaultConnection;
24
    
25
    /**
26
     * @var string
27
     */
28
    private $defaultManager;
29
    
30 1
    public function setManager(string $name, TransferManagerInterface $transferManager)
31
    {
32 1
        $this->managers[$name] = $transferManager;
33 1
    }
34
    
35 1
    public function setClient(string $name, WebserviceClientInterface $client)
36
    {
37 1
        $this->clients[$name] = $client;
38 1
    }
39
    
40 1
    public function setDefaultConnection(string $defaultConnection)
41
    {
42 1
        $this->defaultConnection = $defaultConnection;
43 1
    }
44
45 1
    public function setDefaultManager(string $defaultManager)
46
    {
47 1
        $this->defaultManager = $defaultManager;
48 1
    }
49
            
50
    public function getAliasNamespace($alias): string
51
    {
52
        
53
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
54
55 1
    public function getConnection($name = null): WebserviceClientInterface
56
    {
57 1
        if (null === $name) {
58 1
            return isset($this->defaultConnection) ? $this->clients[$this->defaultConnection] : reset($this->clients);
59
        }
60
        
61 1
        return $this->clients[$name];
62
    }
63
64 1
    public function getConnectionNames(): array
65
    {
66 1
        return array_keys($this->clients);
67
    }
68
69 1
    public function getConnections(): array
70
    {
71 1
        return $this->clients;
72
    }
73
74 1
    public function getDefaultConnectionName(): string
75
    {
76 1
        return $this->defaultConnection ?? array_keys($this->clients)[0];
77
    }
78
79
    public function getDefaultManagerName(): string
80
    {
81
        return $this->defaultManager ?? array_keys($this->managers)[0];
82
    }
83
84 1
    public function getManager($name = null): TransferManagerInterface
85
    {
86 1
        return $this->managers[$name ?? $this->getDefaultConnectionName()];
87
    }
88
89
    public function getManagerForClass($class)
90
    {
91
        return $this->getManager();
92
    }
93
94 1
    public function getManagerNames(): array
95
    {
96 1
        return array_keys($this->managers);
97
    }
98
99 1
    public function getManagers(): array
100
    {
101 1
        return $this->managers;
102
    }
103
104
    public function getRepository($persistentObject, $persistentManagerName = null): ObjectRepository
105
    {
106
        return $this->getManager($persistentManagerName)->getRepository($persistentObject);
107
    }
108
109
    public function resetManager($name = null): TransferManagerInterface
110
    {
111
        $manager = $this->getManager($name);
112
        $manager->clear();
113
        
114
        return $manager;
115
    }
116
}
117