Completed
Push — master ( ce020b...db331d )
by Peter
02:12
created

InlineWrapper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 2
cbo 0
dl 43
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A __get() 4 4 1
A md() 5 5 1
A html() 5 5 1
A __toString() 12 12 3

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 software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/zamm
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 *
11
 */
12
13
namespace Maslosoft\Zamm\Helpers;
14
15
/**
16
 * Wrapper
17
 * @property Wrapper $md Get markdown wrapped code
18
 * @property Wrapper $html Get html `pre` wrapped code
19
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
20
 */
21 View Code Duplication
class InlineWrapper
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...
22
{
23
24
	private $text = '';
25
	private $isMd = false;
26
	private $isHtml = false;
27
28
	public function __construct($text)
29
	{
30
		$this->text = $text;
31
	}
32
33
	public function __get($name)
34
	{
35
		return $this->$name();
36
	}
37
38
	public function md()
39
	{
40
		$this->isMd = true;
41
		return $this;
42
	}
43
44
	public function html()
45
	{
46
		$this->isHtml = true;
47
		return $this;
48
	}
49
50
	public function __toString()
51
	{
52
		if ($this->isMd)
53
		{
54
			return "`$this->text`";
55
		}
56
		if ($this->isHtml)
57
		{
58
			return "<code>$this->text</code>";
59
		}
60
		return $this->text;
61
	}
62
63
}
64