Code Duplication    Length = 56-56 lines in 2 locations

install/cli-install.php 1 location

@@ 1538-1593 (lines=56) @@
1535
 * @param bool|mixed $json
1536
 * @return string
1537
 */
1538
function parseProperties($propertyString, $json=false) {
1539
    $propertyString = str_replace('{}', '', $propertyString );
1540
    $propertyString = str_replace('} {', ',', $propertyString );
1541
1542
    if(empty($propertyString)) return array();
1543
    if($propertyString=='{}' || $propertyString=='[]') return array();
1544
1545
    $jsonFormat = isJson($propertyString, true);
1546
    $property = array();
1547
    // old format
1548
    if ( $jsonFormat === false) {
1549
        $props= explode('&', $propertyString);
1550
        foreach ($props as $prop) {
1551
            $prop = trim($prop);
1552
            if($prop === '') {
1553
                continue;
1554
            }
1555
1556
            $arr = explode(';', $prop);
1557
            if( ! is_array($arr)) {
1558
                $arr = array();
1559
            }
1560
            $key = explode('=', isset($arr[0]) ? $arr[0] : '');
1561
            if( ! is_array($key) || empty($key[0])) {
1562
                continue;
1563
            }
1564
1565
            $property[$key[0]]['0']['label'] = isset($key[1]) ? trim($key[1]) : '';
1566
            $property[$key[0]]['0']['type'] = isset($arr[1]) ? trim($arr[1]) : '';
1567
            switch ($property[$key[0]]['0']['type']) {
1568
                case 'list':
1569
                case 'list-multi':
1570
                case 'checkbox':
1571
                case 'radio':
1572
                case 'menu':
1573
                    $property[$key[0]]['0']['value'] = isset($arr[3]) ? trim($arr[3]) : '';
1574
                    $property[$key[0]]['0']['options'] = isset($arr[2]) ? trim($arr[2]) : '';
1575
                    $property[$key[0]]['0']['default'] = isset($arr[3]) ? trim($arr[3]) : '';
1576
                    break;
1577
                default:
1578
                    $property[$key[0]]['0']['value'] = isset($arr[2]) ? trim($arr[2]) : '';
1579
                    $property[$key[0]]['0']['default'] = isset($arr[2]) ? trim($arr[2]) : '';
1580
            }
1581
            $property[$key[0]]['0']['desc'] = '';
1582
1583
        }
1584
    // new json-format
1585
    } else if(!empty($jsonFormat)){
1586
        $property = $jsonFormat;
1587
    }
1588
    if ($json) {
1589
        $property = json_encode($property, JSON_UNESCAPED_UNICODE);
1590
    }
1591
    $property = ($property !== '[]') ? $property : '';
1592
    return $property;
1593
}
1594
1595
/**
1596
 * @param string $string

install/instprocessor.php 1 location

@@ 814-869 (lines=56) @@
811
 * @param bool|mixed $json
812
 * @return string
813
 */
814
function parseProperties($propertyString, $json=false) {
815
    $propertyString = str_replace('{}', '', $propertyString );
816
    $propertyString = str_replace('} {', ',', $propertyString );
817
818
    if(empty($propertyString)) return array();
819
    if($propertyString=='{}' || $propertyString=='[]') return array();
820
821
    $jsonFormat = isJson($propertyString, true);
822
    $property = array();
823
    // old format
824
    if ( $jsonFormat === false) {
825
        $props= explode('&', $propertyString);
826
        foreach ($props as $prop) {
827
            $prop = trim($prop);
828
            if($prop === '') {
829
                continue;
830
            }
831
832
            $arr = explode(';', $prop);
833
            if( ! is_array($arr)) {
834
                $arr = array();
835
            }
836
            $key = explode('=', isset($arr[0]) ? $arr[0] : '');
837
            if( ! is_array($key) || empty($key[0])) {
838
                continue;
839
            }
840
841
            $property[$key[0]]['0']['label'] = isset($key[1]) ? trim($key[1]) : '';
842
            $property[$key[0]]['0']['type'] = isset($arr[1]) ? trim($arr[1]) : '';
843
            switch ($property[$key[0]]['0']['type']) {
844
                case 'list':
845
                case 'list-multi':
846
                case 'checkbox':
847
                case 'radio':
848
                case 'menu':
849
                    $property[$key[0]]['0']['value'] = isset($arr[3]) ? trim($arr[3]) : '';
850
                    $property[$key[0]]['0']['options'] = isset($arr[2]) ? trim($arr[2]) : '';
851
                    $property[$key[0]]['0']['default'] = isset($arr[3]) ? trim($arr[3]) : '';
852
                    break;
853
                default:
854
                    $property[$key[0]]['0']['value'] = isset($arr[2]) ? trim($arr[2]) : '';
855
                    $property[$key[0]]['0']['default'] = isset($arr[2]) ? trim($arr[2]) : '';
856
            }
857
            $property[$key[0]]['0']['desc'] = '';
858
859
        }
860
    // new json-format
861
    } else if(!empty($jsonFormat)){
862
        $property = $jsonFormat;
863
    }
864
    if ($json) {
865
        $property = json_encode($property, JSON_UNESCAPED_UNICODE);
866
    }
867
    $property = ($property !== '[]') ? $property : '';
868
    return $property;
869
}
870
871
/**
872
 * @param string $string