Passed
Push — main ( 7a1dde...fa78d7 )
by Iain
04:20
created

CustomerManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 15
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCustomerForReference() 0 6 2
A __construct() 0 2 1
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\Customer;
16
17
use Parthenon\Billing\Entity\CustomerInterface;
18
use Parthenon\Billing\Exception\NoCustomerException;
19
use Parthenon\Billing\Repository\CustomerRepositoryInterface;
20
use Parthenon\Common\Exception\NoEntityFoundException;
21
22
final class CustomerManager implements CustomerManagerInterface
23
{
24
    public function __construct(private CustomerRepositoryInterface $customerRepository)
25
    {
26
    }
27
28
    /**
29
     * @throws NoCustomerException
30
     */
31
    public function getCustomerForReference(string $reference): CustomerInterface
32
    {
33
        try {
34
            $customer = $this->customerRepository->getByExternalReference($reference);
0 ignored issues
show
Unused Code introduced by
The assignment to $customer is dead and can be removed.
Loading history...
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Parthenon\Billing\Entity\CustomerInterface. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
35
        } catch (NoEntityFoundException $e) {
36
            throw new NoCustomerException();
37
        }
38
    }
39
}
40