JSendResponseTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addHeaders() 0 4 1
A errorResponse() 0 5 1
A failResponse() 0 5 1
A response() 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\JSendSerializer;
12
13
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
14
15
trait JSendResponseTrait
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 $message
28
     * @param int    $code
29
     * @param null   $data
30
     *
31
     * @return \Symfony\Component\HttpFoundation\Response
32
     */
33
    private function errorResponse($message, $code = 500, $data = null)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
34
    {
35
        return (new HttpFoundationFactory())
36
            ->createResponse($this->addHeaders(new \NilPortugues\Api\JSend\Http\Message\ErrorResponse($message, $code, $data)));
37
    }
38
39
    /**
40
     * @param string $json
41
     *
42
     * @return \Symfony\Component\HttpFoundation\Response
43
     */
44
    private function failResponse($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
45
    {
46
        return (new HttpFoundationFactory())
47
            ->createResponse($this->addHeaders(new \NilPortugues\Api\JSend\Http\Message\FailResponse($json)));
48
    }
49
50
    /**
51
     * @param string $json
52
     *
53
     * @return \Symfony\Component\HttpFoundation\Response
54
     */
55
    private function response($json)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
56
    {
57
        return (new HttpFoundationFactory())
58
            ->createResponse($this->addHeaders(new \NilPortugues\Api\JSend\Http\Message\Response($json)));
59
    }
60
}
61