Metadata::export()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pagantis\OrdersApiClient\Model\Order;
4
5
use Pagantis\OrdersApiClient\Model\AbstractModel;
6
7
/**
8
 * Class Metadata
9
 * @package Pagantis\OrdersApiClient\Model\Order
10
 */
11
class Metadata extends AbstractModel
12
{
13
    /**
14
     * @param $key
15
     * @param $value
16
     *
17
     * @return $this
18
     */
19
    public function addMetadata($key, $value)
20
    {
21
        $this->{$key} = $value;
22
23
        return $this;
24
    }
25
26
    /**
27
     * @param $object
28
     *
29
     */
30
    public function import($object)
31
    {
32
        foreach ($object as $key => $value) {
33
            $this->addMetadata($key, $value);
34
        }
35
    }
36
37
    /**
38
     * Metadata will not use Str::ToCamelCase because we respect the merchant naming convention.
39
     *
40
     * @param bool $validation
41
     *
42
     * @return \stdClass
43
     */
44
    public function export($validation = true)
45
    {
46
        $result = new \stdClass();
47
        foreach ($this as $key => $value) {
48
            if ($value) {
49
                $result->{$key} = $value;
50
            }
51
        }
52
53
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result returns the type stdClass which is incompatible with the return type mandated by Pagantis\OrdersApiClient...odelInterface::export() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
54
    }
55
}
56