Completed
Push — develop ( 92230b...218aa8 )
by Peter
02:10
created

Sharpen::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * Webino (https://github.com/webino/)
4
 *
5
 * @link      https://github.com/webino/WebinoImageThumb/ for the canonical source repository
6
 * @copyright Copyright (c) 2013-2015 Webino, s. r. o. (http://webino.sk/)
7
 * @license   BSD-3-Clause
8
 */
9
10
namespace WebinoImageThumb\PhpThumb\Plugin;
11
12
use PHPThumb\GD as PHPThumb;
13
use PHPThumb\PluginInterface;
14
15
/**
16
 * Sharpen plugin
17
 *
18
 * @author Miguel Vieira <[email protected]>
19
 */
20
class Sharpen implements PluginInterface
21
{
22
    /**
23
     * @var int
24
     */
25
    protected $offset = 0;
26
27
    /**
28
     * @var array
29
     */
30
    protected $matrix = [
31
        [0.0, -1.0, 0.0],
32
        [-1.0, 5.0, -1.0],
33
        [0.0, -1.0, 0.0],
34
    ];
35
36
    /**
37
     * @param int $offset Color offset
38
     * @param int $matrix A 3x3 matrix: an array of three arrays of three floats
39
     */
40
    public function __construct($offset = 0, $matrix = [])
41
    {
42
        empty($offset) or $this->offset = $offset;
43
        empty($matrix) or $this->matrix = $matrix;
0 ignored issues
show
Documentation Bug introduced by
It seems like $matrix can also be of type integer. However, the property $matrix is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
44
    }
45
46
    /**
47
     * @param PHPThumb $phpthumb
48
     * @return PHPThumb
49
     */
50
    public function execute($phpthumb)
51
    {
52
        $divisor = array_sum(array_map('array_sum', $this->matrix));
53
        imageconvolution($phpthumb->getOldImage(), $this->matrix, $divisor, $this->offset);
54
        return $phpthumb;
55
    }
56
}
57