IdGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
generate() 0 1 ?
A create() 0 14 3
1
<?php
2
3
namespace Doctrine\ODM\CouchDB\Id;
4
5
use Doctrine\ODM\CouchDB\DocumentManager;
6
use Doctrine\ODM\CouchDB\Mapping\ClassMetadata;
7
8
/**
9
 * Used to abstract ID generation
10
 *
11
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
12
 * @link        www.doctrine-project.com
13
 * @since       1.0
14
 * @author      Benjamin Eberlei <[email protected]>
15
 * @author      Lukas Kahwe Smith <[email protected]>
16
 */
17
abstract class IdGenerator
18
{
19
    /**
20
     * @param int $generatorType
21
     *
22
     * @return IdGenerator
23
     * @throws \Exception
24
     */
25
    static public function create($generatorType)
26
    {
27
        switch ($generatorType) {
28
            case ClassMetadata::IDGENERATOR_ASSIGNED:
29
                $instance = new AssignedIdGenerator();
30
                break;
31
            case ClassMetadata::IDGENERATOR_UUID:
32
                $instance = new CouchUUIDGenerator();
33
                break;
34
            default:
35
                throw new \Exception("ID Generator does not exist!");
36
        }
37
        return $instance;
38
    }
39
40
    /**
41
     * @param object $document
42
     * @param ClassMetadata $cm
43
     * @param DocumentManager $dm
44
     */
45
    abstract public function generate($document, ClassMetadata $cm, DocumentManager $dm);
46
}
47