ArrayResourceTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 84.21 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_transform_array() 16 16 1
A it_should_return_unecaped_json() 16 16 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
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Http\Resources;
6
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Http\Request;
9
use Longman\LaravelLodash\Http\Resources\ArrayResource;
10
use Tests\Unit\TestCase;
11
12
use function app;
13
14
class ArrayResourceTest extends TestCase
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...
15
{
16
    /** @test */
17 View Code Duplication
    public function it_should_transform_array(): void
0 ignored issues
show
Duplication introduced by
This method 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...
18
    {
19
        $resource = new ArrayResource([
20
            'aa'  => 1,
21
            'aa2' => 2,
22
            'aa3' => 3,
23
        ]);
24
25
        $request = app(Request::class);
26
        $response = $resource->additional(['custom' => '1'])->withResourceType('customType')->toResponse($request);
27
28
        $expected = '{"data":{"id":null,"type":"customType","attributes":{"aa":1,"aa2":2,"aa3":3}},"custom":"1"}';
29
30
        $this->assertInstanceOf(JsonResponse::class, $response);
31
        $this->assertSame($expected, $response->content());
32
    }
33
34
    /** @test */
35 View Code Duplication
    public function it_should_return_unecaped_json(): void
0 ignored issues
show
Duplication introduced by
This method 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...
36
    {
37
        $resource = new ArrayResource([
38
            'aa'  => 'ერთი',
39
            'aa2' => 'ორი',
40
            'aa3' => 'სამი',
41
        ]);
42
43
        $request = app(Request::class);
44
        $response = $resource->additional(['custom' => '1'])->withResourceType('customType')->toResponse($request);
45
46
        $expected = '{"data":{"id":null,"type":"customType","attributes":{"aa":"ერთი","aa2":"ორი","aa3":"სამი"}},"custom":"1"}';
47
48
        $this->assertInstanceOf(JsonResponse::class, $response);
49
        $this->assertSame($expected, $response->content());
50
    }
51
}
52