JsonResponseTrait   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
c 4
b 0
f 0
lcom 1
cbo 11
dl 0
loc 121
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A addHeaders() 0 4 1
A errorResponse() 0 5 1
A resourceCreatedResponse() 0 5 1
A resourceDeletedResponse() 0 5 1
A resourceNotFoundResponse() 0 5 1
A resourcePatchErrorResponse() 0 5 1
A resourcePostErrorResponse() 0 5 1
A resourceProcessingResponse() 0 5 1
A resourceUpdatedResponse() 0 5 1
A response() 0 5 1
A unsupportedActionResponse() 0 5 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 8/18/15
5
 * Time: 11:19 PM
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Laravel5\JsonSerializer;
12
13
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
14
15
trait JsonResponseTrait
16
{
17
    /**
18
     * @param  \Psr\Http\Message\ResponseInterface $response
19
     * @return \Psr\Http\Message\ResponseInterface
20
     */
21
    protected function addHeaders(\Psr\Http\Message\ResponseInterface $response)
22
    {
23
        return $response;
24
    }
25
26
    /**
27
     * @param string $json
28
     *
29
     * @return \Symfony\Component\HttpFoundation\Response
30
     */
31
    private function errorResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
32
    {
33
        return (new HttpFoundationFactory())
34
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ErrorResponse($json)));
35
    }
36
37
    /**
38
     * @param string $json
39
     *
40
     * @return \Symfony\Component\HttpFoundation\Response
41
     */
42
    private function resourceCreatedResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
43
    {
44
        return (new HttpFoundationFactory())
45
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourceCreatedResponse($json)));
46
    }
47
48
    /**
49
     * @param string $json
50
     *
51
     * @return \Symfony\Component\HttpFoundation\Response
52
     */
53
    private function resourceDeletedResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
54
    {
55
        return (new HttpFoundationFactory())
56
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourceDeletedResponse($json)));
0 ignored issues
show
Unused Code introduced by
The call to ResourceDeletedResponse::__construct() has too many arguments starting with $json.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
57
    }
58
59
    /**
60
     * @param string $json
61
     *
62
     * @return \Symfony\Component\HttpFoundation\Response
63
     */
64
    private function resourceNotFoundResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
65
    {
66
        return (new HttpFoundationFactory())
67
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourceNotFoundResponse($json)));
68
    }
69
70
    /**
71
     * @param string $json
72
     *
73
     * @return \Symfony\Component\HttpFoundation\Response
74
     */
75
    private function resourcePatchErrorResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
76
    {
77
        return (new HttpFoundationFactory())
78
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourcePatchErrorResponse($json)));
79
    }
80
81
    /**
82
     * @param string $json
83
     *
84
     * @return \Symfony\Component\HttpFoundation\Response
85
     */
86
    private function resourcePostErrorResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
87
    {
88
        return (new HttpFoundationFactory())
89
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourcePostErrorResponse($json)));
90
    }
91
92
    /**
93
     * @param string $json
94
     *
95
     * @return \Symfony\Component\HttpFoundation\Response
96
     */
97
    private function resourceProcessingResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
98
    {
99
        return (new HttpFoundationFactory())
100
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourceProcessingResponse($json)));
101
    }
102
103
    /**
104
     * @param string $json
105
     *
106
     * @return \Symfony\Component\HttpFoundation\Response
107
     */
108
    private function resourceUpdatedResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
109
    {
110
        return (new HttpFoundationFactory())
111
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\ResourceUpdatedResponse($json)));
112
    }
113
114
    /**
115
     * @param string $json
116
     *
117
     * @return \Symfony\Component\HttpFoundation\Response
118
     */
119
    private function response($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
120
    {
121
        return (new HttpFoundationFactory())
122
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\Response($json)));
123
    }
124
125
    /**
126
     * @param string $json
127
     *
128
     * @return \Symfony\Component\HttpFoundation\Response
129
     */
130
    private function unsupportedActionResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
131
    {
132
        return (new HttpFoundationFactory())
133
            ->createResponse($this->addHeaders(new \NilPortugues\Api\Json\Http\Message\UnsupportedActionResponse($json)));
134
    }
135
}
136