These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | * @inheritDoc |
||
44 | */ |
||
45 | public function getCode() |
||
46 | { |
||
47 | return 'hacked'; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param EventSubscriberInterface $listener |
||
52 | */ |
||
53 | public function addLoggerListener(EventSubscriberInterface $listener) |
||
54 | { |
||
55 | $this->getDispatcher()->addSubscriber($listener); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @inheritDoc |
||
60 | */ |
||
61 | public function getDispatcher() |
||
62 | { |
||
63 | if (!isset($this->dispatcher)) { |
||
64 | $this->dispatcher = new EventDispatcher(); |
||
0 ignored issues
–
show
|
|||
65 | } |
||
66 | |||
67 | return $this->dispatcher; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | public function setDispatcher(EventDispatcherInterface $dispatcher) |
||
74 | { |
||
75 | $this->dispatcher = $dispatcher; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @inheritDoc |
||
80 | */ |
||
81 | public function prepare() |
||
82 | { |
||
83 | |||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @inheritDoc |
||
88 | */ |
||
89 | public function process(array $projects, $options = array()) |
||
90 | { |
||
91 | if (empty($projects)) { |
||
92 | return array(); |
||
93 | } |
||
94 | |||
95 | $reports = array(); |
||
96 | $release_history = new ReleaseHistory(); |
||
97 | |||
98 | /** @var Project $project */ |
||
99 | foreach ($projects as $project) { |
||
100 | $release_history->prepare($project); |
||
101 | |||
102 | $event = new CerbereDoActionEvent($this, $project); |
||
103 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DO_ACTION, $event); |
||
104 | |||
105 | if ($filename = $project->getFilename()) { |
||
106 | $current_dir = getcwd(); |
||
107 | // Change current directory to the module directory. |
||
108 | chdir(dirname($filename)); |
||
109 | |||
110 | $hacked = new HackedProject($project); |
||
111 | $result = $hacked->computeReport(); |
||
112 | |||
113 | $report = array( |
||
114 | 'project' => $project->getProject(), |
||
115 | 'type' => $project->getProjectType(), |
||
116 | 'version' => $project->getVersion(), |
||
117 | 'version_date' => $project->getDatestamp(), |
||
118 | 'status' => $result['status'], |
||
119 | 'status_label' => HackedProject::getStatusLabel($result['status']), |
||
120 | 'modified' => $result['counts']['different'], |
||
121 | 'deleted' => $result['counts']['missing'], |
||
122 | ); |
||
123 | |||
124 | $event = new CerbereReportActionEvent($this, $project, $report); |
||
125 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_REPORT_ACTION, $event); |
||
126 | $report = $event->getReport(); |
||
127 | |||
128 | $reports[] = $report; |
||
129 | |||
130 | // Restore current directory. |
||
131 | chdir($current_dir); |
||
132 | } |
||
133 | |||
134 | $event = new CerbereDoneActionEvent($this, $project); |
||
135 | $this->getDispatcher()->dispatch(CerbereEvents::CERBERE_DONE_ACTION, $event); |
||
136 | } |
||
137 | |||
138 | return $reports; |
||
139 | } |
||
140 | } |
||
141 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: