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

FileTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 4
Bugs 2 Features 0
Metric Value
wmc 4
c 4
b 2
f 0
lcom 1
cbo 5
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFilename() 0 15 4
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