Code Duplication    Length = 71-71 lines in 2 locations

install/cli-install.php 1 location

@@ 1709-1779 (lines=71) @@
1706
    }
1707
}
1708
1709
if (!function_exists('parseProperties')) {
1710
    /**
1711
     * @param string $propertyString
1712
     * @param bool|mixed $json
1713
     * @return string
1714
     */
1715
    function parseProperties($propertyString, $json = false)
1716
    {
1717
        $propertyString = str_replace('{}', '', $propertyString);
1718
        $propertyString = str_replace('} {', ',', $propertyString);
1719
1720
        if (empty($propertyString)) {
1721
            return array();
1722
        }
1723
        if ($propertyString == '{}' || $propertyString == '[]') {
1724
            return array();
1725
        }
1726
1727
        $jsonFormat = isJson($propertyString, true);
1728
        $property = array();
1729
        // old format
1730
        if ($jsonFormat === false) {
1731
            $props = explode('&', $propertyString);
1732
            foreach ($props as $prop) {
1733
                $prop = trim($prop);
1734
                if ($prop === '') {
1735
                    continue;
1736
                }
1737
1738
                $arr = explode(';', $prop);
1739
                if (!is_array($arr)) {
1740
                    $arr = array();
1741
                }
1742
                $key = explode('=', isset($arr[0]) ? $arr[0] : '');
1743
                if (!is_array($key) || empty($key[0])) {
1744
                    continue;
1745
                }
1746
1747
                $property[$key[0]]['0']['label'] = isset($key[1]) ? trim($key[1]) : '';
1748
                $property[$key[0]]['0']['type'] = isset($arr[1]) ? trim($arr[1]) : '';
1749
                switch ($property[$key[0]]['0']['type']) {
1750
                    case 'list':
1751
                    case 'list-multi':
1752
                    case 'checkbox':
1753
                    case 'radio':
1754
                    case 'menu':
1755
                        $property[$key[0]]['0']['value'] = isset($arr[3]) ? trim($arr[3]) : '';
1756
                        $property[$key[0]]['0']['options'] = isset($arr[2]) ? trim($arr[2]) : '';
1757
                        $property[$key[0]]['0']['default'] = isset($arr[3]) ? trim($arr[3]) : '';
1758
                        break;
1759
                    default:
1760
                        $property[$key[0]]['0']['value'] = isset($arr[2]) ? trim($arr[2]) : '';
1761
                        $property[$key[0]]['0']['default'] = isset($arr[2]) ? trim($arr[2]) : '';
1762
                }
1763
                $property[$key[0]]['0']['desc'] = '';
1764
1765
            }
1766
            // new json-format
1767
        } else {
1768
            if (!empty($jsonFormat)) {
1769
                $property = $jsonFormat;
1770
            }
1771
        }
1772
        if ($json) {
1773
            $property = json_encode($property, JSON_UNESCAPED_UNICODE);
1774
        }
1775
        $property = ($property !== '[]') ? $property : '';
1776
1777
        return $property;
1778
    }
1779
}
1780
1781
if (!function_exists('isJson')) {
1782
    /**

install/src/functions.php 1 location

@@ 596-666 (lines=71) @@
593
    }
594
}
595
596
if (!function_exists('parseProperties')) {
597
    /**
598
     * @param string $propertyString
599
     * @param bool|mixed $json
600
     * @return string
601
     */
602
    function parseProperties($propertyString, $json = false)
603
    {
604
        $propertyString = str_replace('{}', '', $propertyString);
605
        $propertyString = str_replace('} {', ',', $propertyString);
606
607
        if (empty($propertyString)) {
608
            return array();
609
        }
610
        if ($propertyString == '{}' || $propertyString == '[]') {
611
            return array();
612
        }
613
614
        $jsonFormat = isJson($propertyString, true);
615
        $property = array();
616
        // old format
617
        if ($jsonFormat === false) {
618
            $props = explode('&', $propertyString);
619
            foreach ($props as $prop) {
620
                $prop = trim($prop);
621
                if ($prop === '') {
622
                    continue;
623
                }
624
625
                $arr = explode(';', $prop);
626
                if (!is_array($arr)) {
627
                    $arr = array();
628
                }
629
                $key = explode('=', isset($arr[0]) ? $arr[0] : '');
630
                if (!is_array($key) || empty($key[0])) {
631
                    continue;
632
                }
633
634
                $property[$key[0]]['0']['label'] = isset($key[1]) ? trim($key[1]) : '';
635
                $property[$key[0]]['0']['type'] = isset($arr[1]) ? trim($arr[1]) : '';
636
                switch ($property[$key[0]]['0']['type']) {
637
                    case 'list':
638
                    case 'list-multi':
639
                    case 'checkbox':
640
                    case 'radio':
641
                    case 'menu':
642
                        $property[$key[0]]['0']['value'] = isset($arr[3]) ? trim($arr[3]) : '';
643
                        $property[$key[0]]['0']['options'] = isset($arr[2]) ? trim($arr[2]) : '';
644
                        $property[$key[0]]['0']['default'] = isset($arr[3]) ? trim($arr[3]) : '';
645
                        break;
646
                    default:
647
                        $property[$key[0]]['0']['value'] = isset($arr[2]) ? trim($arr[2]) : '';
648
                        $property[$key[0]]['0']['default'] = isset($arr[2]) ? trim($arr[2]) : '';
649
                }
650
                $property[$key[0]]['0']['desc'] = '';
651
652
            }
653
            // new json-format
654
        } else {
655
            if (!empty($jsonFormat)) {
656
                $property = $jsonFormat;
657
            }
658
        }
659
        if ($json) {
660
            $property = json_encode($property, JSON_UNESCAPED_UNICODE);
661
        }
662
        $property = ($property !== '[]') ? $property : '';
663
664
        return $property;
665
    }
666
}
667
668
if (!function_exists('isJson')) {
669
    /**