Skip to content

Commit f03357b

Browse files
author
Marc Aschmann
committed
Move error definitions to separate method
1 parent 433a1b4 commit f03357b

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

lib/PhpFlo/Fbp/FbpDumper.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,10 @@ private static function createFbp(array $definition)
7272
if (!empty($definition[self::INITIALIZERS_LABEL])) {
7373
foreach ($definition[self::INITIALIZERS_LABEL] as $initializer) {
7474
if (empty($initializer[self::DATA_LABEL])) {
75-
throw new DumperException("Defintion has " .
76-
self::INITIALIZERS_LABEL . " but no " . self::DATA_LABEL . " node"
77-
);
75+
self::throwDumperException('no_definition', self::DATA_LABEL);
7876
}
7977
if (empty($initializer[self::TARGET_LABEL])) {
80-
throw new DumperException("Defintion has " .
81-
self::INITIALIZERS_LABEL . " but no " . self::TARGET_LABEL . " node"
82-
);
78+
self::throwDumperException('no_definition', self::TARGET_LABEL);
8379
}
8480
array_push(
8581
$fbp,
@@ -134,7 +130,7 @@ private static function examineProcess($type, array $processPart)
134130
if (self::hasElement($process, self::$processes, false)) {
135131
$meta = "(" . self::$processes[$process][self::COMPONENT_LABEL] . ")";
136132
} else {
137-
throw new DumperException("{$process} is not defined in " . self::PROCESSES_LABEL);
133+
self::throwDumperException('process', $process);
138134
}
139135

140136
if (self::SOURCE_LABEL == $type) {
@@ -156,7 +152,7 @@ private static function hasElement($needle, array $haystack, $triggerException =
156152
{
157153
if (empty($haystack[$needle])) {
158154
if ($triggerException) {
159-
throw new DumperException("Element has no {$needle}");
155+
self::throwDumperException('elmeent', $needle);
160156
} else {
161157
return false;
162158
}
@@ -180,4 +176,21 @@ private static function connectPorts($sourcePort, $targetPort)
180176
]
181177
);
182178
}
179+
180+
private static function throwDumperException($type, $value)
181+
{
182+
switch ($type) {
183+
case 'element':
184+
throw new DumperException("Element has no {$value}");
185+
break;
186+
case 'process':
187+
throw new DumperException("{$value} is not defined in " . self::PROCESSES_LABEL);
188+
break;
189+
case 'no_definition':
190+
throw new DumperException("Defintion has " .
191+
self::INITIALIZERS_LABEL . " but no {$value} node"
192+
);
193+
break;
194+
}
195+
}
183196
}

0 commit comments

Comments
 (0)