TachesController::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
class TachesController extends \ControllerBase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    protected $model;
7
    protected $title;
8
    protected $controller;
9
10
    public function initialize()
11
    {
12
        $this->model = "Tache";
13
        $this->title = "Taches";
14
        $this->controller = "Taches";
15
    }
16
17
    public function updateAction($id = null)
18
    {
19
        parent::updateAction();
20
        $this->response->redirect("Projets/read/$id/2");
21
22
    }
23
24
    public function soloUpdateAction()
0 ignored issues
show
Coding Style introduced by
soloUpdateAction uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
    {
26
27
        $name = $this->request->getPost('name', 'string');
28
        //Cr�er la fonction variable 'set' en fonction du name en POST
29
        $func = 'set' . ucfirst($name);
30
        $projet = call_user_func($this->model . '::findFirst', $_POST['pk']);
31
        $projet->$func($_POST['value']);
32
        $projet->save();
33
34
        $this->useCaseUpdate($projet);
35
    }
36
37 View Code Duplication
    public function deleteAction($id = 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...
Coding Style introduced by
deleteAction uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
38
    {
39
        $object = call_user_func($this->model . '::findFirst', "$id");
40
        $object->delete();
41
42
        $this->useCaseUpdate($object);
43
        $this->response->redirect("$this->controller/index");
44
        $this->response->redirect($_SERVER['HTTP_REFERER'] . "/2");
45
    }
46
47
    public function useCaseUpdate($obj)
48
    {
49
        //Update l'avancement de la usecase lors de changements sur une usecase
50
        $avancementTotal = 0;
51
        $usecase = Usecase::findFirst("code='" . $obj->getCodeUseCase() . "'");
52
        $taches = Tache::find("codeUseCase LIKE '" . $obj->getCodeUseCase() . "'");
53
        foreach ($taches as $tache) {
54
            $avancementTotal += $tache->getAvancement();
55
        }
56
        $avancementTotal = $avancementTotal / count($taches);
57
        $usecase->setAvancement($avancementTotal);
58
        $usecase->save();
59
    }
60
}
61
62