Completed
Push — master ( 2d0c9c...1268a4 )
by Jens
10:44
created

ApiError::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Error;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\JsonObject;
10
11
/**
12
 * @package Commercetools\Core\Error
13
 *
14
 * @method string getCode()
15
 * @method ApiError setCode(string $code = null)
16
 * @method string getMessage()
17
 * @method ApiError setMessage(string $message = null)
18
 */
19
class ApiError extends JsonObject
20
{
21 15
    public function fieldDefinitions()
22
    {
23
        return [
24 15
            'code' => [static::TYPE => 'string'],
25 15
            'message' => [static::TYPE => 'string']
26
        ];
27
    }
28
29
    /**
30
     * @param array $data
31
     * @param Context|callable $context
32
     * @return static
33
     */
34 15 View Code Duplication
    public static function fromArray(array $data, $context = null)
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...
35
    {
36 15
        if (isset($data['code'])) {
37 15
            $className = '\Commercetools\Core\Error\\' . ucfirst($data['code']) . 'Error';
38 15
            if (class_exists($className)) {
39 15
                return new $className($data, $context);
40
            }
41
        }
42
        return new static($data, $context);
43
    }
44
}
45