Response::offsetGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the EasyWeChatComposer.
7
 *
8
 * (c) 张铭阳 <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace EasyWeChatComposer\Http;
15
16
use EasyWeChat\Kernel\Contracts\Arrayable;
0 ignored issues
show
Bug introduced by
The type EasyWeChat\Kernel\Contracts\Arrayable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use EasyWeChat\Kernel\Http\Response as HttpResponse;
0 ignored issues
show
Bug introduced by
The type EasyWeChat\Kernel\Http\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use JsonSerializable;
19
20
class Response implements Arrayable, JsonSerializable
21
{
22
    /**
23
     * @var \EasyWeChat\Kernel\Http\Response
24
     */
25
    protected $response;
26
27
    /**
28
     * @var array
29
     */
30
    protected $array;
31
32
    /**
33
     * @param \EasyWeChat\Kernel\Http\Response $response
34
     */
35
    public function __construct(HttpResponse $response)
36
    {
37
        $this->response = $response;
38
    }
39
40
    /**
41
     * @see \ArrayAccess::offsetExists
42
     *
43
     * @param string $offset
44
     *
45
     * @return bool
46
     */
47
    public function offsetExists($offset)
48
    {
49
        return isset($this->toArray()[$offset]);
50
    }
51
52
    /**
53
     * @see \ArrayAccess::offsetGet
54
     *
55
     * @param string $offset
56
     *
57
     * @return mixed
58
     */
59
    public function offsetGet($offset)
60
    {
61
        return $this->toArray()[$offset] ?? null;
62
    }
63
64
    /**
65
     * @see \ArrayAccess::offsetSet
66
     *
67
     * @param string $offset
68
     * @param mixed  $value
69
     */
70
    public function offsetSet($offset, $value)
71
    {
72
        //
73
    }
74
75
    /**
76
     * @see \ArrayAccess::offsetUnset
77
     *
78
     * @param string $offset
79
     */
80
    public function offsetUnset($offset)
81
    {
82
        //
83
    }
84
85
    /**
86
     * Get the instance as an array.
87
     *
88
     * @return array
89
     */
90
    public function toArray()
91
    {
92
        return $this->array ?: $this->array = $this->response->toArray();
93
    }
94
95
    /**
96
     * Convert the object into something JSON serializable.
97
     *
98
     * @return array
99
     */
100
    public function jsonSerialize()
101
    {
102
        return $this->toArray();
103
    }
104
}
105