Target   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

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