Passed
Pull Request — master (#11)
by Carlos C
01:36
created

Customers::findByRfc()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Services\Registration;
6
7
use LogicException;
8
use PhpCfdi\Finkok\Services\AbstractCollection;
9
use stdClass;
10
11
class Customers extends AbstractCollection
12
{
13 6
    protected function createItemFromStdClass(stdClass $content): object
14
    {
15 6
        return new Customer($content);
16
    }
17
18 2
    public function getByRfc(string $rfc): Customer
19
    {
20 2
        $customer = $this->findByRfc($rfc);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $customer is correct as $this->findByRfc($rfc) targeting PhpCfdi\Finkok\Services\...\Customers::findByRfc() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21 2
        if (null === $customer) {
0 ignored issues
show
introduced by
The condition null === $customer is always true.
Loading history...
22 1
            throw new LogicException(sprintf('There is no customer with RFC %s', $rfc));
23
        }
24 1
        return $customer;
25
    }
26
27 3
    public function findByRfc(string $rfc): ?Customer
28
    {
29
        /** @var Customer $customer */
30 3
        foreach ($this->collection as $customer) {
31 3
            if ($rfc === $customer->rfc()) {
32 3
                return $customer;
33
            }
34
        }
35 2
        return null;
36
    }
37
}
38