Code Duplication    Length = 21-21 lines in 2 locations

src/ClassNameMapper.php 2 locations

@@ 29-49 (lines=21) @@
26
     * @param string $namespace The namespace to register
27
     * @param string|array $path The path on the filesystem (or an array of paths)
28
     */
29
    public function registerPsr0Namespace($namespace, $path) {
30
        // A namespace always ends with a \
31
        $namespace = trim($namespace, '\\').'\\';
32
        if ($namespace === '\\') {
33
            $namespace = '';
34
        }
35
36
        if (!is_array($path)) {
37
            $path = [$path];
38
        }
39
        // Paths always end with a /
40
        $paths = array_map(function($path) {
41
            return $path === '' ? '' : rtrim($path, '\\/').'/';
42
        }, $path);
43
44
        if (!isset($this->psr0Namespaces[$namespace])) {
45
            $this->psr0Namespaces[$namespace] = $paths;
46
        } else {
47
            $this->psr0Namespaces[$namespace] = array_merge($this->psr0Namespaces[$namespace], $paths);
48
        }
49
    }
50
51
    /**
52
     * Registers a PSR-4 namespace.
@@ 57-77 (lines=21) @@
54
     * @param string $namespace The namespace to register
55
     * @param string|array $path The path on the filesystem (or an array of paths)
56
     */
57
    public function registerPsr4Namespace($namespace, $path) {
58
        // A namespace always ends with a \
59
        $namespace = trim($namespace, '\\').'\\';
60
        if ($namespace === '\\') {
61
            $namespace = '';
62
        }
63
64
        if (!is_array($path)) {
65
            $path = [$path];
66
        }
67
        // Paths always end with a /
68
        $paths = array_map(function($path) {
69
            return $path === '' ? '' : rtrim($path, '\\/').'/';
70
        }, $path);
71
72
        if (!isset($this->psr4Namespaces[$namespace])) {
73
            $this->psr4Namespaces[$namespace] = $paths;
74
        } else {
75
            $this->psr4Namespaces[$namespace] = array_merge($this->psr4Namespaces[$namespace], $paths);
76
        }
77
    }
78
79
    /**
80
     * @param string $composerJsonPath