ProjectController::addProjectAction()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 2
nop 2
1
<?php
2
3
namespace PRReviewWatcher\Controller;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use PRReviewWatcher\Entity\Project;
8
use PRReviewWatcher\Form\Type\ProjectType;
9
10
class ProjectController
11
{
12
    public function indexAction(Application $app)
13
    {
14
        $projects = $app['project_repository']->findAll();
15
16
        return $app['twig']->render('index.html.twig', array('projects' => $projects));
17
    }
18
19 View Code Duplication
    public function addProjectAction(Request $request, Application $app)
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...
20
    {
21
        $credentials = $app['credential_repository']->findAllAsArray();
22
        $project     = new Project();
23
        $projectForm = $app['form.factory']->create(new ProjectType(), $project, ['credentialChoices' => $credentials]);
24
        $projectForm->handleRequest($request);
25
26
        if ($projectForm->isSubmitted() && $projectForm->isValid()) {
27
            $app['project_repository']->save($project);
28
            $app['session']->getFlashBag()->add('success', 'The project was successfully created.');
29
        }
30
31
        return $app['twig']->render('projectList_form.html.twig', array(
32
            'title'       => 'New project',
33
            'legend'      => 'New project',
34
            'projectForm' => $projectForm->createView(),
35
        ));
36
    }
37
38 View Code Duplication
    public function editProjectAction($id, Request $request, Application $app)
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...
39
    {
40
        $credentials = $app['credential_repository']->findAllAsArray();
41
        $project     = $app['project_repository']->find($id);
42
        $projectForm = $app['form.factory']->create(new ProjectType(), $project, ['credentialChoices' => $credentials]);
43
        $projectForm->handleRequest($request);
44
45
        if ($projectForm->isSubmitted() && $projectForm->isValid()) {
46
            $app['project_repository']->save($project);
47
            $app['session']->getFlashBag()->add('success', 'The project was successfully updated.');
48
        }
49
50
        return $app['twig']->render('projectList_form.html.twig', array(
51
            'title'       => 'Edit project',
52
            'legend'      => 'Edit project',
53
            'projectForm' => $projectForm->createView(),
54
        ));
55
    }
56
57
    public function deleteProjectAction($id, Application $app)
58
    {
59
        $app['project_repository']->delete($id);
60
        $app['session']->getFlashBag()->add('success', 'The project was successfully removed.');
61
62
        return $app->redirect('/admin/project');
63
    }
64
}
65