Issues (92)

src/Request/Traits/HasJsonParameterBag.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Nip\Http\Request\Traits;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
7
/**
8
 * Trait HasJsonParameterBag
9
 * @package Nip\Http\Request\Traits
10
 */
11
trait HasJsonParameterBag
12
{
13
14
    /**
15
     * The decoded JSON content for the request.
16
     *
17
     * @var \Symfony\Component\HttpFoundation\ParameterBag|null
18
     */
19
    protected $json;
20
21
    /**
22
     * Get the JSON payload for the request.
23
     *
24
     * @param string|null $key
25
     * @param mixed $default
26
     * @return \Symfony\Component\HttpFoundation\ParameterBag|mixed
27
     */
28
    public function json($key = null, $default = null)
29
    {
30
        if (!isset($this->json)) {
31
            $this->json = new ParameterBag((array)json_decode($this->getContent(), true));
0 ignored issues
show
It seems like getContent() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

31
            $this->json = new ParameterBag((array)json_decode($this->/** @scrutinizer ignore-call */ getContent(), true));
Loading history...
32
        }
33
34
        if (is_null($key)) {
35
            return $this->json;
36
        }
37
38
        return data_get($this->json->all(), $key, $default);
0 ignored issues
show
The method all() does not exist on null. ( Ignorable by Annotation )

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

38
        return data_get($this->json->/** @scrutinizer ignore-call */ all(), $key, $default);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
    }
40
}
41