Completed
Pull Request — master (#1)
by Sergey
04:51
created

ConnectionOpen   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 75
loc 75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A getVirtualHost() 4 4 1
A getReserved1() 4 4 1
A isReserved2() 4 4 1
A encode() 9 9 1

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 automatically generated.
4
 */
5
6
namespace ButterAMQP\AMQP091\Framing\Method;
7
8
use ButterAMQP\AMQP091\Framing\Frame;
9
use ButterAMQP\Value;
10
11
/**
12
 * Open connection to virtual host.
13
 *
14
 * @codeCoverageIgnore
15
 */
16 View Code Duplication
class ConnectionOpen extends Frame
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...
17
{
18
    /**
19
     * @var string
20
     */
21
    private $virtualHost;
22
23
    /**
24
     * @var string
25
     */
26
    private $reserved1;
27
28
    /**
29
     * @var bool
30
     */
31
    private $reserved2;
32
33
    /**
34
     * @param int    $channel
35
     * @param string $virtualHost
36
     * @param string $reserved1
37
     * @param bool   $reserved2
38
     */
39
    public function __construct($channel, $virtualHost, $reserved1, $reserved2)
40
    {
41
        $this->virtualHost = $virtualHost;
42
        $this->reserved1 = $reserved1;
43
        $this->reserved2 = $reserved2;
44
45
        parent::__construct($channel);
46
    }
47
48
    /**
49
     * Virtual host name.
50
     *
51
     * @return string
52
     */
53
    public function getVirtualHost()
54
    {
55
        return $this->virtualHost;
56
    }
57
58
    /**
59
     * Reserved1.
60
     *
61
     * @return string
62
     */
63
    public function getReserved1()
64
    {
65
        return $this->reserved1;
66
    }
67
68
    /**
69
     * Reserved2.
70
     *
71
     * @return bool
72
     */
73
    public function isReserved2()
74
    {
75
        return $this->reserved2;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function encode()
82
    {
83
        $data = "\x00\x0A\x00\x28".
84
            Value\ShortStringValue::encode($this->virtualHost).
85
            Value\ShortStringValue::encode($this->reserved1).
86
            Value\BooleanValue::encode($this->reserved2);
87
88
        return "\x01".pack('nN', $this->channel, strlen($data)).$data."\xCE";
89
    }
90
}
91