Passed
Push — master ( 8fd177...8c2cea )
by Rougin
03:08
created

Request   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 19
dl 0
loc 53
ccs 0
cts 25
cp 0
rs 10
c 3
b 1
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A uploaded() 0 17 3
A __construct() 0 21 1
1
<?php
2
3
namespace Zapheus\Bridge\Psr\Zapheus;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Zapheus\Http\Message\Request as ZapheusRequest;
7
8
/**
9
 * PSR-07 to Zapheus Server Request Bridge
10
 *
11
 * @package Zapheus
12
 * @author  Rougin Royce Gutib <[email protected]>
13
 */
14
class Request extends ZapheusRequest
15
{
16
    /**
17
     * Initializes the server request instance.
18
     *
19
     * @param \Psr\Http\Message\ServerRequestInterface $request
20
     */
21
    public function __construct(ServerRequestInterface $request)
22
    {
23
        $data = (array) $request->getParsedBody();
24
25
        $cookies = $request->getCookieParams();
26
27
        parent::__construct($request->getServerParams(), $cookies, $data);
0 ignored issues
show
Bug introduced by
$cookies of type array is incompatible with the type string expected by parameter $target of Zapheus\Http\Message\Request::__construct(). ( Ignorable by Annotation )

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

27
        parent::__construct($request->getServerParams(), /** @scrutinizer ignore-type */ $cookies, $data);
Loading history...
Bug introduced by
$request->getServerParams() of type array is incompatible with the type string expected by parameter $method of Zapheus\Http\Message\Request::__construct(). ( Ignorable by Annotation )

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

27
        parent::__construct(/** @scrutinizer ignore-type */ $request->getServerParams(), $cookies, $data);
Loading history...
28
29
        $this->set('files', $this->uploaded($request));
0 ignored issues
show
Bug introduced by
The method set() does not exist on Zapheus\Bridge\Psr\Zapheus\Request. ( Ignorable by Annotation )

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

29
        $this->/** @scrutinizer ignore-call */ 
30
               set('files', $this->uploaded($request));

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...
30
31
        $this->set('attributes', $request->getAttributes());
32
33
        $this->set('queries', $request->getQueryParams());
34
35
        $this->set('headers', (array) $request->getHeaders());
36
37
        $this->set('uri', new Uri($request->getUri()));
38
39
        $this->set('stream', new Stream($request->getBody()));
40
41
        $this->set('version', $request->getProtocolVersion());
42
    }
43
44
    /**
45
     * Returns an array of uploaded files.
46
     *
47
     * @param  \Psr\Http\Message\ServerRequestInterface $request
48
     * @return \Zapheus\Http\Message\FileInterface[]
49
     */
50
    protected function uploaded(ServerRequestInterface $request)
51
    {
52
        list($items, $uploaded) = array(array(), array());
53
54
        $items = $request->getUploadedFiles();
55
56
        foreach ((array) $items as $key => $files) {
57
            $uploaded[$key] = array();
58
59
            foreach ((array) $files as $file) {
60
                $item = new File($file);
61
62
                array_push($uploaded[$key], $item);
63
            }
64
        }
65
66
        return (array) $uploaded;
67
    }
68
}
69