HolidayService::findSolarTermHolidays()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Slince/China package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace China\Holiday;
12
13
use China\Common\ResourceFile;
14
use Doctrine\Common\Collections\Collection;
15
16
class HolidayService implements HolidayServiceInterface
17
{
18
    /**
19
     * @var Collection
20
     */
21
    protected $holidays;
22
23
    public function __construct(ResourceFile $resourceFile)
24
    {
25
        $this->holidays = new HolidayLoader($resourceFile);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function findAll()
32
    {
33
        return $this->holidays;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function findTraditionalHolidays()
40
    {
41
        return $this->findHolidaysByType(HolidayInterface::TYPE_TRADITIONAL);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function findInternationalHolidays()
48
    {
49
        return $this->findHolidaysByType(HolidayInterface::TYPE_INTERNATIONAL);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function findSolarTermHolidays()
56
    {
57
        return $this->findHolidaysByType(HolidayInterface::TYPE_SOLAR_TERM);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function findHolidaysByType($type)
64
    {
65
        return $this->holidays->filter(function(HolidayInterface $holiday) use ($type){
66
            return $holiday->getType() === $type;
67
        });
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function find($name)
74
    {
75
        return $this->holidays->filter(function(HolidayInterface $holiday) use ($name){
76
            return $holiday->getName() === $name;
77
        })->first();
78
    }
79
}