Issues (18)

src/Http/UpDownRequest.php (1 issue)

1
<?php
2
/**
3
 * Copyright (c) 2019 - present
4
 * updown - UpDownRequest.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 15/2/2019
8
 * MIT license: https://github.com/biscolab/updown-php/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\UpDown\Http;
12
13
use Biscolab\UpDown\Abstracts\AbstractObject;
14
15
/**
16
 * Class UpDownRequest
17
 * @package Biscolab\UpDown\Http
18
 */
19
class UpDownRequest
20
{
21
22
    /**
23
     * @var array
24
     */
25
    private $params = [];
26
27
    /**
28
     * UpDownRequest constructor.
29
     *
30
     * @param array $params
31
     */
32
    public function __construct(array $params = [])
33
    {
34
35
        if ($params) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $params of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
36
            foreach ($params as $param_name => $param_value) {
37
                $this->addParam($param_name, $param_value);
38
            }
39
        }
40
    }
41
42
    /**
43
     * @param string         $param_name
44
     * @param AbstractObject $param_value
45
     *
46
     * @return UpDownRequest
47
     */
48
    public function addParam(string $param_name, $param_value): UpDownRequest
49
    {
50
51
        $this->params[$param_name] = $param_value;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getQuery(): string
60
    {
61
62
        $params = [];
63
64
        foreach ($this->params as $param_name => $param_value) {
65
            $params[$param_name] = (string)$param_value;
66
        }
67
68
        return http_build_query($params);
69
    }
70
71
}