1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Packy. |
5
|
|
|
* |
6
|
|
|
* (c) Peter Nijssen |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AppBundle\Controller; |
13
|
|
|
|
14
|
|
|
use AppBundle\Entity\Project; |
15
|
|
|
use AppBundle\Form\Type\ProjectFormType; |
16
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
18
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
21
|
|
|
|
22
|
|
|
class ProjectController extends Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Project overview page. |
26
|
|
|
* |
27
|
|
|
* @return Response A Response instance |
28
|
|
|
*/ |
29
|
|
|
public function overviewAction() |
30
|
|
|
{ |
31
|
|
|
$projectRepository = $this->get('packy.repository.project'); |
32
|
|
|
$projects = $projectRepository->findAll(); |
33
|
|
|
|
34
|
|
|
return $this->render( |
35
|
|
|
'AppBundle:Project:overview.html.twig', |
36
|
|
|
[ |
37
|
|
|
'projects' => $projects, |
38
|
|
|
] |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Add project. |
44
|
|
|
* |
45
|
|
|
* @param Request $request A Request instance |
46
|
|
|
* |
47
|
|
|
* @return Response A Response instance |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
public function addAction(Request $request) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$project = new Project(); |
52
|
|
|
$projectForm = $this->createForm(ProjectFormType::class, $project); |
53
|
|
|
|
54
|
|
|
if ($request->isMethod('POST')) { |
55
|
|
|
$projectForm->handleRequest($request); |
56
|
|
|
if ($projectForm->isValid()) { |
57
|
|
|
$projectManager = $this->get('packy.repository.project'); |
58
|
|
|
$projectManager->create($project); |
59
|
|
|
|
60
|
|
|
return $this->redirect($this->generateUrl('packy_project_overview')); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $this->render( |
65
|
|
|
'AppBundle:Project:form.html.twig', |
66
|
|
|
[ |
67
|
|
|
'project' => $project, |
68
|
|
|
'projectForm' => $projectForm->createView(), |
69
|
|
|
] |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @ParamConverter("project", class="AppBundle:Project", options={"id" = "projectId"}) |
75
|
|
|
* |
76
|
|
|
* Analyze project |
77
|
|
|
* |
78
|
|
|
* @param Project $project |
79
|
|
|
* |
80
|
|
|
* @return Response A Response instance |
81
|
|
|
*/ |
82
|
|
|
public function analyzeAction(Project $project) |
83
|
|
|
{ |
84
|
|
|
$dependencyRepository = $this->get('packy.repository.dependency'); |
85
|
|
|
|
86
|
|
|
$dependencyManagers = $this->get('packy.dependency_managers'); |
87
|
|
|
$dependencyManagers = $dependencyManagers->getAll(); |
88
|
|
|
|
89
|
|
|
//@TODO: Refactor |
90
|
|
|
$vendors = []; |
91
|
|
|
foreach ($dependencyManagers as $manager) { |
92
|
|
|
$name = $manager->getName(); |
93
|
|
|
$dependencies = $dependencyRepository->findAllByManager($project, $name); |
94
|
|
|
if (!empty($dependencies)) { |
95
|
|
|
$vendors[$name] = $dependencies; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
//@TODO: BIG Refactor |
100
|
|
|
$stats = [ |
101
|
|
|
'outdated' => [], |
102
|
|
|
'unstable' => [], |
103
|
|
|
'stable' => [], |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
foreach ($vendors as $name => $dependencies) { |
107
|
|
|
foreach ($stats as &$stat) { |
108
|
|
|
$stat[$name] = 0; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
unset($stat); |
112
|
|
|
|
113
|
|
|
foreach ($stats as $type => $stat) { |
114
|
|
|
foreach ($dependencies as $dependency) { |
115
|
|
|
if ($dependency->getStatus() == $type) { |
116
|
|
|
$stats[$type][$name] += 1; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $this->render( |
123
|
|
|
'AppBundle:Project:analyze.html.twig', |
124
|
|
|
[ |
125
|
|
|
'project' => $project, |
126
|
|
|
'vendors' => $vendors, |
127
|
|
|
'stats' => $stats, |
128
|
|
|
] |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @ParamConverter("project", class="AppBundle:Project", options={"id" = "projectId"}) |
134
|
|
|
* |
135
|
|
|
* Edit project |
136
|
|
|
* |
137
|
|
|
* @param Request $request A Request instance |
138
|
|
|
* @param Project $project |
139
|
|
|
* |
140
|
|
|
* @return Response A Response instance |
141
|
|
|
*/ |
142
|
|
View Code Duplication |
public function editAction(Request $request, Project $project) |
|
|
|
|
143
|
|
|
{ |
144
|
|
|
$projectForm = $this->createForm(ProjectFormType::class, $project); |
145
|
|
|
|
146
|
|
|
if ($request->isMethod('POST')) { |
147
|
|
|
$projectForm->handleRequest($request); |
148
|
|
|
if ($projectForm->isValid()) { |
149
|
|
|
$projectRepository = $this->get('packy.repository.project'); |
150
|
|
|
$projectRepository->update($project); |
151
|
|
|
|
152
|
|
|
return $this->redirect($this->generateUrl('packy_project_overview')); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
return $this->render( |
157
|
|
|
'AppBundle:Project:form.html.twig', |
158
|
|
|
[ |
159
|
|
|
'project' => $project, |
160
|
|
|
'projectForm' => $projectForm->createView(), |
161
|
|
|
] |
162
|
|
|
); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @ParamConverter("project", class="AppBundle:Project", options={"id" = "projectId"}) |
167
|
|
|
* |
168
|
|
|
* Delete project |
169
|
|
|
* |
170
|
|
|
* @param Project $project |
171
|
|
|
* |
172
|
|
|
* @return RedirectResponse A Response instance |
173
|
|
|
*/ |
174
|
|
|
public function deleteAction(Project $project) |
175
|
|
|
{ |
176
|
|
|
$projectRepository = $this->get('packy.repository.project'); |
177
|
|
|
$projectRepository->delete($project); |
178
|
|
|
|
179
|
|
|
return $this->redirect($this->generateUrl('packy_project_overview')); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
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.