Completed
Push — master ( 437dd6...3c7def )
by
unknown
12s
created

Registry.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\ORMException;
9
use Symfony\Bridge\Doctrine\ManagerRegistry;
10
use Symfony\Bridge\Doctrine\RegistryInterface;
11
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
12
use Symfony\Component\DependencyInjection\ContainerInterface;
13
14
/**
15
 * References all Doctrine connections and entity managers in a given Container.
16
 */
17
class Registry extends ManagerRegistry implements RegistryInterface
18
{
19
    /**
20
     * Construct.
21
     *
22
     * @param Connection[]             $connections
23
     * @param EntityManagerInterface[] $entityManagers
24
     * @param string                   $defaultConnection
25
     * @param string                   $defaultEntityManager
26
     */
27
    public function __construct(ContainerInterface $container, array $connections, array $entityManagers, $defaultConnection, $defaultEntityManager)
28
    {
29
        $parentTraits = class_uses(parent::class);
30
        if (isset($parentTraits[ContainerAwareTrait::class])) {
31
            // this case should be removed when Symfony 3.4 becomes the lowest supported version
32
            // and then also, the constructor should type-hint Psr\Container\ContainerInterface
33
            $this->setContainer($container);
34
        } else {
35
            $this->container = $container;
36
        }
37
38
        parent::__construct('ORM', $connections, $entityManagers, $defaultConnection, $defaultEntityManager, 'Doctrine\ORM\Proxy\Proxy');
0 ignored issues
show
$connections is of type array<integer,object<Doctrine\DBAL\Connection>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$entityManagers is of type array<integer,object<Doc...ntityManagerInterface>>, but the function expects a array<integer,string>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
    }
40
41
    /**
42
     * Gets the default entity manager name.
43
     *
44
     * @return string The default entity manager name
45
     *
46
     * @deprecated
47
     */
48
    public function getDefaultEntityManagerName()
49
    {
50
        @trigger_error('getDefaultEntityManagerName is deprecated since Symfony 2.1. Use getDefaultManagerName instead', E_USER_DEPRECATED);
51
52
        return $this->getDefaultManagerName();
53
    }
54
55
    /**
56
     * Gets a named entity manager.
57
     *
58
     * @param string $name The entity manager name (null for the default one)
59
     *
60
     * @return EntityManager
61
     *
62
     * @deprecated
63
     */
64
    public function getEntityManager($name = null)
65
    {
66
        @trigger_error('getEntityManager is deprecated since Symfony 2.1. Use getManager instead', E_USER_DEPRECATED);
67
68
        return $this->getManager($name);
69
    }
70
71
    /**
72
     * Gets an array of all registered entity managers
73
     *
74
     * @return EntityManager[] an array of all EntityManager instances
75
     *
76
     * @deprecated
77
     */
78
    public function getEntityManagers()
79
    {
80
        @trigger_error('getEntityManagers is deprecated since Symfony 2.1. Use getManagers instead', E_USER_DEPRECATED);
81
82
        return $this->getManagers();
83
    }
84
85
    /**
86
     * Resets a named entity manager.
87
     *
88
     * This method is useful when an entity manager has been closed
89
     * because of a rollbacked transaction AND when you think that
90
     * it makes sense to get a new one to replace the closed one.
91
     *
92
     * Be warned that you will get a brand new entity manager as
93
     * the existing one is not usable anymore. This means that any
94
     * other object with a dependency on this entity manager will
95
     * hold an obsolete reference. You can inject the registry instead
96
     * to avoid this problem.
97
     *
98
     * @param string $name The entity manager name (null for the default one)
99
     *
100
     *
101
     * @deprecated
102
     */
103
    public function resetEntityManager($name = null)
104
    {
105
        @trigger_error('resetEntityManager is deprecated since Symfony 2.1. Use resetManager instead', E_USER_DEPRECATED);
106
107
        $this->resetManager($name);
108
    }
109
110
    /**
111
     * Resolves a registered namespace alias to the full namespace.
112
     *
113
     * This method looks for the alias in all registered entity managers.
114
     *
115
     * @param string $alias The alias
116
     *
117
     * @return string The full namespace
118
     *
119
     * @deprecated
120
     */
121
    public function getEntityNamespace($alias)
122
    {
123
        @trigger_error('getEntityNamespace is deprecated since Symfony 2.1. Use getAliasNamespace instead', E_USER_DEPRECATED);
124
125
        return $this->getAliasNamespace($alias);
126
    }
127
128
    /**
129
     * Resolves a registered namespace alias to the full namespace.
130
     *
131
     * This method looks for the alias in all registered entity managers.
132
     *
133
     * @param string $alias The alias
134
     *
135
     * @return string The full namespace
136
     *
137
     * @see Configuration::getEntityNamespace
138
     */
139
    public function getAliasNamespace($alias)
140
    {
141
        foreach (array_keys($this->getManagers()) as $name) {
142
            try {
143
                return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
144
            } catch (ORMException $e) {
145
            }
146
        }
147
148
        throw ORMException::unknownEntityNamespace($alias);
149
    }
150
151
    /**
152
     * Gets all connection names.
153
     *
154
     * @return string[] An array of connection names
155
     *
156
     * @deprecated
157
     */
158
    public function getEntityManagerNames()
159
    {
160
        @trigger_error('getEntityManagerNames is deprecated since Symfony 2.1. Use getManagerNames instead', E_USER_DEPRECATED);
161
162
        return $this->getManagerNames();
163
    }
164
165
    /**
166
     * Gets the entity manager associated with a given class.
167
     *
168
     * @param string $class A Doctrine Entity class name
169
     *
170
     * @return EntityManager|null
171
     *
172
     * @deprecated
173
     */
174
    public function getEntityManagerForClass($class)
175
    {
176
        @trigger_error('getEntityManagerForClass is deprecated since Symfony 2.1. Use getManagerForClass instead', E_USER_DEPRECATED);
177
178
        return $this->getManagerForClass($class);
179
    }
180
}
181