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

MessagePart::getSize()   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 0
1
<?php
2
declare(strict_types=1);
3
4
defined('BASEPATH') OR exit('No direct script access allowed');
5
6
class MessagePart
7
{
8
  /**
9
   * [protected description]
10
   * @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...
11
   */
12
  protected $part;
13
  /**
14
   * [__construct description]
15
   * @date  2019-11-23
16
   * @param [type]     $part [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...
17
   */
18
  function __construct($part)
19
  {
20
    $this->part = $part;
21
  }
22
  /**
23
   * [__get description]
24
   * @date   2019-11-23
25
   * @param  string     $key [description]
26
   * @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...
27
   */
28
  public function __get(string $key):string
29
  {
30
    return $this->part->{$key};
31
  }
32
  /**
33
   * [header description]
34
   * @date   2019-11-22
35
   * @param  string     $key [description]
36
   * @return string          [description]
37
   */
38
  public function header(string $key):string
39
  {
40
    foreach ($this->part->headers as $header) {
41
      if ($header->name == $key) {
42
        return $header->value;
43
      }
44
    }
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...
45
  }
46
  /**
47
   * [getSize description]
48
   * @date   2019-11-23
49
   * @return int        [description]
50
   */
51
  public function getSize():int
52
  {
53
    return $this->part->body->size;
54
  }
55
  /**
56
   * [body description]
57
   * @date   2019-11-23
58
   * @param  integer    $partId [description]
59
   * @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...
60
   */
61
  public function body(int $partId=0)
0 ignored issues
show
Unused Code introduced by
The parameter $partId is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
  public function body(/** @scrutinizer ignore-unused */ int $partId=0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
  {
63
    return base64url_decode($this->part->body->data);
64
  }
65
}
66
?>
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...
67