CustomerImage::canView()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
class CustomerImage extends DataObject
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
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db 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...
6
        'Status' => "Enum('New,Approved,Declined,Example', 'New')",
7
        'FirstName' => 'Varchar',
8
        'Email' => 'Varchar(100)',
9
        'Surname' => 'Varchar',
10
        'Location' => 'Varchar(255)',
11
        'Feedback' => 'Text'
12
    );
13
14
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
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...
15
        'ProductPage' => 'ProductPage',
16
        'ProductVariation' => 'ProductVariation',
17
        'Image1' => 'Image',
18
        'Image2' => 'Image',
19
        'Image3' => 'Image',
20
        'Image4' => 'Image',
21
        'Image5' => 'Image',
22
        'FinalImage' => 'Image'
23
    );
24
25
    private static $default_sort = '"Created" DESC';
0 ignored issues
show
Unused Code introduced by
The property $default_sort 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...
26
27
    private static $singular_name = 'Customer Image';
0 ignored issues
show
Unused Code introduced by
The property $singular_name 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...
28
29
    private static $plural_name = 'Customer Images';
0 ignored issues
show
Unused Code introduced by
The property $plural_name 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...
30
31
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting 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...
32
        "Title" => "Varchar",
33
        'Thumbnail' => "HTMLText"
34
    );
35
36
    private static $summary_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $summary_fields 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...
37
        "Thumbnail" => "Thumbnail",
38
        "Status" => "Status",
39
        "Location" => "Location"
40
    );
41
42
43
    /**
44
     * STANDARD SILVERSTRIPE STUFF
45
     * @todo: how to translate this?
46
     **/
47
    private static $searchable_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $searchable_fields 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...
48
        'Status',
49
        'FirstName' => 'PartialMatchFilter',
50
        'Surname' => 'PartialMatchFilter',
51
        'Location' => 'PartialMatchFilter',
52
        'ProductPageID'
53
    );
54
55
    public function IsPortrait()
56
    {
57
        if ($this->getWidth() < $this->getHeight()) {
0 ignored issues
show
Documentation Bug introduced by
The method getWidth does not exist on object<CustomerImage>? 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...
Documentation Bug introduced by
The method getHeight does not exist on object<CustomerImage>? 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...
58
            return true;
59
        }
60
    }
61
62
    public function canView($member = null)
63
    {
64
        if ($this->Status == "Approved") {
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<CustomerImage>. 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...
65
            return true;
66
        }
67
        return $this->canDelete($member);
68
    }
69
70
    public function getCMSFields()
71
    {
72
        $fields = parent::getCMSFields();
73
74
        //variations drop down
75
        $variations = ProductVariation::get()->filter(array("ProductID" => $this->ProductPageID))->map("ID", "Title")->toArray();
0 ignored issues
show
Documentation introduced by
The property ProductPageID does not exist on object<CustomerImage>. 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...
76
        $fields->addFieldToTab("Root.Main", new DropdownField('ProductVariationID', 'Model', $variations), "FinalImage");
77
78
        //final image field ...
79
        $newImageField = new UploadField("FinalImage");
80
        $newImageField->setFolderName("Customer-Photos");
81
        $newImageField->setAllowedExtensions(array("png", "jpg", "gif"));
82
        $fields->addFieldToTab("Root.Main", $newImageField, "Status");
83
        //loop through images
84
        for ($i = 1; $i < 6; $i++) {
85
            $field = "Image$i"."ID";
86
            $method = "Image$i";
87
            if ($this->$field && $image = $this->$method()) {
88
                $imageField = new UploadField($method);
89
                $imageField->setFolderName("Customer-Photos/Drafts");
90
                $imageField->setAllowedExtensions(array("png", "jpg", "gif"));
91
                $fields->addFieldToTab("Root.DraftImages", $imageField);
92
            } else {
93
                $fields->removeByName($method);
94
            }
95
        }
96
        return $fields;
97
    }
98
99
    public function getThumbnail()
0 ignored issues
show
Documentation introduced by
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...
100
    {
101
        $image = $this->FinalImage();
0 ignored issues
show
Documentation Bug introduced by
The method FinalImage does not exist on object<CustomerImage>? 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...
102
        if (!$image->exists()) {
103
            $image = $this->Image1();
0 ignored issues
show
Documentation Bug introduced by
The method Image1 does not exist on object<CustomerImage>? 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...
104
        }
105
        if ($image->exists()) {
106
            $icon = "<img src=\"".$image->Link()."\" style=\"border: 1px solid black; height: 150px; \" height=\"200\" />";
107
        } else {
108
            $icon = "[NO IMAGE]";
109
        }
110
        return DBField::create_field("HTMLText", $icon);
0 ignored issues
show
Bug introduced by
The method create_field() does not exist on DBField. Did you maybe mean create()?

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...
111
    }
112
}
113
114
115
116
class CustomerImage_ModelAdmin extends ModelAdmin
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
117
{
118
    private static $url_segment = 'customerimages';
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...
Unused Code introduced by
The property $url_segment 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...
119
120
    private static $menu_title = 'Customer Images';
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...
Unused Code introduced by
The property $menu_title 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...
121
122
    private static $managed_models = array('CustomerImage');
0 ignored issues
show
Unused Code introduced by
The property $managed_models 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...
123
}
124