Error   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 52
rs 10
c 1
b 0
f 0
ccs 12
cts 12
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setError() 0 4 1
A isInvalidGrant() 0 3 1
A isInvalidClient() 0 3 1
A __construct() 0 1 1
A initializeByString() 0 6 1
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\OAuth2\Response;
19
20
use alxmsl\Google\InitializationInterface;
21
22
/**
23
 * Class for error response
24
 * @author alxmsl
25
 * @date 2/5/13
26
 */ 
27
final class Error implements InitializationInterface {
28
    /**
29
     * Error string constants
30
     */
31
    const STRING_INVALID_GRANT  = 'invalid_grant',
32
          STRING_INVALID_CLIENT = 'invalid_client';
33
34
    /**
35
     * @var string google error code
36
     */
37
    private $error = '';
38
39
    /**
40
     * Setter for error code
41
     * @param string $error error code
42
     * @return Error self
43
     */
44 1
    private function setError($error) {
45 1
        $this->error = (string) $error;
46 1
        return $this;
47
    }
48
49
    /**
50
     * Getter for invalid grant error
51
     * @return bool if error is invalid grant
52
     */
53 1
    public function isInvalidGrant() {
54 1
        return $this->error == self::STRING_INVALID_GRANT;
55
    }
56
57
    /**
58
     * Getter for invalid client error
59
     * @return bool if error is invalid client
60
     */
61 1
    public function isInvalidClient() {
62 1
        return $this->error == self::STRING_INVALID_CLIENT;
63
    }
64
65
    private function __construct() {}
66
67
    /**
68
     * Method for object initialization by the string
69
     * @param string $string response string
70
     * @return Error error object
71
     */
72 1
    public static function initializeByString($string) {
73 1
        $object = json_decode($string);
74 1
        $Response = new self();
75 1
        $Response->setError($object->error);
76 1
        return $Response;
77
    }
78
}
79