ErrorException::initializeByString()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 3
Bugs 0 Features 1
Metric Value
dl 0
loc 12
rs 9.2
c 3
b 0
f 1
ccs 10
cts 10
cp 1
cc 4
eloc 9
nc 3
nop 1
crap 4
1
<?php
2
/*
3
 * Copyright 2015 Alexey Maslov <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace alxmsl\Google\AndroidPublisher\Exception;
19
20
use alxmsl\Google\InitializationInterface;
21
use Exception;
22
use stdClass;
23
24
/**
25
 * Class for AndroidPublisher API errors
26
 * @author alxmsl
27
 */
28
class ErrorException extends Exception implements InitializationInterface {
29
    /**
30
     * @var stdClass[] error objects
31
     */
32
    private $errors = [];
33
34
    /**
35
     * @return stdClass[] error objects
36
     */
37 3
    public function getErrors() {
38 3
        return $this->errors;
39
    }
40
41
    /**
42
     * @inheritdoc
43
     * @return ErrorException error instance
44
     */
45 3
    public static function initializeByString($string) {
46 3
        $Object = json_decode($string);
47 3
        if (!is_null($Object) && isset($Object->error)) {
48 3
            $ErrorException = new static($Object->error->message, $Object->error->code);
49 3
            if (isset($Object->error->errors)) {
50 2
                $ErrorException->errors = (array) $Object->error->errors;
51 2
            }
52 3
        } else {
53 2
            $ErrorException = new static($string);
54
        }
55 3
        return $ErrorException;
56
    }
57
}
58