DMSUploadField_ItemHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A EditForm() 0 19 1
A getItem() 0 4 1
1
<?php
2
3
class DMSUploadField_ItemHandler extends UploadField_ItemHandler
4
{
5
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
6
        'delete',
7
        'edit',
8
        'EditForm',
9
    );
10
11
    /**
12
     * Gets a DMS document by its ID
13
     *
14
     * @return DMSDocument
0 ignored issues
show
Documentation introduced by
Should the return type not be DMSDocument|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
15
     */
16
    public function getItem()
17
    {
18
        return DMSDocument::get()->byId($this->itemID);
19
    }
20
21
    /**
22
     * @return Form
23
     */
24
    public function EditForm()
25
    {
26
        $file = $this->getItem();
27
28
        // Get form components
29
        $fields = $this->parent->getDMSFileEditFields($file);
0 ignored issues
show
Bug introduced by
The method getDMSFileEditFields() does not exist on UploadField. Did you maybe mean getFileEditFields()?

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...
30
        $actions = $this->parent->getDMSFileEditActions($file);
0 ignored issues
show
Bug introduced by
The method getDMSFileEditActions() does not exist on UploadField. Did you maybe mean getFileEditActions()?

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...
31
        $validator = $this->parent->getDMSFileEditValidator($file);
0 ignored issues
show
Bug introduced by
The method getDMSFileEditValidator() does not exist on UploadField. Did you maybe mean getFileEditValidator()?

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...
32
        $form = new Form(
33
            $this,
0 ignored issues
show
Documentation introduced by
$this is of type this<DMSUploadField_ItemHandler>, but the function expects a object<Controller>.

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...
34
            __FUNCTION__,
35
            $fields,
36
            $actions,
37
            $validator
38
        );
39
        $form->loadDataFrom($file);
0 ignored issues
show
Bug introduced by
It seems like $file defined by $this->getItem() on line 26 can be null; however, Form::loadDataFrom() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
40
41
        return $form;
42
    }
43
}
44