Issues (38)

libraries/RefactorPayload.php (10 issues)

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
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
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
The condition is_object($this->payload) is always false.
Loading history...
54
    return $this->payload[$key];
55
  }
56
  /**
57
   * [__toString description]
58
   * @date   2019-11-03
59
   * @return string     [description]
60
   */
61
  public function __toString():string
62
  {
63
    $buff = $refactor->toArray();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $refactor seems to be never defined.
Loading history...
64
    if ($buff != null) return json_encode($buff);
65
66
    return json_encode($this->payload);
67
  }
68
  /**
69
   * [__debugInfo description]
70
   * @date   2019-11-03
71
   * @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...
72
   */
73
  public function __debugInfo():array
74
  {
75
    return [
76
      'payload' => $this->payload
77
    ];
78
  }
79
  /**
80
   * [setPayload description]
81
   * @date  2019-11-02
82
   * @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...
83
   */
84
  public function setPayload($payload):void
85
  {
86
    $this->payload = $payload;
87
  }
88
  /**
89
   * [set_payload description]
90
   * @date  2019-11-02
91
   * @param array      $payload [description]
92
   */
93
  public function switchPayload(&$payload):void
94
  {
95
    $this->payload =& $payload;
96
  }
97
  /**
98
   * [toArray description]
99
   * @date   2019-11-02
100
   * @return array      [description]
101
   */
102
  public function toArray():array
103
  {
104
    if (is_array($this->payload)) return $this->payload;
0 ignored issues
show
The condition is_array($this->payload) is always true.
Loading history...
105
    return json_decode(json_encode($this->payload), true);
106
  }
107
}
108
?>
0 ignored issues
show
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...
109