Passed
Push — next ( 4a2827...9707a2 )
by Bas
07:22
created

HandlesTestingTransactions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A initializeTestDatabaseTransactions() 0 22 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Testing;
6
7
use Illuminate\Foundation\Testing\RefreshDatabase as IlluminateRefreshDatabase;
8
9
trait HandlesTestingTransactions
10
{
11
    protected function initializeTestDatabaseTransactions(): void
12
    {
13
        $database = $this->app->make('db');
14
15
        foreach ($this->connectionsToTransact() as $name) {
0 ignored issues
show
Bug introduced by
It seems like connectionsToTransact() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

15
        foreach ($this->/** @scrutinizer ignore-call */ connectionsToTransact() as $name) {
Loading history...
16
            $connection = $database->connection($name);
17
            $dispatcher = $connection->getEventDispatcher();
18
19
            $connection->unsetEventDispatcher();
20
            $connection->beginTransaction($this->transactionCollections);
21
            $connection->setEventDispatcher($dispatcher);
22
        }
23
24
        $this->beforeApplicationDestroyed(function () use ($database) {
0 ignored issues
show
Bug introduced by
It seems like beforeApplicationDestroyed() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        $this->/** @scrutinizer ignore-call */ 
25
               beforeApplicationDestroyed(function () use ($database) {
Loading history...
25
            foreach ($this->connectionsToTransact() as $name) {
26
                $connection = $database->connection($name);
27
                $dispatcher = $connection->getEventDispatcher();
28
29
                $connection->unsetEventDispatcher();
30
                $connection->rollback();
31
                $connection->setEventDispatcher($dispatcher);
32
                $connection->disconnect();
33
            }
34
        });
35
    }
36
}
37