Completed
Pull Request — master (#151)
by
unknown
11:44
created

ImageUploadAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Admin\Action;
4
5
use Psr\Http\Message\ResponseInterface as Response;
6
use Psr\Http\Message\ServerRequestInterface as RequestInterface;
7
use Zend\Http\PhpEnvironment\Request;
8
use Zend\Diactoros\Response\JsonResponse;
9
use UploadHelper\Upload;
10
11
/**
12
 * Class ImageUploadAction.
13
 */
14
final class ImageUploadAction
15
{
16
17
    /**
18
     * IndexAction constructor.
19
     *
20
     * @param Template $template template engine
0 ignored issues
show
Bug introduced by
There is no parameter named $template. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
21
     */
22
    public function __construct(Upload $upload)
23
    {
24
        $this->upload = $upload;
0 ignored issues
show
Bug introduced by
The property upload does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    /**
28
     * Executed when action is called.
29
     *
30
     * @param RequestInterface       $request  request
31
     * @param Response      $response response
32
     * @param callable|null $next     next middleware
33
     *
34
     * @return JsonResponse
35
     */
36
    public function __invoke(RequestInterface $request, Response $response, callable $next = null)
37
    {
38
        $data = $request->getParsedBody();
39
        $data += (new Request())->getFiles()->toArray();
40
        $imagePath = $this->upload->uploadImage($data, 'file');
41
42
        return new JsonResponse(['location' => $imagePath]);
43
    }
44
}
45