Completed
Push — master ( 9cc936...48646c )
by Tim
15s
created

CommandNames::isCommandName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Utils\CommandNames
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Utils;
22
23
/**
24
 * Utility class containing the available command names.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import
30
 * @link      http://www.techdivision.com
31
 */
32
class CommandNames extends \ArrayObject
33
{
34
35
    /**
36
     * The command name for the attribute import.
37
     *
38
     * @var string
39
     */
40
    const IMPORT_ATTRIBUTES = 'import:attributes';
41
42
    /**
43
     * The command name for the category import.
44
     *
45
     * @var string
46
     */
47
    const IMPORT_CATEGORIES = 'import:categories';
48
49
    /**
50
     * The command name for the product import.
51
     *
52
     * @var string
53
     */
54
    const IMPORT_PRODUCTS = 'import:products';
55
56
    /**
57
     * The command name for the command that creates an OK file.
58
     *
59
     * @var string
60
     */
61
    const IMPORT_CREATE_OK_FILE = 'import:create:ok-file';
62
63
    /**
64
     * The command name for the command that clears the PID file.
65
     *
66
     * @var string
67
     */
68
    const IMPORT_CLEAR_PID_FILE = 'import:clear:pid-file';
69
70
    /**
71
     * Construct a new command names instance.
72
     *
73
     * @param array $commandNames The array with the additional command names
74
     * @link http://www.php.net/manual/en/arrayobject.construct.php
75
     */
76
    public function __construct(array $commandNames = array())
77
    {
78
79
        // merge the command names with the passed ones
80
        $mergedCommandNames = array_merge(
81
            array(
82
                CommandNames::IMPORT_ATTRIBUTES,
83
                CommandNames::IMPORT_CATEGORIES,
84
                CommandNames::IMPORT_PRODUCTS,
85
                CommandNames::IMPORT_CREATE_OK_FILE,
86
                CommandNames::IMPORT_CLEAR_PID_FILE
87
            ),
88
            $commandNames
89
        );
90
91
        // initialize the parent class with the merged command names
92
        parent::__construct($mergedCommandNames);
93
    }
94
95
    /**
96
     * Query whether or not the passed command name is valid.
97
     *
98
     * @param string $commandName The command name to query for
99
     *
100
     * @return boolean TRUE if the command name is valid, else FALSE
101
     */
102
    public function isCommandName($commandName)
103
    {
104
        return isset($this[$commandName]);
105
    }
106
}
107