Code Duplication    Length = 12-13 lines in 3 locations

Form.php 3 locations

@@ 1371-1383 (lines=13) @@
1368
			// Use the first correct match in the given group.
1369
			$groupNames = explode('.', $group);
1370
1371
			foreach ($fields as &$field)
1372
			{
1373
				// Get the group names as strings for ancestor fields elements.
1374
				$attrs = $field->xpath('ancestor::fields[@name]/@name');
1375
				$names = array_map('strval', $attrs ? $attrs : array());
1376
1377
				// If the field is in the exact group use it and break out of the loop.
1378
				if ($names == (array) $groupNames)
1379
				{
1380
					$element = &$field;
1381
					break;
1382
				}
1383
			}
1384
		}
1385
		else
1386
		{
@@ 1493-1504 (lines=12) @@
1490
					{
1491
						$groupNames = explode('.', $group);
1492
1493
						foreach ($tmp as $field)
1494
						{
1495
							// Get the names of the groups that the field is in.
1496
							$attrs = $field->xpath('ancestor::fields[@name]/@name');
1497
							$names = array_map('strval', $attrs ? $attrs : array());
1498
1499
							// If the field is in the specific group then add it to the return list.
1500
							if ($names == (array) $groupNames)
1501
							{
1502
								$fields = array_merge($fields, array($field));
1503
							}
1504
						}
1505
					}
1506
				}
1507
			}
@@ 1576-1588 (lines=13) @@
1573
					$children = $element->xpath('descendant::fields[@name="' . (string) $group[$i] . '"]');
1574
1575
					// For the found fields elements validate that they are in the correct groups.
1576
					foreach ($children as $fields)
1577
					{
1578
						// Get the group names as strings for ancestor fields elements.
1579
						$attrs = $fields->xpath('ancestor-or-self::fields[@name]/@name');
1580
						$names = array_map('strval', $attrs ? $attrs : array());
1581
1582
						// If the group names for the fields element match the valid names at this
1583
						// level add the fields element.
1584
						if ($validNames == $names)
1585
						{
1586
							$tmp[] = $fields;
1587
						}
1588
					}
1589
				}
1590
			}
1591