Completed
Pull Request — master (#444)
by Yanick
12:17 queued 01:09
created

LiteSpeedTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 98
Duplicated Lines 13.27 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A getBinary() 0 4 2
A getCachingProxyPort() 0 4 2
A getHostName() 0 12 2
A getProxy() 0 13 3
A getProxyClient() 13 13 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
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test;
13
14
use FOS\HttpCache\ProxyClient\HttpDispatcher;
15
use FOS\HttpCache\ProxyClient\LiteSpeed;
16
use FOS\HttpCache\Test\Proxy\LiteSpeedProxy;
17
18
/**
19
 * Starts and clears the LiteSpeed proxy between tests.
20
 */
21
trait LiteSpeedTest
22
{
23
    /**
24
     * @var LiteSpeed
25
     */
26
    protected $proxyClient;
27
28
    /**
29
     * @var LiteSpeedProxy
30
     */
31
    protected $proxy;
32
33
    protected function setUp()
34
    {
35
        $this->getProxy()->clear();
36
    }
37
38
    protected function tearDown()
39
    {
40
        $this->getProxy()->stop();
41
    }
42
43
    /**
44
     * Defaults to "/usr/local/lsws/bin/lswsctrl".
45
     *
46
     * @return string
47
     */
48
    protected function getBinary()
49
    {
50
        return defined('LITESPEED_BINARY') ? LITESPEED_BINARY : null;
51
    }
52
53
    /**
54
     * Defaults to 80.
55
     *
56
     * @return int
57
     */
58
    protected function getCachingProxyPort()
59
    {
60
        return defined('LITESPEED_PORT') ? LITESPEED_PORT : 8089; // 8088 is used by nginx
61
    }
62
63
    /**
64
     * Get the hostname where your application can be reached.
65
     *
66
     * @throws \Exception
67
     *
68
     * @return string
69
     */
70
    protected function getHostName()
71
    {
72
        // @codeCoverageIgnoreStart
73
        if (!defined('WEB_SERVER_HOSTNAME')) {
74
            throw new \Exception(
75
                'To use this test, you need to define the WEB_SERVER_HOSTNAME constant in your phpunit.xml'
76
            );
77
        }
78
        // @codeCoverageIgnoreEnd
79
80
        return WEB_SERVER_HOSTNAME;
81
    }
82
83
    /**
84
     * @return LiteSpeedProxy
85
     */
86
    protected function getProxy()
87
    {
88
        if (null === $this->proxy) {
89
            $this->proxy = new LiteSpeedProxy();
90
            $this->proxy->setPort($this->getCachingProxyPort());
91
92
            if ($this->getBinary()) {
93
                $this->proxy->setBinary($this->getBinary());
94
            }
95
        }
96
97
        return $this->proxy;
98
    }
99
100
    /**
101
     * Get proxy client.
102
     *
103
     * @return LiteSpeed
104
     */
105 View Code Duplication
    protected function getProxyClient()
0 ignored issues
show
Duplication introduced by
This method 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...
106
    {
107
        if (null === $this->proxyClient) {
108
            $httpDispatcher = new HttpDispatcher(
109
                ['http://127.0.0.1:'.$this->getCachingProxyPort()],
110
                $this->getHostName().':'.$this->getCachingProxyPort()
111
            );
112
113
            $this->proxyClient = new LiteSpeed($httpDispatcher);
114
        }
115
116
        return $this->proxyClient;
117
    }
118
}
119