Code Duplication    Length = 23-29 lines in 2 locations

src/V1/OmsApi.php 1 location

@@ 71-93 (lines=23) @@
68
    /**
69
     * @throws OmsClientExceptionInterface
70
     */
71
    private function request(string $token, string $method, string $uri, array $query = [], $body = null): string
72
    {
73
        $options = [
74
            RequestOptions::BODY => $body,
75
            RequestOptions::HEADERS => [
76
                'Content-Type' => 'application/json',
77
                'clientToken' => $token,
78
            ],
79
            RequestOptions::QUERY => $query,
80
            RequestOptions::HTTP_ERRORS => true,
81
        ];
82
83
        $uri = ltrim($uri, '/');
84
85
        try {
86
            $result = $this->client->request($method, $uri, $options);
87
        } catch (\Throwable $exception) {
88
            /* @noinspection PhpUnhandledExceptionInspection */
89
            throw $this->handleRequestException($exception);
90
        }
91
92
        return (string) $result->getBody();
93
    }
94
95
    private function handleRequestException(\Throwable $exception): OmsClientExceptionInterface
96
    {

src/V2/OmsApi.php 1 location

@@ 123-151 (lines=29) @@
120
    /**
121
     * @throws OmsRequestErrorException
122
     */
123
    private function request(
124
        string $token,
125
        string $method,
126
        string $uri,
127
        array $query = [],
128
        $body = null,
129
        $headers = []
130
    ): string {
131
        $options = [
132
            RequestOptions::BODY => $body,
133
            RequestOptions::HEADERS => array_merge($headers, [
134
                'Content-Type' => 'application/json',
135
                'clientToken' => $token,
136
            ]),
137
            RequestOptions::QUERY => $query,
138
            RequestOptions::HTTP_ERRORS => true,
139
        ];
140
141
        $uri = ltrim($uri, '/');
142
143
        try {
144
            $result = $this->client->request($method, $uri, $options);
145
        } catch (\Throwable $exception) {
146
            /* @noinspection PhpUnhandledExceptionInspection */
147
            throw $this->handleRequestException($exception);
148
        }
149
150
        return (string)$result->getBody();
151
    }
152
153
    private function handleRequestException(\Throwable $exception): OmsClientExceptionInterface
154
    {