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.
Completed
Pull Request — master (#290)
by
unknown
01:34
created

DataExtension::getImplementationSummary()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Queue\Admin;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\LiteralField;
7
use SilverStripe\Forms\TextareaField;
8
use SilverStripe\ORM\DataExtension as BaseDataExtension;
9
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor;
10
11
/**
12
 * Class DataExtension
13
 *
14
 * @property QueuedJobDescriptor|$this $owner
15
 * @package App\Queue\Admin
16
 */
17
class DataExtension extends BaseDataExtension
18
{
19
20
    /**
21
     * @param FieldList $fields
22
     */
23
    public function updateCMSFields(FieldList $fields): void
24
    {
25
        $owner = $this->owner;
26
27
        $fields->addFieldsToTab('Root.JobData', [
28
            $jobDataPreview = TextareaField::create('SavedJobDataPreview', 'Job Data'),
29
        ]);
30
31
        if (strlen($owner->getMessagesRaw()) > 0) {
32
            $fields->addFieldToTab(
33
                'Root.MessagesRaw',
34
                $messagesRaw = LiteralField::create('MessagesRaw', $owner->getMessagesRaw())
0 ignored issues
show
Bug introduced by
The method getMessagesRaw does only exist in App\Queue\Admin\DataExtension, but not in Symbiote\QueuedJobs\Data...cts\QueuedJobDescriptor.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
35
            );
36
        }
37
38
        $jobDataPreview->setReadonly(true);
39
    }
40
41
    /**
42
     * @return string|null
43
     */
44
    public function getSavedJobDataPreview(): ?string
45
    {
46
        return $this->owner->SavedJobData;
47
    }
48
49
    /**
50
     * @return string|null
51
     */
52
    public function getMessagesRaw(): ?string
53
    {
54
        return $this->owner->SavedJobMessages;
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function getImplementationSummary(): string
61
    {
62
        $segments = explode('\\', $this->owner->Implementation);
63
64
        while (count($segments) > 2) {
65
            array_shift($segments);
66
        }
67
68
        return implode('\\', $segments);
69
    }
70
}
71