Info   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 19.54 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCode() 0 4 1
A getProjects() 0 10 2
A getProject() 0 4 1
A processContent() 17 17 3
A processFile() 0 6 1
A supportedFile() 0 4 1

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
/**
4
 * Drush Cerbere command line tools.
5
 * Copyright (C) 2015 - Sebastien Malot <[email protected]>
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along
18
 * with this program; if not, write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
 */
21
22
namespace Cerbere\Parser;
23
24
use Cerbere\Model\Project;
25
26
/**
27
 * Class Info
28
 * @package Cerbere\Parser
29
 */
30
class Info extends Ini
31
{
32
    /**
33
     * @var Project
34
     */
35
    protected $project;
36
37
    /**
38
     *
39
     */
40
    public function __construct()
41
    {
42
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getCode()
49
    {
50
        return 'info';
51
    }
52
53
    /**
54
     * @return Project[]
55
     */
56
    public function getProjects()
57
    {
58
        $project = $this->getProject();
59
60
        if (null !== $project) {
61
            return array($project);
62
        }
63
64
        return array();
65
    }
66
67
    /**
68
     * @return Project|null
69
     */
70
    public function getProject()
71
    {
72
        return $this->project;
73
    }
74
75
    /**
76
     * @param string $content
77
     * @param string $filename
78
     */
79 View Code Duplication
    public function processContent($content, $filename = null)
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...
80
    {
81
        $data = $this->parseContent($content);
82
83
        if (!empty($data['project'])) {
84
            $data += array('version' => '');
85
86
            $project = new Project($data['project'], $data['core'], $data['version']);
87
            $project->setDetails($data);
88
89
            if (!empty($filename)) {
90
                $project->setFilename(realpath($filename));
91
            }
92
93
            $this->project = $project;
94
        }
95
    }
96
97
    /**
98
     * @param string $filename
99
     */
100
    public function processFile($filename)
101
    {
102
        $content = file_get_contents($filename);
103
104
        $this->processContent($content, $filename);
105
    }
106
107
    /**
108
     * @parser string $filename
109
     *
110
     * @return bool
111
     */
112
    public function supportedFile($filename)
113
    {
114
        return preg_match('/\.info$/i', $filename) > 0;
115
    }
116
}
117