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

AbstractTableTest::insertDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
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