Completed
Pull Request — master (#76)
by Luke
02:26
created

IsSerializable   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
wmc 1
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
unserialize() 0 1 ?
toArray() 0 1 ?
A serialize() 0 4 1
1
<?php
2
/**
3
 * Nozavroni/Collections
4
 * Just another collections library for PHP5.6+.
5
 * @version   {version}
6
 * @copyright Copyright (c) 2016 Luke Visinoni <[email protected]>
7
 * @author    Luke Visinoni <[email protected]>
8
 * @license   https://github.com/deni-zen/csvelte/blob/master/LICENSE The MIT License (MIT)
9
 */
10
namespace Noz\Traits;
11
12
/**
13
 * Interface IsSerializable.
14
 *
15
 * Ensures a class can be converted to an array using toArray()
16
 *
17
 * @package Noz\Contracts
18
 */
19
trait IsSerializable
20
{
21
    /**
22
     * Serialize collection data and return it.
23
     *
24
     * @return string
25
     */
26
    public function serialize()
27
    {
28
        return serialize($this->toArray());
29
    }
30
31
    /**
32
     * Unserialize serialized data.
33
     *
34
     * @param string $serialized The serialized data
35
     */
36
    abstract public function unserialize($serialized);
37
38
    /**
39
     * @return array
40
     */
41
    abstract public function toArray();
42
}
43