CollectionHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 7 2
A deserialize() 0 13 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Majora\Framework\Serializer\Handler\Collection;
4
5 2
@trigger_error('The '.__NAMESPACE__.'\CollectionHandler class is deprecated and will be removed in 2.0. Use Majora\Framework\Normalizer\MajoraNormalizer instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
6
7
use Majora\Framework\Serializer\Handler\FormatHandlerInterface;
8
use Majora\Framework\Serializer\Model\SerializableInterface;
9
10
/**
11
 * Handler implementation creating and using arrays.
12
 */
13
class CollectionHandler implements FormatHandlerInterface
14
{
15
    /**
16
     * @see FormatHandlerInterface::serialize()
17
     */
18 8
    public function serialize($data, $scope)
19
    {
20 8
        return $data instanceof SerializableInterface ?
21 5
            $data->serialize($scope) :
22 4
            (array) $data
23 4
        ;
24
    }
25
26
    /**
27
     * @see FormatHandlerInterface::deserialize()
28
     */
29 8
    public function deserialize($data, $output)
30
    {
31 8
        if (!class_exists($output)) {
32 4
            return $data;
33
        }
34
35 4
        $object = new $output();
36
37 4
        return $object instanceof SerializableInterface ?
38 3
            $object->deserialize($data) :
39 2
            $object
40 2
        ;
41
    }
42
}
43