Put::prepare()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.4286
cc 2
eloc 8
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the bee4/transport package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2015
8
 * @author  Stephane HULARD <[email protected]>
9
 * @package Bee4\Transport\Message\Request\Http
10
 */
11
12
namespace Bee4\Transport\Message\Request\Http;
13
14
use Bee4\Transport\Message\WithBodyStreamTrait;
15
16
/**
17
 * HTTP POST Request object
18
 * @package Bee4\Transport\Message\Request\Http
19
 */
20
class Put extends HttpRequest
21
{
22
    use WithBodyStreamTrait;
23
24 2
    protected function prepare()
25
    {
26 2
        if ($this->hasBodyStream()) {
27 1
            $this->addOption(CURLOPT_PUT, true);
28 1
            $this->addOption(CURLOPT_INFILE, $this->getBody());
29 1
            $this->addOption(CURLOPT_INFILESIZE, $this->getBodyLength());
30 1
        } else {
31 1
            $this->addOption(CURLOPT_CUSTOMREQUEST, 'PUT');
32 1
            $this->addOption(CURLOPT_POSTFIELDS, $this->getBody());
33
        }
34 2
    }
35
36
    /**
37
     * Handle resource management
38
     */
39 2
    public function __destruct()
40
    {
41 2
        if ($this->hasOption(CURLOPT_INFILE)) {
42 1
            $options = $this->getOptions();
43 1
            fclose($options[CURLOPT_INFILE]);
44 1
        }
45 2
    }
46
}
47