Completed
Push — master ( 9c72bc...5cbbf2 )
by Francis
01:53
created

RefactorPayload::switchPayload()   A

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
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
defined('BASEPATH') OR exit('No direct script access allowed');
5
6
class RefactorPayload
7
{
8
  protected $payload;
9
  /**
10
   * [__construct description]
11
   * @date  2019-11-02
12
   * @param array      $payload [description]
13
   */
14
  public function __construct($payload=[])
15
  {
16
    $this->payload = $payload;
17
  }
18
  /**
19
   * [__set description]
20
   * @date  2019-11-02
21
   * @param string     $key   [description]
22
   * @param [type]     $value [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
23
   */
24
  public function __set(string $key, $value):void
25
  {
26
    if (is_object($this->payload)) {
0 ignored issues
show
introduced by
The condition is_object($this->payload) is always false.
Loading history...
27
      $this->payload->$key = $value;
28
      return;
29
    }
30
    $this->payload[$key] = $value;
31
  }
32
  /**
33
   * [__unset description]
34
   * @date  2019-11-02
35
   * @param string     $key [description]
36
   */
37
  public function __unset(string $key):void
38
  {
39
    if (is_object($this->payload)) {
0 ignored issues
show
introduced by
The condition is_object($this->payload) is always false.
Loading history...
40
      unset($this->payload->$key);
41
      return;
42
    }
43
    unset($this->payload[$key]);
44
  }
45
  /**
46
   * [__get description]
47
   * @date   2019-11-02
48
   * @param  string     $key [description]
49
   * @return [type]          [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
50
   */
51
  public function __get(string $key)
52
  {
53
    if (is_object($this->payload)) return $this->payload->$key;
0 ignored issues
show
introduced by
The condition is_object($this->payload) is always false.
Loading history...
54
    return $this->payload[$key];
55
  }
56
  /**
57
   * [setPayload description]
58
   * @date  2019-11-02
59
   * @param [type]     $payload [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
60
   */
61
  public function setPayload($payload):void
62
  {
63
    $this->payload = $payload;
64
  }
65
  /**
66
   * [set_payload description]
67
   * @date  2019-11-02
68
   * @param array      $payload [description]
69
   */
70
  public function switchPayload(&$payload):void
71
  {
72
    $this->payload =& $payload;
73
  }
74
  /**
75
   * [toArray description]
76
   * @date   2019-11-02
77
   * @return array      [description]
78
   */
79
  public function toArray():array
80
  {
81
    if (is_array($this->payload)) return $this->payload;
0 ignored issues
show
introduced by
The condition is_array($this->payload) is always true.
Loading history...
82
    return json_decode(json_encode($this->payload), true);
83
  }
84
}
85
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
86