FileAppenderTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _appendFileToPaths() 0 12 2
_joinPaths() 0 1 ?
_isAtom() 0 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