Completed
Push — master ( 312098...b95ba9 )
by Nikolas
40:06
created

CurirParameterReader::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace rtens\domin\delivery\web\adapters\curir;
3
4
use rtens\domin\delivery\ParameterReader;
5
use rtens\domin\Parameter;
6
use watoki\collections\Collection;
7
use watoki\curir\delivery\WebRequest;
8
use watoki\curir\protocol\UploadedFile;
9
10
class CurirParameterReader implements ParameterReader {
11
12
    /** @var WebRequest */
13
    private $request;
14
15
    public function __construct(WebRequest $request) {
16
        $this->request = $request;
17
    }
18
19
    /**
20
     * IMPORTANT: files must be properly merged into the parameters
21
     *
22
     * @param Parameter $parameter
23
     * @return mixed The serialized paramater
24
     */
25
    public function read(Parameter $parameter) {
26
        return $this->map($this->request->getArguments()->get($parameter->getName()));
27
    }
28
29
    /**
30
     * @param Parameter $parameter
31
     * @return boolean
32
     */
33
    public function has(Parameter $parameter) {
34
        return $this->request->getArguments()->has($parameter->getName());
35
    }
36
37 View Code Duplication
    private function map($value) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
        if (is_array($value) || $value instanceof Collection) {
39
            $mapped = [];
40
            foreach ($value as $key => $item) {
41
                $mapped[$key] = $this->map($item);
42
            }
43
            return $mapped;
44
        } else if ($value instanceof UploadedFile) {
0 ignored issues
show
Bug introduced by
The class watoki\curir\protocol\UploadedFile does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
45
            return [
46
                'name' => $value->getName(),
47
                'tmp_name' => $value->getTemporaryName(),
48
                'error' => $value->getError(),
49
                'size' => $value->getSize(),
50
                'type' => $value->getType()
51
            ];
52
        } else {
53
            return $value;
54
        }
55
    }
56
}