Passed
Push — main ( e4206e...255a41 )
by Iain
04:28
created

SubscriptionFactory::createSubscriptionWithPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Obol;
16
17
use Obol\Model\BillingDetails;
18
use Obol\Model\Subscription;
19
use Parthenon\Billing\Entity\Price;
20
use Parthenon\Billing\Plan\PlanPrice;
21
22
class SubscriptionFactory implements SubscriptionFactoryInterface
23
{
24
    public function createSubscription(
25
        BillingDetails $billingDetails,
26
        PlanPrice $planPrice,
27
        int $seatNumbers,
28
    ): Subscription {
29
        $obolSubscription = new \Obol\Model\Subscription();
30
        $obolSubscription->setBillingDetails($billingDetails);
31
        $obolSubscription->setSeats($seatNumbers);
32
        $obolSubscription->setCostPerSeat($planPrice->getPriceAsMoney());
33
        if ($planPrice->hasPriceId()) {
34
            $obolSubscription->setPriceId($planPrice->getPriceId());
0 ignored issues
show
Bug introduced by
It seems like $planPrice->getPriceId() can also be of type null; however, parameter $priceId of Obol\Model\Subscription::setPriceId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
            $obolSubscription->setPriceId(/** @scrutinizer ignore-type */ $planPrice->getPriceId());
Loading history...
35
        }
36
37
        return $obolSubscription;
38
    }
39
40
    public function createSubscriptionWithPrice(BillingDetails $billingDetails, Price $price, int $seatNumbers): Subscription
41
    {
42
        $obolSubscription = new \Obol\Model\Subscription();
43
        $obolSubscription->setBillingDetails($billingDetails);
44
        $obolSubscription->setSeats($seatNumbers);
45
        $obolSubscription->setCostPerSeat($price->getAsMoney());
46
        $obolSubscription->setPriceId($price->getExternalReference());
0 ignored issues
show
Bug introduced by
It seems like $price->getExternalReference() can also be of type null; however, parameter $priceId of Obol\Model\Subscription::setPriceId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $obolSubscription->setPriceId(/** @scrutinizer ignore-type */ $price->getExternalReference());
Loading history...
47
48
        return $obolSubscription;
49
    }
50
}
51