Completed
Push — master ( a39575...82bd32 )
by ARCANEDEV
21:20 queued 06:33
created

AttachedObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceWith() 0 13 3
A count() 0 4 1
1
<?php namespace Arcanedev\Stripe;
2
3
use Arcanedev\Stripe\Contracts\AttachedObject as AttachedObjectContract;
4
5
/**
6
 * Class     AttachedObject
7
 *
8
 * @package  Arcanedev\Stripe
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class AttachedObject extends StripeObject implements AttachedObjectContract
12
{
13
    /* -----------------------------------------------------------------
14
     |  Properties
15
     | -----------------------------------------------------------------
16
     */
17
18
    /** @var bool */
19
    protected $checkUnsavedAttributes = false;
20
21
    /* -----------------------------------------------------------------
22
     |  Main Functions
23
     | -----------------------------------------------------------------
24
     */
25
26
    /**
27
     * Updates this object.
28
     *
29
     * @param  array  $properties  -  A mapping of properties to update on this object.
30
     */
31 15
    public function replaceWith($properties)
32
    {
33 15
        $removed = array_diff(array_keys($this->values), array_keys($properties));
34
35
        // Don't unset, but rather set to null so we send up '' for deletion.
36 15
        foreach ($removed as $k) {
37 3
            $this->$k = null;
38 5
        }
39
40 15
        foreach ($properties as $k => $v) {
41 15
            $this->$k = $v;
42 5
        }
43 15
    }
44
45
    /**
46
     * Counts the number of elements.
47
     *
48
     * @return int
49
     */
50 12
    public function count()
51
    {
52 12
        return count($this->values);
53
    }
54
}
55