Completed
Push — master ( 59c799...149ad0 )
by Will
02:15
created

code/models/ElementVirtualLinked.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Virtual Linked Element.
5
 *
6
 * As elemental is based on widgets which have a natural has_one relation to an
7
 * object, this is a workaround for allowing the same element to be linked to
8
 * multiple pages.
9
 *
10
 * {@see ElementalGridFieldAddExistingAutocompleter}
11
 *
12
 * @package elemental
13
 */
14
class ElementVirtualLinked extends BaseElement {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
16
    private static $has_one = 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...
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
        'LinkedElement' => 'BaseElement'
18
    );
19
20
    public function getTitle()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
21
    {
22
        return $this->LinkedElement()->getTitle();
0 ignored issues
show
Documentation Bug introduced by
The method LinkedElement does not exist on object<ElementVirtualLinked>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
23
    }
24
25
    public function i18n_singular_name()
26
    {
27
        return _t(__CLASS__, $this->LinkedElement()->config()->title);
0 ignored issues
show
Documentation Bug introduced by
The method LinkedElement does not exist on object<ElementVirtualLinked>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
28
    }
29
30
    public function getCMSFields() {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
31
        $message = sprintf('<p>%s</p><p><a href="%2$s">%2$s</a></p>',
32
             _t('ElementVirtualLinked.DESCRIBE', 'This is a virtual copy of a block. To edit, visit'),
33
             $this->LinkedElement()->getEditLink()
0 ignored issues
show
Documentation Bug introduced by
The method LinkedElement does not exist on object<ElementVirtualLinked>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
34
        );
35
36
        $fields = new FieldList(
37
            new LiteralField('Existing', $message)
38
        );
39
40
        $this->extend('updateCMSFields', $fields);
41
42
        return $fields;
43
    }
44
}
45