Passed
Push — main ( 7d5b4b...15f1b6 )
by Sammy
18:04 queued 11:18
created

Target::controller()   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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace HexMakina\Hopper;
5
6
class Target
7
{
8
    private string $controller;
9
    private string $method;
10
11
    public function __construct(Request $request)
12
    {
13
      $res = explode('::', $request->target());
14
15
      // if explode() returned false
16
      // or if the array doesn't have a second element (the method)
17
      // or if the array has more than 2 elements
18
      if ($res === false || !isset($res[1]) || isset($res[2])) {
19
          throw new RouterException('INVALID_TARGET_FORMAT');
20
      }
21
22
      $this->controller = $res[0];
23
      $this->method = $res[1];
24
    }
25
26
    public function controller()
27
    {
28
        return $this->controller;
29
    }
30
31
    public function method()
32
    {
33
        return $this->method;
34
    }
35
}
36
?>
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...