OptimisticLockException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 34
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDocument() 0 4 1
A lockFailed() 0 4 1
A lockFailedVersionMissmatch() 0 4 1
A notVersioned() 0 4 1
1
<?php
2
3
namespace Doctrine\ODM\CouchDB;
4
5
/**
6
 * An OptimisticLockException is thrown when a version check on an object
7
 * that uses optimistic locking through a version field fails.
8
 *
9
 * @author Benjamin Eberlei <[email protected]>
10
 * @since 2.0
11
 */
12
class OptimisticLockException extends CouchDBException
13
{
14
    private $document;
15
16
    public function __construct($msg, $document)
17
    {
18
        $this->document = $document;
19
    }
20
21
    /**
22
     * Gets the document that caused the exception.
23
     *
24
     * @return object
25
     */
26
    public function getDocument()
27
    {
28
        return $this->document;
29
    }
30
31
    public static function lockFailed($document)
32
    {
33
        return new self("The optimistic lock on an document failed.", $document);
34
    }
35
36
    public static function lockFailedVersionMissmatch($document, $expectedLockVersion, $actualLockVersion)
37
    {
38
        return new self("The optimistic lock failed, version " . $expectedLockVersion . " was expected, but is actually ".$actualLockVersion, $document);
39
    }
40
41
    public static function notVersioned($entityName)
42
    {
43
        return new self("Cannot obtain optimistic lock on unversioned document " . $entityName, null);
44
    }
45
}
46