Completed
Pull Request — master (#447)
by Alexandru
03:28 queued 21s
created

QueryParameters   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A __construct() 0 4 1
A all() 0 8 1
A get() 0 4 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Server;
4
5
use Psr\Http\Message\RequestInterface;
6
7
class QueryParameters
8
{
9
    /**
10
     * The Request object.
11
     *
12
     * @var \Psr\Http\Message\RequestInterface
13
     */
14
    protected $request;
15
16
    public static function create(RequestInterface $request)
17
    {
18
        return new static($request);
19
    }
20
21
    /**
22
     * Initialize the class.
23
     *
24
     * @param  \Psr\Http\Message\RequestInterface  $request
25
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
26
     */
27
    public function __construct(RequestInterface $request)
28
    {
29
        $this->request = $request;
30
    }
31
32
    /**
33
     * Get all query parameters.
34
     *
35
     * @return array
36
     */
37
    public function all(): array
38
    {
39
        $queryParameters = [];
40
41
        parse_str($this->request->getUri()->getQuery(), $queryParameters);
42
43
        return $queryParameters;
44
    }
45
46
    /**
47
     * Get a specific query parameter.
48
     *
49
     * @param  string  $name
50
     * @return string
51
     */
52
    public function get(string $name): string
53
    {
54
        return $this->all()[$name] ?? '';
55
    }
56
}
57