FieldFactory   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 8
dl 0
loc 50
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getField() 0 34 9
1
<?php
2
3
/**
4
 * NOTICE OF LICENSE
5
 *
6
 * This source file is subject to the Open Software License (OSL 3.0)
7
 * that is available through the world-wide-web at this URL:
8
 * http://opensource.org/licenses/osl-3.0.php
9
 *
10
 * Some of this work is derived from mtdowling/cron-expression which is copyrighted as:
11
 * Copyright (c) 2011 Michael Dowling <[email protected]> and contributors
12
 * The licence of this work can be found here: https://github.com/mtdowling/cron-expression/blob/master/LICENSE
13
 *
14
 * Some limitations might apply.
15
 *
16
 * PHP version 5
17
 *
18
 * @category  Library
19
 * @package   Microcron
20
 * @author    Bernhard Wick <[email protected]>
21
 * @copyright 2015 TechDivision GmbH - <[email protected]>
22
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
23
 * @link      http://www.appserver.io/
24
 */
25
26
namespace AppserverIo\Microcron;
27
28
use Cron\FieldFactory as SimpleFieldFactory;
29
use Cron\MinutesField;
30
use Cron\HoursField;
31
use Cron\DayOfWeekField;
32
use Cron\DayOfMonthField;
33
use Cron\MonthField;
34
use Cron\YearField;
35
36
/**
37
 * AppserverIo\Microcron\FieldFactory
38
 *
39
 * Flyweight factory which allows for the creation of FieldInterface implementation objects
40
 *
41
 * @category  Library
42
 * @package   Microcron
43
 * @author    Bernhard Wick <[email protected]>
44
 * @copyright 2015 TechDivision GmbH - <[email protected]>
45
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
46
 * @link      http://www.appserver.io/
47
 */
48
class FieldFactory extends SimpleFieldFactory
49
{
50
    /**
51
     * @var array Cache of instantiated fields
52
     */
53
    private $fields = array();
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
54
55
    /**
56
     * Get an instance of a field object for a cron expression position
57
     *
58
     * @param int $position CRON expression position value to retrieve
59
     *
60
     * @return \Cron\FieldInterface
61
     * @throws \InvalidArgumentException if a position is not valid
62
     */
63 3
    public function getField($position)
64
    {
65 3
        if (!isset($this->fields[$position])) {
66 3
            switch ($position) {
67 3
                case 0:
68 2
                    $this->fields[$position] = new SecondsField();
69 2
                    break;
70 3
                case 1:
71 2
                    $this->fields[$position] = new MinutesField();
72 2
                    break;
73 3
                case 2:
74 2
                    $this->fields[$position] = new HoursField();
75 2
                    break;
76 3
                case 3:
77 2
                    $this->fields[$position] = new DayOfMonthField();
78 2
                    break;
79 3
                case 4:
80 2
                    $this->fields[$position] = new MonthField();
81 2
                    break;
82 3
                case 5:
83 2
                    $this->fields[$position] = new DayOfWeekField();
84 2
                    break;
85 2
                case 6:
86 1
                    $this->fields[$position] = new YearField();
87 1
                    break;
88
                default:
89 1
                    throw new \InvalidArgumentException(
90 1
                        $position . ' is not a valid position'
91
                    );
92
            }
93
        }
94
95 2
        return $this->fields[$position];
96
    }
97
}
98