Rectangle::getWidth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
namespace mrcnpdlk\Grandstream\XMLApp\Helper;
16
17
/**
18
 * Class Rectangle
19
 *
20
 * @package mrcnpdlk\Grandstream\XMLApp\Helper
21
 */
22
class Rectangle
23
{
24
    /**
25
     * @var int
26
     */
27
    private $iWidth;
28
    /**
29
     * @var int
30
     */
31
    private $iHeight;
32
33
    /**
34
     * Rectangle constructor.
35
     *
36
     * @param int      $w
37
     * @param int|null $h
38
     */
39 4
    public function __construct(int $w, int $h = null)
40
    {
41 4
        $this->iWidth  = $w < 0 ? 0 : $w;
42 4
        $this->iHeight = $h < 0 ? 0 : ($h ?? $this->iWidth);
43 4
    }
44
45
    /**
46
     * @return int
47
     */
48 3
    public function getArea()
49
    {
50 3
        return $this->getHeight() * $this->getWidth();
51
    }
52
53
    /**
54
     * @return int
55
     */
56 3
    public function getHeight()
57
    {
58 3
        return $this->iHeight;
59
    }
60
61
    /**
62
     * @return int
63
     */
64 3
    public function getWidth()
65
    {
66 3
        return $this->iWidth;
67
    }
68
}
69