Completed
Pull Request — master (#52)
by
unknown
03:11
created

JSON::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Balloon
6
 *
7
 * @author      Stefan Aebischer <[email protected]>
8
 * @copyright   Copryright (c) 2012-2017 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPLv3 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\Rest\v1\Parameter;
13
14
use Balloon\Exception;
15
16
class JSON extends \ArrayObject {
17
    /**
18
     * Initialize
19
     *
20
     * @param  ReflectionParameter $param
21
     * @param  string $value
22
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
23
     */
24
    public function __construct(\ReflectionParameter $param, $value)
25
    {
26
        if(!is_string($value)) {
27
          throw new Exception\InvalidArgument('Parameter '.$param->name.' expects a json string. ' . gettype($value).' given.');
28
        }
29
30
        $data = json_decode($value);
31
32
        if($data === null) {
33
            throw new Exception\InvalidArgument('Parameter '.$param->name.' expects a valid json string. ' . json_last_error_msg());
34
        }
35
36
        return call_user_func_array(array('parent', __FUNCTION__), [$data]);
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
37
    }
38
}
39