Completed
Push — master ( 0f3135...772d91 )
by Neomerx
01:58
created

JsonApiCallsTrait::deleteJsonApi()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 3
cts 3
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php namespace Limoncello\Testing;
2
3
/**
4
 * Copyright 2015-2018 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Http\Message\StreamInterface;
21
use Zend\Diactoros\Stream;
22
23
/** @noinspection PhpTooManyParametersInspection
24
 * @package Limoncello\Testing
25
 *
26
 * @@codingStandardsIgnoreLine
27
 * @method ResponseInterface call(string $method, string $uri, array $queryParams = [], array $parsedBody = [], array $headers = [], array $cookies = [], array $files = [], array $server = [], string $messageBody = 'php://input')
28
 */
29
trait JsonApiCallsTrait
30
{
31
    /**
32
     * @param string $uri
33
     * @param string $json
34
     * @param array  $headers
35
     * @param array  $cookies
36
     *
37
     * @return ResponseInterface
38
     */
39 1 View Code Duplication
    protected function postJsonApi(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
        string $uri,
41
        string $json,
42
        array $headers = [],
43
        array $cookies = []
44
    ): ResponseInterface {
45 1
        $headers['CONTENT_TYPE'] = 'application/vnd.api+json';
46
47 1
        return $this->call('POST', $uri, [], [], $headers, $cookies, [], [], $this->streamFromString($json));
48
    }
49
50
    /**
51
     * @param string $uri
52
     * @param string $json
53
     * @param array  $headers
54
     * @param array  $cookies
55
     *
56
     * @return ResponseInterface
57
     */
58 1 View Code Duplication
    protected function putJsonApi(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
        string $uri,
60
        string $json,
61
        array $headers = [],
62
        array $cookies = []
63
    ): ResponseInterface {
64 1
        $headers['CONTENT_TYPE'] = 'application/vnd.api+json';
65
66 1
        return $this->call('PUT', $uri, [], [], $headers, $cookies, [], [], $this->streamFromString($json));
67
    }
68
69
    /**
70
     * @param string $uri
71
     * @param string $json
72
     * @param array  $headers
73
     * @param array  $cookies
74
     *
75
     * @return ResponseInterface
76
     */
77 1 View Code Duplication
    protected function patchJsonApi(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
        string $uri,
79
        string $json,
80
        array $headers = [],
81
        array $cookies = []
82
    ): ResponseInterface {
83 1
        $headers['CONTENT_TYPE'] = 'application/vnd.api+json';
84
85 1
        return $this->call('PATCH', $uri, [], [], $headers, $cookies, [], [], $this->streamFromString($json));
86
    }
87
88
    /**
89
     * @param string $uri
90
     * @param string $json
91
     * @param array  $headers
92
     * @param array  $cookies
93
     *
94
     * @return ResponseInterface
95
     */
96 1 View Code Duplication
    protected function deleteJsonApi(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
        string $uri,
98
        string $json,
99
        array $headers = [],
100
        array $cookies = []
101
    ): ResponseInterface {
102 1
        $headers['CONTENT_TYPE'] = 'application/vnd.api+json';
103
104 1
        return $this->call('DELETE', $uri, [], [], $headers, $cookies, [], [], $this->streamFromString($json));
105
    }
106
107
    /**
108
     * @param string $content
109
     *
110
     * @return StreamInterface
111
     */
112 5
    protected function streamFromString(string $content): StreamInterface
113
    {
114 5
        $stream = new Stream('php://temp', 'wb+');
115 5
        $stream->write($content);
116
117 5
        return $stream;
118
    }
119
}
120