Completed
Push — refactoring-session ( a6dec9 )
by Kamil
06:43
created

DashboardStatistics   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTotalSales() 0 4 1
A __construct() 0 7 1
A getChannel() 0 4 1
A getNumberOfNewOrders() 0 4 1
A getNumberOfNewCustomers() 0 4 1
A getAverageOrderValue() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Core\Dashboard;
15
16
use Sylius\Component\Core\Model\ChannelInterface;
17
18
class DashboardStatistics
19
{
20
    /**
21
     * @var ChannelInterface
22
     */
23
    private $channel;
24
25
    /** @var int */
26
    private $totalSales;
27
28
    /** @var int */
29
    private $numberOfNewOrders;
30
31
    /** @var int */
32
    private $numberOfNewCustomers;
33
34
    /**
35
     * @throws \InvalidArgumentException
36
     */
37
    public function __construct(ChannelInterface $channel, int $totalSales, int $numberOfNewOrders, int $numberOfNewCustomers)
38
    {
39
        $this->channel = $channel;
40
        $this->totalSales = $totalSales;
41
        $this->numberOfNewOrders = $numberOfNewOrders;
42
        $this->numberOfNewCustomers = $numberOfNewCustomers;
43
    }
44
45
    public function getChannel(): ChannelInterface
46
    {
47
        return $this->channel;
48
    }
49
50
    public function getTotalSales(): int
51
    {
52
        return $this->totalSales;
53
    }
54
55
    public function getNumberOfNewOrders(): int
56
    {
57
        return $this->numberOfNewOrders;
58
    }
59
60
    public function getNumberOfNewCustomers(): int
61
    {
62
        return $this->numberOfNewCustomers;
63
    }
64
65
    public function getAverageOrderValue(): int
66
    {
67
        if (0 === $this->numberOfNewOrders) {
68
            return 0;
69
        }
70
71
        return (int) round($this->totalSales / $this->numberOfNewOrders);
72
    }
73
}
74