Info::getProjects()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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