Json   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 50
ccs 6
cts 12
cp 0.5
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 10 3
A encode() 0 10 2
A getJsonService() 0 4 1
1
<?php
2
namespace SEOstats\Helper;
3
4
/**
5
 * URL-String Helper Class
6
 *
7
 * @package    SEOstats
8
 * @author     Stephan Schmitz <[email protected]>
9
 * @copyright  Copyright (c) 2010 - present Stephan Schmitz
10
 * @license    http://eyecatchup.mit-license.org/  MIT License
11
 * @updated    2013/02/03
12
 */
13
14
class Json
15
{
16
   /**
17
    * Decodes a JSON string into appropriate variable.
18
    *
19
    * @param    string  $str    JSON-formatted string
20
    * @param    boolean $accos  When true, returned objects will be converted into associative arrays.
0 ignored issues
show
Bug introduced by
There is no parameter named $accos. 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
    * @return   mixed   number, boolean, string, array, or object corresponding to given JSON input string.
22
    *                   Note that decode() always returns strings in ASCII or UTF-8 format!
23
    */
24 34
    public static function decode($str, $assoc = false)
25
    {
26 34
        if (!function_exists('json_decode')) {
27
            $j = self::getJsonService();
28
            return $j->decode($str);
29
        }
30
        else {
31 34
            return $assoc ? json_decode($str, true) : json_decode($str);
32
        }
33
    }
34
35
   /**
36
    * Encodes an arbitrary variable into JSON format.
37
    *
38
    * @param    mixed   $var    any number, boolean, string, array, or object to be encoded.
39
    *                           if var is a string, note that encode() always expects it
40
    *                           to be in ASCII or UTF-8 format!
41
    * @return   mixed   JSON string representation of input var or an error if a problem occurs
42
    */
43 2
    public static function encode($var)
44
    {
45 2
        if (!function_exists('json_encode')) {
46
            $j = self::getJsonService();
47
            return $j->encode($var);
48
        }
49
        else {
50 2
            return json_encode($var);
51
        }
52
    }
53
54
    /**
55
     * Return a new object of Services_JSON class.
56
     * Used if native PHP JSON extension is not available.
57
     */
58
    private static function getJsonService()
59
    {
60
        return new \Services_JSON();
61
    }
62
63
}
64