Completed
Push — master ( fe643b...2e3f04 )
by Patrick
03:45
created

JSONSerializer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 44 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 11
loc 25
rs 10
c 1
b 0
f 1
wmc 5
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsType() 11 11 3
A serializeData() 0 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Serialize;
3
4
class JSONSerializer implements ISerializer
5
{
6
    private $types = array('json', 'application/json', 'application/x-javascript', 'text/javascript', 'text/x-javascript', 'text/x-json');
7
8 View Code Duplication
    public function supportsType($type)
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...
9
    {
10
        foreach($this->types as $t)
11
        {
12
            if(strcasecmp($t, $type) === 0)
13
            {
14
                return true;
15
            }
16
        }
17
        return false;
18
    }
19
 
20
    public function serializeData($type, $array)
21
    {
22
        if($this->supportsType($type) === false)
23
        {
24
            return null;
25
        }
26
        return json_encode($array);
27
    }
28
}
29
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
30