PreciseMask   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addWordToMask() 0 32 5
1
<?php
2
3
namespace SixtyNine\Cloud\Usher;
4
5
use SixtyNine\Cloud\FontMetrics;
6
use SixtyNine\DataTypes\Box;
7
use Imagine\Image\Point;
8
9
class PreciseMask extends QuadTreeMask implements MaskInterface
10
{
11
    /**
12
     * @param int $width
13
     * @param int $height
14
     * @param FontMetrics $metrics
15
     */
16
    public function __construct($width, $height, FontMetrics $metrics) {
17
        parent::__construct($width, $height);
18
        $this->metrics = $metrics;
0 ignored issues
show
Bug introduced by
The property metrics does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * @param string $word
23
     * @param Box $place
24
     * @param string $font
25
     * @param int $size
26
     * @param int $angle
27
     */
28
    public function addWordToMask($word, Box $place, $font, $size, $angle)
29
    {
30
        $base = $this->metrics->calculateSize($word, $font, $size, $angle);
31
        foreach (str_split($word) as $letter) {
32
            $box = $this->metrics->calculateSize($letter, $font, $size);
33
34
            if ($angle === 0) {
35
                $newPos = new Point($place->getX(), $place->getY() + ($base->getHeight() - $box->getHeight()));
36
                $this->add($newPos, $box, $angle);
0 ignored issues
show
Unused Code introduced by
The call to PreciseMask::add() has too many arguments starting with $angle.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37
                $place = $place->move($box->getWidth(), 0);
38
                continue;
39
            }
40
41
            // Invert width and height
42
            $box = new Box(0, 0, $box->getHeight(), $box->getWidth());
43
44
            if ($place->getY() + ($base->getHeight() - $box->getHeight()) < 0) {
45
                continue;
46
            }
47
48
            if ($place->getX() + ($base->getWidth() - $box->getWidth()) < 0) {
49
                continue;
50
            }
51
52
            $newPos = new Point(
53
                $place->getX() + ($base->getWidth() - $box->getWidth()),
54
                $place->getY() + ($base->getHeight() - $box->getHeight())
55
            );
56
            $this->add($newPos, $box);
57
            $place = $place->move(0, -$box->getHeight());
58
        }
59
    }
60
61
}
62