Completed
Push — master ( 726362...d621a8 )
by Hong
03:08
created

SerializedReader   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A readFile() 15 15 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
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Shared
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Shared\Reader;
16
17
use Phossa2\Shared\Exception\RuntimeException;
18
19
/**
20
 * Read serialized formatted content from file
21
 *
22
 * @package Phossa2\Shared
23
 * @author  Hong Zhang <[email protected]>
24
 * @version 2.0.1
25
 * @since   2.0.1 added
26
 */
27 View Code Duplication
class SerializedReader extends ReaderAbstract
0 ignored issues
show
Duplication introduced by
This class 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...
28
{
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public static function readFile(/*# string */ $path)
33
    {
34
        // check first
35
        static::checkPath($path);
36
37
        // read
38
        $data = @unserialize(file_get_contents($path));
39
40
        if (false === $data) {
41
            $error = error_get_last();
42
            throw new RuntimeException($error['message']);
43
        }
44
45
        return $data;
46
    }
47
}
48