FileAppenderTrait::_joinPaths()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
namespace Nubs\Which\PathBuilder;
3
4
/**
5
 * Appends filenames to an array of paths.
6
 */
7
trait FileAppenderTrait
8
{
9
    /**
10
     * Append the filename to the array of paths.
11
     *
12
     * @param array $paths The paths to append to.
13
     * @param string $file The filename.
14
     * @return array The paths with the file name appended.
15
     */
16
    protected function _appendFileToPaths(array $paths, $file)
17
    {
18
        if (!$this->_isAtom($file)) {
19
            return [$file];
20
        }
21
22
        $appendFile = function($path) use($file) {
23
            return $this->_joinPaths($path, $file);
24
        };
25
26
        return array_map($appendFile, $paths);
27
    }
28
29
    /**
30
     * Joins two path segments together.
31
     *
32
     * @param string $start The starting segment.
33
     * @param string $end The ending segment.
34
     * @return string The joined segments.
35
     */
36
    abstract protected function _joinPaths($start, $end);
37
38
    /**
39
     * Checks to see if a path is just a single atom (no directory).
40
     *
41
     * @param string $path The path to check.
42
     * @return boolean True if it's an atom, false otherwise.
43
     */
44
    abstract protected function _isAtom($path);
45
}
46