PlanningService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 8
c 2
b 1
f 0
lcom 1
cbo 1
dl 0
loc 79
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A find() 0 4 1
A findByPeriod() 0 4 1
A save() 0 12 3
A delete() 0 12 2
1
<?php
2
3
namespace SDIS62\Core\Ops\Service;
4
5
use Datetime;
6
use SDIS62\Core\Ops\Entity\Planning;
7
use SDIS62\Core\Ops\Repository\PlanningRepositoryInterface;
8
9
class PlanningService
10
{
11
    /**
12
     * Initialisation du service avec les repository utilisés.
13
     *
14
     * @param SDIS62\Core\Ops\Repository\PlanningRepositoryInterface $planning_repository
15
     */
16
    public function __construct(PlanningRepositoryInterface $planning_repository)
17
    {
18
        $this->planning_repository = $planning_repository;
0 ignored issues
show
Bug introduced by
The property planning_repository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * Retourne un planning à l'id spécifié.
23
     *
24
     * @param mixed $id_planning
25
     *
26
     * @return SDIS62\Core\Ops\Entity\Planning
27
     */
28
    public function find($id_planning)
29
    {
30
        return $this->planning_repository->find($id_planning);
31
    }
32
33
    /**
34
     * Retourne le planning entre les dates données.
35
     *
36
     * @param mixed    $id_planning
37
     * @param Datetime $start
38
     * @param Datetime $end
39
     *
40
     * @return SDIS62\Core\User\Entity\Planning
41
     */
42
    public function findByPeriod($id_planning, Datetime $start, Datetime $end)
43
    {
44
        return $this->planning_repository->findByPeriod($id_planning, $start, $end);
45
    }
46
47
    /**
48
     * Sauvegarde du planning.
49
     *
50
     * @param array $data
51
     * @param array $id_planning
52
     *
53
     * @return SDIS62\Core\Ops\Entity\Planning
54
     */
55
    public function save($data, $id_planning = null)
56
    {
57
        $planning = empty($id_planning) ? new Planning($data['name']) : $this->planning_repository->find($id_planning);
58
59
        if (!empty($data['name'])) {
60
            $planning->setName($data['name']);
61
        }
62
63
        $this->planning_repository->save($planning);
64
65
        return $planning;
66
    }
67
68
    /**
69
     * Suppression d'un planning.
70
     *
71
     * @param mixed $id_planning
72
     *
73
     * @return SDIS62\Core\Ops\Entity\Planning
74
     */
75
    public function delete($id_planning)
76
    {
77
        $planning = $this->find($id_planning);
78
79
        if (empty($planning)) {
80
            return;
81
        }
82
83
        $this->planning_repository->delete($planning);
84
85
        return $planning;
86
    }
87
}
88