Passed
Pull Request — master (#28)
by Timon
04:16 queued 42s
created

AbstractTableTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A insertDocument() 0 12 1
A tearDown() 0 7 2
A setUp() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\IntegrationTest\Query;
5
6
use TBolier\RethinkQL\IntegrationTest\AbstractTestCase;
7
use TBolier\RethinkQL\Response\ResponseInterface;
8
9
abstract class AbstractTableTest extends AbstractTestCase
10
{
11
    public function setUp()
12
    {
13
        parent::setUp();
14
15
        if (!\in_array('tabletest', $this->r()->db()->tableList()->run()->getData(), true)) {
0 ignored issues
show
Bug introduced by
It seems like $this->r()->db()->tableList()->run()->getData() can also be of type string; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

15
        if (!\in_array('tabletest', /** @scrutinizer ignore-type */ $this->r()->db()->tableList()->run()->getData(), true)) {
Loading history...
16
            $this->r()->db()->tableCreate('tabletest')->run();
17
        }
18
    }
19
20
    public function tearDown()
21
    {
22
        if (\in_array('tabletest', $this->r()->db()->tableList()->run()->getData(), true)) {
0 ignored issues
show
Bug introduced by
It seems like $this->r()->db()->tableList()->run()->getData() can also be of type string; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

22
        if (\in_array('tabletest', /** @scrutinizer ignore-type */ $this->r()->db()->tableList()->run()->getData(), true)) {
Loading history...
23
            $this->r()->db()->tableDrop('tabletest')->run();
24
        }
25
26
        parent::tearDown();
27
    }
28
29
30
    /**
31
     * @param int $documentId
32
     * @return ResponseInterface
33
     */
34
    protected function insertDocument(int $documentId): ResponseInterface
35
    {
36
        $res = $this->r()
37
            ->table('tabletest')
38
            ->insert([
39
                'id' => $documentId,
40
                'title' => 'Test document ' . $documentId,
41
                'description' => 'A document description.',
42
            ])
43
            ->run();
44
45
        return $res;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $res could return the type iterable which is incompatible with the type-hinted return TBolier\RethinkQL\Response\ResponseInterface. Consider adding an additional type-check to rule them out.
Loading history...
46
    }
47
}
48