Put   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 34
loc 34
ccs 0
cts 23
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepare() 18 18 3
A __destruct() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Ssh
10
 */
11
12
namespace Bee4\Transport\Message\Request\Ssh;
13
14
use Bee4\Transport\Message\WithBodyStreamTrait;
15
16
/**
17
 * SSH Put Request object => Use to upload files to remote
18
 * @package Bee4\Transport\Message\Request\Ssh
19
 */
20 View Code Duplication
class Put extends SshRequest
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