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\Action; |
23
|
|
|
|
24
|
|
|
use Cerbere\Event\CerbereDoActionEvent; |
25
|
|
|
use Cerbere\Event\CerbereDoneActionEvent; |
26
|
|
|
use Cerbere\Event\CerbereEvents; |
27
|
|
|
use Cerbere\Event\CerbereReportActionEvent; |
28
|
|
|
use Cerbere\Model\Hacked\HackedProject; |
29
|
|
|
use Cerbere\Model\Project; |
30
|
|
|
use Cerbere\Model\ReleaseHistory; |
31
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
32
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
33
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class Hacked |
37
|
|
|
* |
38
|
|
|
* @package Cerbere\Action |
39
|
|
|
*/ |
40
|
|
|
class Hacked implements ActionInterface |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* @var EventDispatcherInterface |
44
|
|
|
*/ |
45
|
|
|
protected $dispatcher; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritDoc |
49
|
|
|
*/ |
50
|
|
|
public function getCode() |
51
|
|
|
{ |
52
|
|
|
return 'hacked'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public function addLoggerListener(EventSubscriberInterface $listener) |
59
|
|
|
{ |
60
|
|
|
$this->getDispatcher()->addSubscriber($listener); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritDoc |
65
|
|
|
*/ |
66
|
|
|
public function getDispatcher() |
67
|
|
|
{ |
68
|
|
|
if (!isset($this->dispatcher)) { |
69
|
|
|
$this->dispatcher = new EventDispatcher(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->dispatcher; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritDoc |
77
|
|
|
*/ |
78
|
|
|
public function setDispatcher(EventDispatcherInterface $dispatcher) |
79
|
|
|
{ |
80
|
|
|
$this->dispatcher = $dispatcher; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritDoc |
85
|
|
|
*/ |
86
|
|
|
public function prepare() |
87
|
|
|
{ |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritDoc |
93
|
|
|
*/ |
94
|
|
|
public function process(array $projects, $options = array()) |
95
|
|
|
{ |
96
|
|
|
if (empty($projects)) { |
97
|
|
|
return array(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$reports = array(); |
101
|
|
|
$release_history = new ReleaseHistory(); |
102
|
|
|
|
103
|
|
|
/** @var Project $project */ |
104
|
|
|
foreach ($projects as $project) { |
105
|
|
|
$release_history->prepare($project); |
106
|
|
|
|
107
|
|
|
$event = new CerbereDoActionEvent($this, $project); |
108
|
|
|
$this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DO_ACTION, $event); |
109
|
|
|
|
110
|
|
|
if ($filename = $project->getFilename()) { |
|
|
|
|
111
|
|
|
$current_dir = getcwd(); |
112
|
|
|
// Change current directory to the module directory. |
113
|
|
|
chdir($project->getWorkingDirectory()); |
114
|
|
|
|
115
|
|
|
$hacked = new HackedProject($project); |
116
|
|
|
$result = $hacked->computeReport(); |
117
|
|
|
|
118
|
|
|
$report = array( |
119
|
|
|
'project' => $project->getProject(), |
120
|
|
|
'type' => $project->getProjectType(), |
121
|
|
|
'version' => $project->getVersion(), |
122
|
|
|
'version_date' => $project->getDatestamp(), |
123
|
|
|
'status' => $result['status'], |
124
|
|
|
'status_label' => HackedProject::getStatusLabel($result['status']), |
125
|
|
|
'modified' => $result['counts']['different'], |
126
|
|
|
'deleted' => $result['counts']['missing'], |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
$event = new CerbereReportActionEvent($this, $project, $report); |
130
|
|
|
$this->getDispatcher()->dispatch(CerbereEvents::CERBERE_REPORT_ACTION, $event); |
131
|
|
|
$report = $event->getReport(); |
132
|
|
|
|
133
|
|
|
$reports[] = $report; |
134
|
|
|
|
135
|
|
|
// Restore current directory. |
136
|
|
|
chdir($current_dir); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$event = new CerbereDoneActionEvent($this, $project); |
140
|
|
|
$this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DONE_ACTION, $event); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $reports; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.