Card::find()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 1
nop 2
crap 6
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
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 PhpMob\Omise\Api;
15
16
use PhpMob\Omise\Api;
17
use PhpMob\Omise\Domain\Card as Domain;
18
use PhpMob\Omise\Domain\Customer;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, PhpMob\Omise\Api\Customer.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use PhpMob\Omise\Domain\Pagination;
20
21
/**
22
 * @author Ishmael Doss <[email protected]>
23
 *
24
 * @see https://www.omise.co/cards-api
25
 */
26
final class Card extends Api
27
{
28
    /**
29
     * @param string $customerId
30
     * @param string $cardId
31
     *
32
     * @return string
33
     */
34
    private static function path($customerId, $cardId)
35
    {
36
        return "/customers/$customerId/cards/$cardId";
37
    }
38
39
    /**
40
     * @param Customer $customer
41
     * @param array $parameters
42
     *
43
     * @return Pagination
44
     */
45
    public function all(Customer $customer, array $parameters = [])
46
    {
47
        self::assertNotEmpty($customer->id, 'Customer Id cannot be empty.');
48
49
        return $this->doRequest('GET', "/customers/$customer->id/cards", $parameters);
50
    }
51
52
    /**
53
     * @param string $customerId
54
     * @param string $id
55
     *
56
     * @return Domain
57
     */
58
    public function find($customerId, $id)
59
    {
60
        self::assertNotEmpty($customerId && $id, 'Customer Id or Id cannot be empty.');
61
62
        return $this->doRequest('GET', self::path($customerId, $id));
63
    }
64
65
    /**
66
     * @param Domain $card
67
     */
68
    public function refresh(Domain $card)
69
    {
70
        $card->updateStore($this->find((string) ($card->customer), $card->id)->toArray());
71
    }
72
73
    /**
74
     * @param Domain $card
75
     */
76 View Code Duplication
    public function update(Domain $card)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
    {
78
        self::assertNotEmpty((string) ($card->customer) && $card->id, 'CustomerId or Id cannot be empty.');
79
80
        $card->updateStore(
81
            $this->doRequest('PATCH', self::path((string) ($card->customer), $card->id), $card->getUpdateData())->getData()
82
        );
83
    }
84
85
    /**
86
     * @param Domain $card
87
     */
88 View Code Duplication
    public function destroy(Domain $card)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        self::assertNotEmpty((string) ($card->customer) && $card->id, 'CustomerId or Id cannot be empty.');
91
92
        $card->updateStore(
93
            $this->doRequest('DELETE', self::path((string) ($card->customer), $card->id), $card->getUpdateData())->toArray()
94
        );
95
    }
96
}
97