Transaction   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A begin() 0 5 1
A commit() 0 5 1
A link() 0 3 1
A rollback() 0 5 1
A __construct() 0 11 1
A execute() 0 3 1
A escape() 0 3 1
1
<?php
2
/**
3
 * Transaction program
4
 * User: moyo
5
 * Date: 03/11/2017
6
 * Time: 11:43 AM
7
 */
8
9
namespace Carno\Database\Programs;
10
11
use Carno\Database\Contracts\Executable;
12
use Carno\Database\Contracts\Transaction as TransAPI;
13
use Carno\Promise\Promised;
14
15
class Transaction implements TransAPI, Executable
16
{
17
    /**
18
     * @var TransAPI|Executable
19
     */
20
    private $link = null;
21
22
    /**
23
     * @var Promised
24
     */
25
    private $wStart = null;
26
27
    /**
28
     * @var Promised
29
     */
30
    private $wCommit = null;
31
32
    /**
33
     * @var Promised
34
     */
35
    private $wRollback = null;
36
37
    /**
38
     * Transaction constructor.
39
     * @param TransAPI $link
40
     * @param Promised $start
41
     * @param Promised $commit
42
     * @param Promised $rollback
43
     */
44
    public function __construct(
45
        TransAPI $link,
46
        Promised $start,
47
        Promised $commit,
48
        Promised $rollback
49
    ) {
50
        $this->link = $link;
51
52
        $this->wStart = $start;
53
        $this->wCommit = $commit;
54
        $this->wRollback = $rollback;
55
    }
56
57
    /**
58
     * @return Executable
59
     */
60
    public function link() : Executable
61
    {
62
        return $this->link;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->link could return the type Carno\Database\Contracts\Transaction which is incompatible with the type-hinted return Carno\Database\Contracts\Executable. Consider adding an additional type-check to rule them out.
Loading history...
63
    }
64
65
    /**
66
     * @param string $sql
67
     * @param array $bind
68
     * @return Promised
69
     */
70
    public function execute(string $sql, array $bind = [])
71
    {
72
        return $this->link->execute($sql, $bind);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->link->execute($sql, $bind) also could return the type Carno\Database\Results\C...atabase\Results\Updated which is incompatible with the documented return type Carno\Promise\Promised.
Loading history...
Bug introduced by
The method execute() does not exist on Carno\Database\Contracts\Transaction. Since it exists in all sub-types, consider adding an abstract or default implementation to Carno\Database\Contracts\Transaction. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        return $this->link->/** @scrutinizer ignore-call */ execute($sql, $bind);
Loading history...
73
    }
74
75
    /**
76
     * @deprecated
77
     * @param string $data
78
     * @return string
79
     */
80
    public function escape(string $data) : string
81
    {
82
        return $this->link->escape($data);
0 ignored issues
show
Deprecated Code introduced by
The function Carno\Database\Contracts\Executable::escape() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

82
        return /** @scrutinizer ignore-deprecated */ $this->link->escape($data);
Loading history...
Bug introduced by
The method escape() does not exist on Carno\Database\Contracts\Transaction. Since it exists in all sub-types, consider adding an abstract or default implementation to Carno\Database\Contracts\Transaction. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
        return $this->link->/** @scrutinizer ignore-call */ escape($data);
Loading history...
83
    }
84
85
    /**
86
     * @return Promised
87
     */
88
    public function begin()
89
    {
90
        yield $this->link->begin();
0 ignored issues
show
Bug introduced by
The method begin() does not exist on Carno\Database\Contracts\Executable. It seems like you code against a sub-type of Carno\Database\Contracts\Executable such as Carno\Database\Connectors\MySQL or Carno\Database\Programs\Transaction. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        yield $this->link->/** @scrutinizer ignore-call */ begin();
Loading history...
Bug Best Practice introduced by
The expression yield $this->link->begin() returns the type Generator which is incompatible with the documented return type Carno\Promise\Promised.
Loading history...
91
        $this->wStart->resolve();
92
        return $this->wStart;
93
    }
94
95
    /**
96
     * @return Promised
97
     */
98
    public function commit()
99
    {
100
        yield $this->link->commit();
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->link->commit() returns the type Generator which is incompatible with the documented return type Carno\Promise\Promised.
Loading history...
Bug introduced by
The method commit() does not exist on Carno\Database\Contracts\Executable. It seems like you code against a sub-type of Carno\Database\Contracts\Executable such as Carno\Database\Connectors\MySQL or Carno\Database\Programs\Transaction. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
        yield $this->link->/** @scrutinizer ignore-call */ commit();
Loading history...
101
        $this->wCommit->resolve();
102
        return $this->wCommit;
103
    }
104
105
    /**
106
     * @return Promised
107
     */
108
    public function rollback()
109
    {
110
        yield $this->link->rollback();
0 ignored issues
show
Bug introduced by
The method rollback() does not exist on Carno\Database\Contracts\Executable. It seems like you code against a sub-type of Carno\Database\Contracts\Executable such as Carno\Database\Connectors\MySQL or Carno\Database\Programs\Transaction. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
        yield $this->link->/** @scrutinizer ignore-call */ rollback();
Loading history...
Bug Best Practice introduced by
The expression yield $this->link->rollback() returns the type Generator which is incompatible with the documented return type Carno\Promise\Promised.
Loading history...
111
        $this->wRollback->resolve();
112
        return $this->wRollback;
113
    }
114
}
115