I25Object   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 165
Duplicated Lines 20.61 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 34
loc 165
rs 10
c 0
b 0
f 0
wmc 25
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A I25Object() 0 16 1
B GetSize() 6 39 10
A DrawStart() 10 10 1
A DrawStop() 9 9 1
C DrawObject() 9 48 12

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
// File name   : i25aobject.php
4
// Begin       : 2002-07-31
5
// Last Update : 2004-12-29
6
// Author      : Karim Mribti [[email protected]]
7
//             : Nicola Asuni [[email protected]]
8
// Version     : 0.0.8a  2001-04-01 (original code)
9
// License     : GNU LGPL (Lesser General Public License) 2.1
10
//               http://www.gnu.org/copyleft/lesser.txt
11
// Source Code : http://www.mribti.com/barcode/
12
//
13
// Description : I25 Barcode Render Class for PHP using
14
//               the GD graphics library.
15
//               Interleaved 2 of 5 is a numeric only bar code
16
//               with a optional check number.
17
//
18
// NOTE:
19
// This version contains changes by Nicola Asuni:
20
//  - porting to PHP4
21
//  - code style and formatting
22
//  - automatic php documentation in PhpDocumentor Style
23
//    (www.phpdoc.org)
24
//  - minor bug fixing
25
//============================================================+
26
27
/**
28
 * I25 Barcode Render Class for PHP using the GD graphics library.<br<
29
 * Interleaved 2 of 5 is a numeric only bar code with a optional check number.
30
 * @author Karim Mribti, Nicola Asuni
31
 * @name BarcodeObject
32
 * @package com.tecnick.tcpdf
33
 * @version 0.0.8a  2001-04-01 (original code)
34
 * @since 2001-03-25
35
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
36
 */
37
38
/**
39
 * I25 Barcode Render Class for PHP using the GD graphics library.<br<
40
 * Interleaved 2 of 5 is a numeric only bar code with a optional check number.
41
 * @author Karim Mribti, Nicola Asuni
42
 * @name BarcodeObject
43
 * @package com.tecnick.tcpdf
44
 * @version 0.0.8a  2001-04-01 (original code)
45
 * @since 2001-03-25
46
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
47
 */
48
class I25Object extends BarcodeObject {
49
	
50
	/**
51
	 * Class Constructor.
52
	 * @param int $Width Image width in pixels.
53
	 * @param int $Height Image height in pixels. 
54
	 * @param int $Style Barcode style.
55
	 * @param int $Value value to print on barcode.
56
	 */
57
	function I25Object($Width, $Height, $Style, $Value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
58
		$this->BarcodeObject($Width, $Height, $Style);
59
		$this->mValue = $Value;
0 ignored issues
show
Bug introduced by
The property mValue does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60
		$this->mCharSet = array (
0 ignored issues
show
Documentation Bug introduced by
It seems like array('00110', '10001', ...011', '10010', '01010') of type array<integer,string,{"0..."string","9":"string"}> is incompatible with the declared type object<Character> of property $mCharSet.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
		/* 0 */ "00110",
62
		/* 1 */ "10001",
63
		/* 2 */ "01001",
64
		/* 3 */ "11000",
65
		/* 4 */ "00101",
66
		/* 5 */ "10100",
67
		/* 6 */ "01100",
68
		/* 7 */ "00011",
69
		/* 8 */ "10010",
70
		/* 9 */ "01010"
71
		);
72
	}
73
	
74
	/**
75
	 * Returns barcode size.
76
	 * @param int $xres Horizontal resolution.
77
	 * @return barcode size.
0 ignored issues
show
Documentation introduced by
Should the return type not be false|integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
78
	 * @access private
79
	 */
80
	function GetSize($xres) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
81
		$len = strlen($this->mValue);
82
83
		if ($len == 0)  {
84
			$this->mError = "Null value";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'Null value' of type string is incompatible with the declared type object<Error> of property $mError.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
			return false;
86
		}
87
88 View Code Duplication
		for ($i=0;$i<$len;$i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
89
			if ((ord($this->mValue[$i])<48) || (ord($this->mValue[$i])>57)) {
90
				$this->mError = "I25 is numeric only";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'I25 is numeric only' of type string is incompatible with the declared type object<Error> of property $mError.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
91
				return false;
92
			}
93
		}
94
95
		if (($len%2) != 0) {
96
			$this->mError = "The length of barcode value must be even";
0 ignored issues
show
Documentation Bug introduced by
It seems like 'The length of barcode value must be even' of type string is incompatible with the declared type object<Error> of property $mError.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
97
			return false;
98
		}
99
		$StartSize = BCD_I25_NARROW_BAR * 4  * $xres;
100
		$StopSize  = BCD_I25_WIDE_BAR * $xres + 2 * BCD_I25_NARROW_BAR * $xres;
101
		$cPos = 0;
102
		$sPos = 0;
103
		do {
104
			$c1    = $this->mValue[$cPos];
105
			$c2    = $this->mValue[$cPos+1];
106
			$cset1 = $this->mCharSet[$c1];
107
			$cset2 = $this->mCharSet[$c2];
108
109
			for ($i=0;$i<5;$i++) {
110
				$type1 = ($cset1[$i]==0) ? (BCD_I25_NARROW_BAR  * $xres) : (BCD_I25_WIDE_BAR * $xres);
111
				$type2 = ($cset2[$i]==0) ? (BCD_I25_NARROW_BAR  * $xres) : (BCD_I25_WIDE_BAR * $xres);
112
				$sPos += ($type1 + $type2);
113
			}
114
			$cPos+=2;
115
		} while ($cPos<$len);
116
117
		return $sPos + $StartSize + $StopSize;
118
	}
119
120
	/**
121
	 * Draws the start code.
122
	 * @param int $DrawPos Drawing position.
123
	 * @param int $yPos Vertical position.
124
	 * @param int $ySize Vertical size.
125
	 * @param int $xres Horizontal resolution.
126
	 * @return int drawing position.
127
	 * @access private
128
	 */
129 View Code Duplication
	function DrawStart($DrawPos, $yPos, $ySize, $xres) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
130
		/* Start code is "0000" */
131
		$this->DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR  * $xres , $ySize);
