Code Duplication    Length = 56-56 lines in 2 locations

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

install/cli-install.php 1 location

@@ 1590-1645 (lines=56) @@
1587
 * @param bool|mixed $json
1588
 * @return string
1589
 */
1590
function parseProperties($propertyString, $json=false) {
1591
    $propertyString = str_replace('{}', '', $propertyString );
1592
    $propertyString = str_replace('} {', ',', $propertyString );
1593
1594
    if(empty($propertyString)) return array();
1595
    if($propertyString=='{}' || $propertyString=='[]') return array();
1596
1597
    $jsonFormat = isJson($propertyString, true);
1598
    $property = array();
1599
    // old format
1600
    if ( $jsonFormat === false) {
1601
        $props= explode('&', $propertyString);
1602
        foreach ($props as $prop) {
1603
            $prop = trim($prop);
1604
            if($prop === '') {
1605
                continue;
1606
            }
1607
1608
            $arr = explode(';', $prop);
1609
            if( ! is_array($arr)) {
1610
                $arr = array();
1611
            }
1612
            $key = explode('=', isset($arr[0]) ? $arr[0] : '');
1613
            if( ! is_array($key) || empty($key[0])) {
1614
                continue;
1615
            }
1616
1617
            $property[$key[0]]['0']['label'] = isset($key[1]) ? trim($key[1]) : '';
1618
            $property[$key[0]]['0']['type'] = isset($arr[1]) ? trim($arr[1]) : '';
1619
            switch ($property[$key[0]]['0']['type']) {
1620
                case 'list':
1621
                case 'list-multi':
1622
                case 'checkbox':
1623
                case 'radio':
1624
                case 'menu':
1625
                    $property[$key[0]]['0']['value'] = isset($arr[3]) ? trim($arr[3]) : '';
1626
                    $property[$key[0]]['0']['options'] = isset($arr[2]) ? trim($arr[2]) : '';
1627
                    $property[$key[0]]['0']['default'] = isset($arr[3]) ? trim($arr[3]) : '';
1628
                    break;
1629
                default:
1630
                    $property[$key[0]]['0']['value'] = isset($arr[2]) ? trim($arr[2]) : '';
1631
                    $property[$key[0]]['0']['default'] = isset($arr[2]) ? trim($arr[2]) : '';
1632
            }
1633
            $property[$key[0]]['0']['desc'] = '';
1634
1635
        }
1636
    // new json-format
1637
    } else if(!empty($jsonFormat)){
1638
        $property = $jsonFormat;
1639
    }
1640
    if ($json) {
1641
        $property = json_encode($property, JSON_UNESCAPED_UNICODE);
1642
    }
1643
    $property = ($property !== '[]') ? $property : '';
1644
    return $property;
1645
}
1646
1647
/**
1648
 * @param string $string