ScannedDocument   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 11
c 2
b 0
f 1
dl 0
loc 36
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A execute() 0 12 2
1
<?php
2
3
namespace Jackal\ImageMerge\Command\Effect;
4
5
use Jackal\ImageMerge\Builder\ImageBuilder;
6
use Jackal\ImageMerge\Command\AbstractCommand;
7
use Jackal\ImageMerge\Command\Options\LevelCommandOption;
8
use Jackal\ImageMerge\Model\Image;
9
10
class ScannedDocument extends AbstractCommand
11
{
12
    /**
13
     * @var LevelCommandOption
14
     */
15
    private $contrast;
16
17
    /**
18
     * ScannedDocument constructor.
19
     * @param LevelCommandOption|null $contrast
20
     */
21
    public function __construct(LevelCommandOption $contrast = null)
22
    {
23
        if ($contrast == null) {
24
            $this->contrast = new LevelCommandOption(-60);
25
        }
26
27
        parent::__construct($this->contrast);
28
    }
29
30
    /**
31
     * @param Image $image
32
     * @return Image
33
     */
34
    public function execute(Image $image)
35
    {
36
        $builder = new ImageBuilder($image);
37
38
        if ($image->getWidth() > $image->getHeight()) {
39
            $builder->rotate(-90);
40
        }
41
42
        $builder->grayScale();
43
        $builder->contrast($this->contrast->getLevel());
44
45
        return $builder->getImage();
46
    }
47
}
48