132
		$DrawPos += BCD_I25_NARROW_BAR  * $xres;
133
		$DrawPos += BCD_I25_NARROW_BAR  * $xres;
134
		$this->DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR  * $xres , $ySize);
135
		$DrawPos += BCD_I25_NARROW_BAR  * $xres;
136
		$DrawPos += BCD_I25_NARROW_BAR  * $xres;
137
		return $DrawPos;
138
	}
139
	
140
	/**
141
	 * Draws the stop code.
142
	 * @param int $DrawPos Drawing position.
143
	 * @param int $yPos Vertical position.
144
	 * @param int $ySize Vertical size.
145
	 * @param int $xres Horizontal resolution.
146
	 * @return int drawing position.
147
	 * @access private
148
	 */
149 View Code Duplication
	function DrawStop($DrawPos, $yPos, $ySize, $xres) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
150
		/* Stop code is "100" */
151
		$this->DrawSingleBar($DrawPos, $yPos, BCD_I25_WIDE_BAR * $xres , $ySize);
152
		$DrawPos += BCD_I25_WIDE_BAR  * $xres;
153
		$DrawPos += BCD_I25_NARROW_BAR  * $xres;
154
		$this->DrawSingleBar($DrawPos, $yPos, BCD_I25_NARROW_BAR  * $xres , $ySize);
155
		$DrawPos += BCD_I25_NARROW_BAR  * $xres;
156
		return $DrawPos;
157
	}
158
159
	/**
160
	 * Draws the barcode object.
161
	 * @param int $xres Horizontal resolution.
162
	 * @return bool true in case of success.
163
	 */
164
	function DrawObject($xres) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
165
		$len = strlen($this->mValue);
166
167
		if (($size = $this->GetSize($xres))==0) {
168
			return false;
169
		}
170
171
		$cPos  = 0;
172
173
		if ($this->mStyle & BCS_DRAW_TEXT) $ysize = $this->mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2 - $this->GetFontHeight($this->mFont);
174
		else $ysize = $this->mHeight - BCD_DEFAULT_MAR_Y1 - BCD_DEFAULT_MAR_Y2;
175
176
		if ($this->mStyle & BCS_ALIGN_CENTER) $sPos = (integer)(($this->mWidth - $size ) / 2);
177
		else if ($this->mStyle & BCS_ALIGN_RIGHT) $sPos = $this->mWidth - $size;
178
		else $sPos = 0;
179
180
		if ($this->mStyle & BCS_DRAW_TEXT) {
181
			if ($this->mStyle & BCS_STRETCH_TEXT) {
182
				/* Stretch */
183 View Code Duplication
				for ($i=0;$i<$len;$i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
184
					$this->DrawChar($this->mFont, $sPos+BCD_I25_NARROW_BAR*4*$xres+($size/$len)*$i,
185
					$ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET , $this->mValue[$i]);
186
				}
187 View Code Duplication
			}else {/* Center */
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
188
			$text_width = $this->GetFontWidth($this->mFont) * strlen($this->mValue);
189
			$this->DrawText($this->mFont, $sPos+(($size-$text_width)/2)+(BCD_I25_NARROW_BAR*4*$xres),
190
			$ysize + BCD_DEFAULT_MAR_Y1 + BCD_DEFAULT_TEXT_OFFSET, $this->mValue);
191
			}
192
		}
193
194
		$sPos = $this->DrawStart($sPos, BCD_DEFAULT_MAR_Y1, $ysize, $xres);
195
		do {
196
			$c1 = $this->mValue[$cPos];
197
			$c2 = $this->mValue[$cPos+1];
198
			$cset1 = $this->mCharSet[$c1];
199
			$cset2 = $this->mCharSet[$c2];
200
201
			for ($i=0;$i<5;$i++) {
202
				$type1 = ($cset1[$i]==0) ? (BCD_I25_NARROW_BAR * $xres) : (BCD_I25_WIDE_BAR * $xres);
203
				$type2 = ($cset2[$i]==0) ? (BCD_I25_NARROW_BAR * $xres) : (BCD_I25_WIDE_BAR * $xres);
204
				$this->DrawSingleBar($sPos, BCD_DEFAULT_MAR_Y1, $type1 , $ysize);
205
				$sPos += ($type1 + $type2);
206
			}
207
			$cPos+=2;
208
		} while ($cPos<$len);
209
		$sPos =  $this->DrawStop($sPos, BCD_DEFAULT_MAR_Y1, $ysize, $xres);
0 ignored issues
show
Unused Code introduced by
$sPos is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
210
		return true;
211
	}
212
}
213
214
//============================================================+
215
// END OF FILE
216
//============================================================+
217
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...