TransactionMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 17 3
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
 * <https://github.com/baleen/migrations>.
18
 */
19
20
namespace Baleen\Migrations\Service\MigrationBus\Middleware;
21
22
use Baleen\Migrations\Migration\Capabilities\TransactionAwareInterface;
23
use Baleen\Migrations\Service\MigrationBus\MigrateCommand;
24
use League\Tactician\Middleware;
25
26
/**
27
 * Wraps the migration in a transaction if the migration implements
28
 * TransactionAwareInterface.
29
 *
30
 * @author Gabriel Somoza <[email protected]>
31
 */
32
final class TransactionMiddleware implements Middleware
33
{
34
    /**
35
     * execute
36
     *
37
     * @param MigrateCommand $command
38
     * @param callable $next
39
     *
40
     * @return void
41
     */
42 15
    public function execute($command, callable $next)
43
    {
44 15
        $migration = $command->getMigration();
45 15
        if (!$migration instanceof TransactionAwareInterface) {
46 14
            $next($command);
47 14
            return;
48
        }
49
50 1
        $result = null;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
51
        try {
52 1
            $migration->begin();
53 1
            $next($command);
54 1
            $migration->finish();
55 1
        } catch (\Exception $e) {
56 1
            $migration->abort($e);
57
        }
58 1
    }
59
}
60