Completed
Pull Request — master (#372)
by Mike
31:01 queued 16:07
created

HasManyThroughTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 59
loc 59
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testEagerloadedHasManyThrough() 28 28 1
A testLazyloadedHasManyThrough() 27 27 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration\CachedBuilder;
2
3
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
5
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
6
7 View Code Duplication
class HasManyThroughTest extends IntegrationTestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    public function testEagerloadedHasManyThrough()
10
    {
11
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-testing:{$this->testingSqlitePath}testing.sqlite:printers-first");
12
        $tags = [
13
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
14
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprinter",
15
        ];
16
17
        $printers = (new Author)
18
            ->with("printers")
19
            ->first()
20
            ->printers;
21
        $cachedResults = $this->cache()
22
            ->tags($tags)
23
            ->get($key)['value']
24
            ->first()
25
            ->printers;
26
        $liveResults = (new UncachedAuthor)
27
            ->with("printers")
28
            ->first()
29
            ->printers;
30
31
        $this->assertEquals($liveResults->pluck("id")->toArray(), $printers->pluck("id")->toArray());
32
        $this->assertEquals($liveResults->pluck("id")->toArray(), $cachedResults->pluck("id")->toArray());
33
        $this->assertNotEmpty($printers);
34
        $this->assertNotEmpty($cachedResults);
35
        $this->assertNotEmpty($liveResults);
36
    }
37
38
    public function testLazyloadedHasManyThrough()
39
    {
40
        $key = sha1("genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:authors:genealabslaravelmodelcachingtestsfixturesauthor-authors.deleted_at_null-authors.id_=_1-testing:{$this->testingSqlitePath}testing.sqlite:printers-limit_1");
0 ignored issues
show
Unused Code introduced by
$key 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...
41
        $tags = [
0 ignored issues
show
Unused Code introduced by
$tags 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...
42
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesauthor",
43
            "genealabs:laravel-model-caching:testing:{$this->testingSqlitePath}testing.sqlite:genealabslaravelmodelcachingtestsfixturesprinter",
44
        ];
45
46
        // $printers = (new Author)
47
        //     ->find(1)
48
        //     ->printers;
49
        // $cachedResults = $this->cache()
50
        //     ->tags($tags)
51
        //     ->get($key)['value']
52
        //     ->first()
53
        //     ->printers;
54
        // $liveResults = (new UncachedAuthor)
55
        //     ->find(1)
56
        //     ->printers;
57
58
        // $this->assertEquals($liveResults->pluck("id")->toArray(), $printers->pluck("id")->toArray());
59
        // $this->assertEquals($liveResults->pluck("id")->toArray(), $cachedResults->pluck("id")->toArray());
60
        // $this->assertNotEmpty($printers);
61
        // $this->assertNotEmpty($cachedResults);
62
        // $this->assertNotEmpty($liveResults);
63
        $this->markTestSkipped();
64
    }
65
}
66