Completed
Pull Request — master (#532)
by
unknown
01:33
created

ResponsePdfFileStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 4 1
A getPdfFileResponses() 0 17 3
1
<?php
2
3
namespace Mpociot\ApiDoc\Tools\ResponseStrategies;
4
5
use Illuminate\Routing\Route;
6
use Illuminate\Http\JsonResponse;
7
use Mpociot\Reflection\DocBlock\Tag;
8
9
/**
10
 * Get a response from from a file in the docblock ( @responseFile ).
11
 */
12
class ResponsePdfFileStrategy
13
{
14
    /**
15
     * @param Route $route
16
     * @param array $tags
17
     * @param array $routeProps
18
     *
19
     * @return array|null
20
     */
21
    public function __invoke(Route $route, array $tags, array $routeProps)
22
    {
23
        return $this->getPdfFileResponses($tags);
24
    }
25
26
    /**
27
     * Get the response from the file if available.
28
     *
29
     * @param array $tags
30
     *
31
     * @return array|null
32
     */
33
    protected function getPdfFileResponses(array $tags)
34
    {
35
        // avoid "holes" in the keys of the filtered array, by using array_values on the filtered array
36
        $responsePdfFileTags = array_values(
37
            array_filter($tags, function ($tag) {
38
                return $tag instanceof Tag && strtolower($tag->getName()) === 'responsepdffile';
39
            })
40
        );
41
42
        if (empty($responsePdfFileTags)) {
43
            return;
44
        }
45
46
        return array_map(function (Tag $responsePdfFileTag) {
0 ignored issues
show
Unused Code introduced by
The parameter $responsePdfFileTag is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
            return new JsonResponse(null, 200, ['Content-Type' => 'application/pdf']);
48
        }, $responsePdfFileTags);
49
    }
50
}
51