Completed
Push — master ( e43f1a...57db71 )
by Arman
26s queued 12s
created

Body::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.4.0
13
 */
14
15
namespace Quantum\Http\Response;
16
17
/**
18
 * Trait Body
19
 * @package Quantum\Http\Response
20
 */
21
trait Body
22
{
23
24
    /**
25
     * Response
26
     * @var array
27
     */
28
    private static $__response = [];
29
    
30
    /**
31
     * Checks if response contains a data by given key
32
     * @param string $key
33
     * @return bool
34
     */
35
    public static function has(string $key): bool
36
    {
37
        return isset(self::$__response[$key]);
38
    }
39
40
    /**
41
     * Gets the data from response by given key
42
     * @param string $key
43
     * @param string|null $default
44
     * @return mixed
45
     */
46
    public static function get(string $key, string $default = null)
47
    {
48
        return self::has($key) ? self::$__response[$key] : $default;
49
    }
50
51
    /**
52
     * Sets new key/value pair into response
53
     * @param string $key
54
     * @param mixed $value
55
     */
56
    public static function set(string $key, $value)
57
    {
58
        self::$__response[$key] = $value;
59
    }
60
61
    /**
62
     * Gets all response parameters
63
     * @return array
64
     */
65
    public static function all(): array
66
    {
67
        return self::$__response;
68
    }
69
70
    /**
71
     * Deletes the element from response by given key
72
     * @param string $key
73
     */
74
    public static function delete(string $key)
75
    {
76
        if (self::has($key)) {
77
            unset(self::$__response[$key]);
78
        }
79
    }
80
81
}