Completed
Pull Request — master (#6365)
by Daniel Tome
10:44
created

BigIntegerIdentityGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 37
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generate() 0 4 1
A isPostInsertGenerator() 0 4 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Id;
21
22
use Doctrine\ORM\EntityManager;
23
24
/**
25
 * Id generator that obtains IDs from special "identity" columns. These are columns
26
 * that automatically get a database-generated, auto-incremented identifier on INSERT.
27
 * This generator obtains the last insert id after such an insert.
28
 */
29
class BigIntegerIdentityGenerator extends AbstractIdGenerator
30
{
31
    /**
32
     * The name of the sequence to pass to lastInsertId(), if any.
33
     *
34
     * @var string
35
     */
36
    private $sequenceName;
37
38
    /**
39
     * Constructor.
40
     *
41
     * @param string|null $sequenceName The name of the sequence to pass to lastInsertId()
42
     *                                  to obtain the last generated identifier within the current
43
     *                                  database session/connection, if any.
44
     */
45
    public function __construct($sequenceName = null)
46
    {
47
        $this->sequenceName = $sequenceName;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    public function generate(EntityManager $em, $entity)
54
    {
55
        return (string) $em->getConnection()->lastInsertId($this->sequenceName);
56
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61
    public function isPostInsertGenerator()
62
    {
63
        return true;
64
    }
65
}
66
67