Conditions | 4 |
Paths | 4 |
Total Lines | 19 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | protected function _getPortableSequenceDefinition($sequence) |
||
20 | { |
||
21 | $sequenceName = $sequence['relname']; |
||
22 | if ('public' !== $sequence['schemaname']) { |
||
23 | $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; |
||
24 | } |
||
25 | |||
26 | $query = 'SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName); |
||
27 | |||
28 | // the `method_exists` is only to avoid test to fail: |
||
29 | // DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticConnection doesn't support the `getServerVersion` |
||
30 | if (method_exists($this->_conn->getWrappedConnection(), 'getServerVersion') && (float) ($this->_conn->getWrappedConnection()->getServerVersion()) >= 10) { |
||
|
|||
31 | $query = "SELECT min_value, increment_by FROM pg_sequences WHERE schemaname = 'public' AND sequencename = " . $this->_conn->quote($sequenceName); |
||
32 | } |
||
33 | |||
34 | $data = $this->_conn->fetchAll($query); |
||
35 | |||
36 | return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']); |
||
37 | } |
||
38 | } |
||
39 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: