Issues (113)

src/bill/BillFactory.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\bill;
12
13
use DateTimeImmutable;
14
use hiqdev\billing\hiapi\action\UsageIntervalHydrator;
0 ignored issues
show
The type hiqdev\billing\hiapi\action\UsageIntervalHydrator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use hiqdev\php\billing\action\UsageInterval;
16
17
/**
18
 * Default bill factory.
19
 *
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class BillFactory implements BillFactoryInterface
23
{
24 2
    /**
25
     * Creates bill object.
26 2
     * @return Bill
27 2
     */
28 2
    public function create(BillCreationDto $dto)
29 2
    {
30 2
        $bill = new Bill(
31 2
            $dto->id,
32 2
            $dto->type,
33 2
            $dto->time,
34 2
            $dto->sum,
35 2
            $dto->quantity,
36 2
            $dto->customer,
37
            $dto->target,
38
            $dto->plan,
39
            $dto->charges ?: [],
40
            $dto->state
41
        );
42
        if (!empty($dto->usageInterval)) {
43
            if ($dto->usageInterval instanceof UsageInterval) {
44
                $interval = $dto->usageInterval;
45
            } else {
46
                $month = $dto->usageInterval['month']['date'];
47
                $start = $dto->usageInterval['start']['date'];
48
                $end = $dto->usageInterval['end']['date'];;
49
                $interval = UsageInterval::withinMonth(
50
                    new DateTimeImmutable($month),
51
                    new DateTimeImmutable($start),
52
                    new DateTimeImmutable($end)
53
                );
54
            }
55
            $bill->setUsageInterval($interval);
56
        }
57
        return $bill;
58
    }
59
}
60