Put::__destruct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
ccs 0
cts 7
cp 0
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
crap 6
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\Ftp
10
 */
11
12
namespace Bee4\Transport\Message\Request\Ftp;
13
14
use Bee4\Transport\Message\WithBodyStreamTrait;
15
16
/**
17
 * Ftp Put Request object => Use to upload files to remote
18
 * @package Bee4\Transport\Message\Request\Ftp
19
 */
20 View Code Duplication
class Put extends FtpRequest
0 ignored issues
show
Duplication introduced by
This class 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...
21
{
22
    use WithBodyStreamTrait;
23
24
    protected function prepare()
25
    {
26
        parent::prepare();
27
28
        if (!$this->hasBodyStream()) {
29
            if (false === $stream = tmpfile()) {
30
                throw new \RuntimeException("Can't create temporary file !");
31
            }
32
            fwrite($stream, $this->getBody());
33
            rewind($stream);
34
            $this->setBody($stream);
0 ignored issues
show
Documentation introduced by
$stream is of type resource, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
        }
36
37
        $this->addOption(CURLOPT_URL, $this->getUrl());
38
        $this->addOption(CURLOPT_UPLOAD, true);
39
        $this->addOption(CURLOPT_INFILE, $this->getBody());
40
        $this->addOption(CURLOPT_INFILESIZE, $this->getBodyLength());
41
    }
42
43
    /**
44
     * Handle resource management
45
     */
46
    public function __destruct()
47
    {
48
        if ($this->hasOption(CURLOPT_INFILE)) {
49
            $options = $this->getOptions();
50
            fclose($options[CURLOPT_INFILE]);
51
        }
52
    }
53
}
54