GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SentryEventRecorderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 45.45 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
lcom 1
cbo 3
dl 25
loc 55
rs 10
c 1
b 0
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testStoreAndRetrieveEventId() 8 8 1
A testRetrieveAllIds() 0 13 1
A testIgnoresNonObjects() 0 8 1
A testIgnoresUnknownObjects() 9 9 1
A testIgnoresEmptyIds() 8 8 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
namespace Classmarkets\RavenBundle\Tests;
4
5
use Classmarkets\RavenBundle\SentryEventRecorder;
6
7
class SentryEventRecorderTest extends \PHPUnit\Framework\TestCase
8
{
9
    use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
10
11 View Code Duplication
    public function testStoreAndRetrieveEventId()
12
    {
13
        $recorder = new SentryEventRecorder();
14
        $exception = new \Exception();
15
        $recorder->addExceptionEventId($exception, 'abc');
16
17
        $this->assertEquals('abc', $recorder->getEventIdForException($exception));
18
    }
19
20
    public function testRetrieveAllIds()
21
    {
22
        $recorder = new SentryEventRecorder();
23
24
        $e = new \Exception();
25
        $recorder->addExceptionEventId($e, 'abc');
26
        $recorder->addExceptionEventId($e, 'abc'); // yes, twice.
27
28
        $e = new \Exception();
29
        $recorder->addExceptionEventId($e, 'def');
30
31
        $this->assertEquals(['abc', 'def'], $recorder->getAllEventIds());
32
    }
33
34
    public function testIgnoresNonObjects()
35
    {
36
        $recorder = new SentryEventRecorder();
37
        $nonObject = 'some string';
38
        $recorder->addExceptionEventId($nonObject, 'abc');
0 ignored issues
show
Documentation introduced by
$nonObject is of type string, but the function expects a object.

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...
39
40
        $this->assertEquals(null, $recorder->getEventIdForException('some string'));
41
    }
42
43 View Code Duplication
    public function testIgnoresUnknownObjects()
44
    {
45
        $recorder = new SentryEventRecorder();
46
        $exception = new \Exception();
47
        $otherException = new \Exception();
48
        $recorder->addExceptionEventId($exception, 'abc');
49
50
        $this->assertEquals(null, $recorder->getEventIdForException($otherException));
51
    }
52
53 View Code Duplication
    public function testIgnoresEmptyIds()
54
    {
55
        $recorder = new SentryEventRecorder();
56
        $exception = new \Exception();
57
        $recorder->addExceptionEventId($exception, '');
58
59
        $this->assertEquals(null, $recorder->getEventIdForException($exception));
60
    }
61
}
62