SimpleBasicAuthTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 69.23 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 45
loc 65
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_return_access_denied_on_empty_credentials() 11 11 1
A it_should_return_access_denied_on_wrong_credentials() 11 11 1
A it_should_return_ok_on_disabled_auth() 12 12 1
A it_should_return_ok_with_credentials() 11 11 1
A getEnvironmentSetUp() 0 9 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\Middleware;
6
7
use Longman\LaravelLodash\Middlewares\SimpleBasicAuth;
8
use Tests\Unit\TestCase;
9
10
use function config;
11
12
class SimpleBasicAuthTest 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...
13
{
14
    /** @test */
15 View Code Duplication
    public function it_should_return_access_denied_on_empty_credentials()
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...
16
    {
17
        config()->set('auth.simple', [
18
            'enabled'  => true,
19
            'user'     => 'testuser',
20
            'password' => 'testpass',
21
        ]);
22
23
        $response = $this->call('GET', 'url1', [], [], [], []);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
        $response->assertStatus(401);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
25
    }
26
27
    /** @test */
28 View Code Duplication
    public function it_should_return_access_denied_on_wrong_credentials()
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...
29
    {
30
        config()->set('auth.simple', [
31
            'enabled'  => true,
32
            'user'     => 'testuser',
33
            'password' => 'testpass',
34
        ]);
35
36
        $response = $this->call('GET', 'url1', [], [], [], ['PHP_AUTH_USER' => 'testuser', 'PHP_AUTH_PW' => 'wrongpass']);
0 ignored issues
show
Documentation introduced by
array('PHP_AUTH_USER' =>...UTH_PW' => 'wrongpass') is of type array<string,string,{"PH...PHP_AUTH_PW":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
37
        $response->assertStatus(401);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
38
    }
39
40
    /** @test */
41 View Code Duplication
    public function it_should_return_ok_on_disabled_auth()
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...
42
    {
43
        config()->set('auth.simple', [
44
            'enabled'  => false,
45
            'user'     => 'testuser',
46
            'password' => 'testpass',
47
        ]);
48
49
        $response = $this->call('GET', 'url1', [], [], [], []);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        $response->assertStatus(200);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
51
        $response->assertSeeText('ok');
52
    }
53
54
    /** @test */
55 View Code Duplication
    public function it_should_return_ok_with_credentials()
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...
56
    {
57
        config()->set('auth.simple', [
58
            'enabled'  => true,
59
            'user'     => 'testuser',
60
            'password' => 'testpass',
61
        ]);
62
        $response = $this->call('GET', 'url1', [], [], [], ['PHP_AUTH_USER' => 'testuser', 'PHP_AUTH_PW' => 'testpass']);
0 ignored issues
show
Documentation introduced by
array('PHP_AUTH_USER' =>...AUTH_PW' => 'testpass') is of type array<string,string,{"PH...PHP_AUTH_PW":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
        $response->assertStatus(200);
0 ignored issues
show
Bug introduced by
The method assertStatus() does not exist on Illuminate\Http\Response. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64
        $response->assertSeeText('ok');
65
    }
66
67
    protected function getEnvironmentSetUp($app)
68
    {
69
        /** @var \Illuminate\Routing\Router $router */
70
        $router = $app['router'];
71
72
        $router->get('url1', static function () {
73
            return 'ok';
74
        })->middleware(SimpleBasicAuth::class);
75
    }
76
}
77