Aggregate   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A add() 0 6 1
A getEvents() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of CalendR, a Fréquence web project.
5
 *
6
 * (c) 2012 Fréquence web
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 CalendR\Event\Provider;
13
14
/**
15
 * This class provide multiple event providers support.
16
 *
17
 * @author Yohan Giarelli <[email protected]>
18
 */
19
class Aggregate implements ProviderInterface
20
{
21
    /**
22
     * @var ProviderInterface[]
23
     */
24
    private $providers;
25
26
    /**
27
     * @param ProviderInterface[] $providers
28
     *
29
     * @throws \InvalidArgumentException
30
     */
31
    public function __construct(array $providers)
32
    {
33
        foreach ($providers as $provider) {
34
            if (!$provider instanceof ProviderInterface) {
35
                throw new \InvalidArgumentException('Providers must implement CalendR\\Event\\ProviderInterface');
36
            }
37
            $this->providers[] = $provider;
38
        }
39
    }
40
41
    /**
42
     * Adds a provider.
43
     *
44
     * @param ProviderInterface $provider
45
     *
46
     * @return Aggregate
47
     */
48
    public function add(ProviderInterface $provider)
49
    {
50
        $this->providers[] = $provider;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Return events that matches to $begin && $end
57
     * $end date should be exclude.
58
     *
59
     * @param \DateTime $begin
60
     * @param \DateTime $end
61
     * @param array     $options
62
     *
63
     * @return \CalendR\Event\EventInterface
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
64
     */
65
    public function getEvents(\DateTime $begin, \DateTime $end, array $options = array())
66
    {
67
        $events = array();
68
69
        foreach ($this->providers as $provider) {
70
            $events = array_merge($events, $provider->getEvents($begin, $end, $options));
71
        }
72
73
        return $events;
74
    }
75
}
76