SepiaImages   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Sepia() 0 4 1
A generateSepia() 0 19 2
1
<?php
2
3
/**
4
 * Class SepiaImages
5
 * for generating sepia toned images. Use $Image.Sepia in your template.
6
 */
7
class SepiaImages  extends DataExtension
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...
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before extends keyword; 2 found
Loading history...
8
{
9
10
    private static $brightness = -30;
0 ignored issues
show
Unused Code introduced by
The property $brightness 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...
11
12
    private static $colorize_red = 90;
0 ignored issues
show
Unused Code introduced by
The property $colorize_red 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...
13
    private static $colorize_green = 55;
0 ignored issues
show
Unused Code introduced by
The property $colorize_green 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...
14
    private static $colorize_blue = 30;
0 ignored issues
show
Unused Code introduced by
The property $colorize_blue 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
16
17
    public function Sepia()
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...
18
    {
19
        return $this->owner->getFormattedImage('Sepia');
20
    }
21
22
    public function generateSepia($gd)
23
    {
24
        $imageResource= $gd->getImageResource();
25
        if (!$imageResource) {
26
            return;
27
        }
28
29
        $conf = Config::inst()->forClass('SepiaImages');
30
31
        imagefilter($imageResource, IMG_FILTER_GRAYSCALE);
32
        imagefilter($imageResource, IMG_FILTER_BRIGHTNESS, $conf->get('brightness'));
33
        imagefilter($imageResource, IMG_FILTER_COLORIZE,
34
            $conf->get('colorize_red'), $conf->get('colorize_green'), $conf->get('colorize_blue'));
35
36
        $output = clone $gd;
37
        $output->setImageResource($imageResource);
38
39
        return $output;
40
    }
41
}
42