Completed
Push — master ( e3ac1d...99fd83 )
by Francis
02:01 queued 30s
created

Message::__get()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
defined('BASEPATH') OR exit('No direct script access allowed');
3
4
class Message
5
{
6
  /**
7
   * [protected description]
8
   * @var [type]
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...
9
   */
10
  protected $message;
11
12
  public function __construct($jsonString)
13
  {
14
    $this->message = json_decode($jsonString);
15
  }
16
  /**
17
   * [__get description]
18
   * @date   2019-11-23
19
   * @param  string     $key [description]
20
   * @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...
21
   */
22
  public function __get(string $key):string
23
  {
24
    return $this->message->{$key};
25
  }
26
  /**
27
   * [header description]
28
   * @date   2019-11-22
29
   * @param  string     $key [description]
30
   * @return string          [description]
31
   */
32
  public function header(string $key):string
33
  {
34
    foreach ($this->message->payload->headers as $header) {
35
      if ($header->name == $key) {
36
        return $header->value;
37
      }
38
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
39
  }
40
  /**
41
   * [isMultiPart description]
42
   * @date   2019-11-23
43
   * @return bool       [description]
44
   */
45
  public function isMultiPart():bool
46
  {
47
    return isset($this->message->payload->parts);
48
  }
49
  /**
50
   * [getSize description]
51
   * @date   2019-11-23
52
   * @return int        [description]
53
   */
54
  public function getSize():int
55
  {
56
    return $this->message->payload->body->size;
57
  }
58
  /**
59
   * [body description]
60
   * @date   2019-11-23
61
   * @param  integer    $partId [description]
62
   * @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...
63
   */
64
  public function body(int $partId=0)
65
  {
66
    if ($this->isMultiPart()) {
67
      return new MessagePart($this->message->payload->parts[$partId]);
68
    }
69
70
    return base64url_decode($this->message->payload->body->data);
71
  }
72
}
73