Code Duplication    Length = 33-33 lines in 2 locations

class/DoSync.php 1 location

@@ 96-128 (lines=33) @@
93
     * @param bool|int    $empty
94
     * @return bool
95
     */
96
    public function smallworld_remDir($userid, $directory, $empty = false)
97
    {
98
        if ('' != $userid) {
99
            if ('/' === mb_substr($directory, -1)) {
100
                $directory = mb_substr($directory, 0, -1);
101
            }
102
103
            if (!file_exists($directory) || !is_dir($directory)) {
104
                return false;
105
            } elseif (!is_readable($directory)) {
106
                return false;
107
            }
108
            $directoryHandle = opendir($directory);
109
            while (false !== ($contents = readdir($directoryHandle))) {
110
                if ('.' !== $contents && '..' !== $contents) {
111
                    $path = $directory . '/' . $contents;
112
                    if (is_dir($path)) {
113
                        $this->smallworld_remDir($userid, $path);
114
                    } else {
115
                        unlink($path);
116
                    }
117
                }
118
            }
119
            closedir($directoryHandle);
120
            if (false === $empty) {
121
                if (!rmdir($directory)) {
122
                    return false;
123
                }
124
            }
125
126
            return true;
127
        }
128
    }
129
130
    /**
131
     * SmallworldDeleteDirectory function

class/SwDatabase.php 1 location

@@ 585-617 (lines=33) @@
582
     * @param bool|int    $empty
583
     * @return bool
584
     */
585
    public function smallworld_remDir($userid, $directory, $empty = false)
586
    {
587
        if ('' != $userid) {
588
            if ('/' === mb_substr($directory, -1)) {
589
                $directory = mb_substr($directory, 0, -1);
590
            }
591
592
            if (!file_exists($directory) || !is_dir($directory)) {
593
                return false;
594
            } elseif (!is_readable($directory)) {
595
                return false;
596
            }
597
            $directoryHandle = opendir($directory);
598
            while (false !== ($contents = readdir($directoryHandle))) {
599
                if ('.' !== $contents && '..' !== $contents) {
600
                    $path = $directory . '/' . $contents;
601
                    if (is_dir($path)) {
602
                        $this->smallworld_remDir($userid, $path);
603
                    } else {
604
                        unlink($path);
605
                    }
606
                }
607
            }
608
            closedir($directoryHandle);
609
            if (false === $empty) {
610
                if (!rmdir($directory)) {
611
                    return false;
612
                }
613
            }
614
615
            return true;
616
        }
617
    }
618
619
    /**
620
     * Update private settings