Rectangle   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A writeRectangleArray() 0 9 1
1
<?php
2
/**
3
 * BaconPdf
4
 *
5
 * @link      http://github.com/Bacon/BaconPdf For the canonical source repository
6
 * @copyright 2015 Ben Scholzen (DASPRiD)
7
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
8
 */
9
10
namespace Bacon\Pdf;
11
12
use Bacon\Pdf\Writer\ObjectWriter;
13
14
/**
15
 * Rectangle data structure as defiend in section 3.8.4.
16
 */
17
final class Rectangle
18
{
19
    /**
20
     * @var float
21
     */
22
    private $x1;
23
24
    /**
25
     * @var float
26
     */
27
    private $y1;
28
29
    /**
30
     * @var float
31
     */
32
    private $x2;
33
34
    /**
35
     * @var float
36
     */
37
    private $y2;
38
39
    /**
40
     * Creates a new rectangle.
41
     *
42
     * It doesn't matter in which way you specify the corners, as they will internally be normalized.
43
     *
44
     * @param float $x1
45
     * @param float $y1
46
     * @param float $x2
47
     * @param float $y2
48
     */
49
    public function __construct($x1, $y1, $x2, $y2)
50
    {
51
        $this->x1 = min($x1, $x2);
52
        $this->y1 = min($y1, $y2);
53
        $this->x2 = max($x1, $x2);
54
        $this->y2 = max($y1, $y2);
55
    }
56
57
    /**
58
     * Writes the rectangle object to a writer.
59
     *
60
     * @param ObjectWriter $objectWriter
61
     * @internal
62
     */
63
    public function writeRectangleArray(ObjectWriter $objectWriter)
64
    {
65
        $objectWriter->startArray();
66
        $objectWriter->writeNumber($this->x1);
67
        $objectWriter->writeNumber($this->y1);
68
        $objectWriter->writeNumber($this->x2);
69
        $objectWriter->writeNumber($this->y2);
70
        $objectWriter->endArray();
71
    }
72
}
73