CalendarService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getByDate() 0 6 1
A formatEvents() 0 9 2
1
<?php
2
3
namespace GolfLeague\Services;
4
5
use GolfLeague\Storage\Match\MatchRepository;
6
7
class CalendarService
8
{
9
    // Containing our matchRepository to make all our database calls to
10
    protected $matchRepo;
11
12
    /**
13
     * Loads our $matchRepo
14
     *
15
     * @param MatchRepository $matchRepo
16
     * @return CalendarService
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
17
     */
18
    public function __construct(MatchRepository $matchRepo)
19
    {
20
        $this->matchRepo = $matchRepo;
21
    }
22
23
    public function getByDate($startDate, $endDate)
24
    {
25
        $events = $this->matchRepo->getByDate($startDate, $endDate);
26
        //Decorate for javascript Calendar
27
        return $this->formatEvents($events);
28
    }
29
30
    public function formatEvents($events)
31
    {
32
        $events->toArray();
33
        foreach($events as $event){
34
            $event['title'] = 'Match ' . $event->course->name;
35
            $event['url'] = 'matches/' . $event->id . '/edit?group=1';
36
        }
37
        return $events;
38
    }
39
40
}