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

JSON   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 4
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_array($value)) {
27
          $data = $value;
28
        } else {
29
          if(!is_string($value)) {
30
            throw new Exception\InvalidArgument('Parameter '.$param->name.' expects a json string. ' . gettype($value).' given.');
31
          }
32
33
          $data = json_decode($value);
34
35
          if($data === null) {
36
              throw new Exception\InvalidArgument('Parameter '.$param->name.' expects a valid json string. ' . json_last_error_msg());
37
          }
38
        }
39
40
        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...
41
    }
42
}
43