GalleryImage::getPortletCaption()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
class GalleryImage extends DataObject implements RenderableAsPortlet
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...
4
{
5
    public static $db = array(
6
        'SortOrder' => 'Int',
7
        'Title' => 'Varchar',
8
        'Caption' => 'Text'
9
    );
10
11
    // One-to-one relationship with gallery page
12
    public static $has_one = array(
13
        'Image' => 'Image',
14
        'GalleryPage' => 'GalleryPage',
15
    );
16
17
    // tidy up the CMS by not showing these fields
18 1
    public function getCMSFields()
19
    {
20 1
        $fields = parent::getCMSFields();
21 1
        $fields->removeFieldFromTab('Root.Main', 'GalleryPageID');
22 1
        $fields->removeFieldFromTab('Root.Main', 'ExifRead');
23 1
        $fields->removeFieldFromTab('Root.Main', 'SortOrder');
24 1
        $fields->renameField('Title', _t('GalleryImage.TITLE', 'Title'));
25 1
        $fields->renameField('Image', _t('GalleryImage.IMAGE', 'Image'));
26 1
        return $fields;
27
    }
28
29
    // Tell the datagrid what fields to show in the table
30
    public static $summary_fields = array(
31
        'ID' => 'ID',
32
        'Title' => 'Title',
33
        'Thumbnail' => 'Thumbnail',
34
    );
35
36
    // this function creates the thumnail for the summary fields to use
37 1
    public function getThumbnail()
38
    {
39 1
        return $this->Image()->CMSThumbnail();
0 ignored issues
show
Documentation Bug introduced by
The method Image does not exist on object<GalleryImage>? 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...
40
    }
41
42 1
    public function getPortletTitle()
43
    {
44 1
        return $this->Title;
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<GalleryImage>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
45
    }
46
47
    /**
48
    * An accessor method for an image for a portlet.
49
    *
50
    * @example
51
    * <code>
52
    *  return $this->NewsItemImage;
53
    * </code>
54
    *
55
    * @return string
56
    */
57 1
    public function getPortletImage()
58
    {
59 1
        return $this->Image();
0 ignored issues
show
Documentation Bug introduced by
The method Image does not exist on object<GalleryImage>? 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...
60
    }
61
62
    /**
63
    * An accessor for text associated with the portlet.
64
    *
65
    * @example
66
    * <code>
67
    * return $this->Summary
68
    * </code>
69
    *
70
    * @return string
71
    */
72 1
    public function getPortletCaption()
73
    {
74 1
        return '';
75
    }
76
}
77