CategoryPresenter::getTax()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace App\Libraries\Presenterable\Presenters;
4
5
use App\Traits\HasImagesPresentable;
6
7
class CategoryPresenter extends Presenter
8
{
9
    use HasImagesPresentable;
10
11
    /**
12
     * Render tax.
13
     *
14
     * @return string
15
     */
16
    public function getTax()
17
    {
18
        $tax = $this->model->tax;
19
        if($tax <= 0)
20
            $tax = 0;
21
22
        return sprintf('%s%%', $tax);
23
    }
24
25
    /**
26
     * Render name.
27
     * 
28
     * @param bool $upper
29
     * @return mixed|string
30
     */
31
    public function renderName($upper = false)
32
    {
33
        $name = $this->model->name;
34
35
        if($upper)
36
            return strtoupper($name);
37
38
        return $name;
39
    }
40
41
    /**
42
     * Render name with tax.
43
     * 
44
     * @return string
45
     */
46
    public function renderNameWithTax()
47
    {
48
        return sprintf('%s, taxa (%s)', $this->renderName(), $this->getTax());
49
    }
50
51
    /**
52
     * Render tax of category.
53
     *
54
     * @return int
55
     */
56
    public function renderTax()
57
    {
58
        if($this->model->tax)
59
            return (int) $this->model->tax;
60
61
        return 0;
62
    }
63
}