AddXOriginatingIpHeaderPlugin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 26.32 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 10
loc 38
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Init() 0 4 1
A FilterBuildMessage() 0 13 3
A configMapping() 10 10 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
class AddXOriginatingIpHeaderPlugin extends \RainLoop\Plugins\AbstractPlugin
4
{
5
	public function Init()
6
	{
7
		$this->addHook('filter.build-message', 'FilterBuildMessage');
8
	}
9
10
	/**
11
	 * @param \MailSo\Mime\Message $oMessage
12
	 */
13
	public function FilterBuildMessage(&$oMessage)
14
	{
15
		if ($oMessage instanceof \MailSo\Mime\Message)
0 ignored issues
show
Bug introduced by
The class MailSo\Mime\Message does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
16
		{
17
			$sIP = $this->Manager()->Actions()->Http()->GetClientIp(
18
				!!$this->Config()->Get('plugin', 'check_proxy', false));
19
			
20
			$oMessage->SetCustomHeader(
21
				\MailSo\Mime\Enumerations\Header::X_ORIGINATING_IP,
22
				$this->Manager()->Actions()->Http()->IsLocalhost($sIP) ? '127.0.0.1' : $sIP
23
			);
24
		}
25
	}
26
27
	/**
28
	 * @return array
29
	 */
30 View Code Duplication
	public function configMapping()
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...
31
	{
32
		return array(
33
			\RainLoop\Plugins\Property::NewInstance('check_proxy')
34
				->SetLabel('Сheck User Proxy')
35
				->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
36
				->SetDescription('Enable, if you need to check proxy header')
37
				->SetDefaultValue(false)
38
		);
39
	}
40
}