Completed
Push — master ( 7dba56...6875ae )
by Oscar
10:21
created

FileTrait::getFilename()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 8
nc 8
nop 1
1
<?php
2
3
namespace Psr7Middlewares\Utils;
4
5
use Psr\Http\Message\RequestInterface;
6
7
/**
8
 * Common methods used by middlewares that read/write files.
9
 */
10
trait FileTrait
11
{
12
    use BasePathTrait;
13
    use StorageTrait;
14
15
    /**
16
     * Returns the filename of the response file.
17
     *
18
     * @param RequestInterface $request
19
     *
20
     * @return string
21
     */
22
    private function getFilename(RequestInterface $request)
23
    {
24
        $path = $this->getBasePath($request->getUri()->getPath());
25
26
        $parts = pathinfo($path);
27
        $path = isset($parts['dirname']) ? $parts['dirname'] : '';
28
        $filename = isset($parts['basename']) ? $parts['basename'] : '';
29
30
        //if it's a directory, append "/index.html"
31
        if (empty($parts['extension'])) {
32
            $filename .= '/index.html';
33
        }
34
35
        return Path::join($this->storage, $path, $filename);
36
    }
37
}
38