Permalink
Browse files

Issue #3 PHPCS

  • Loading branch information...
1 parent 9451abc commit eecac942b46c807c30624b29831db453b2b99b8f @CloCkWeRX committed Dec 11, 2011
Showing with 50 additions and 33 deletions.
  1. +50 −33 Image/Barcode2/Code39.php
View
@@ -123,25 +123,25 @@ class Image_Barcode2_Code39
/**
* Constructor
*
- * @param string $text A text that should be in the image barcode
- * @param int $wThin Width of the thin lines on the barcode
- * @param int $wThick Width of the thick lines on the barcode
+ * @param string $text A text that should be in the image barcode
+ * @param int $wThin Width of the thin lines on the barcode
+ * @param int $wThick Width of the thick lines on the barcode
*
* @author Ryan Briones <ryanbriones@webxdesign.org>
*
*/
- public function __construct( $text = '', $wThin = 0, $wThick = 0 )
+ public function __construct($text = '', $wThin = 0, $wThick = 0)
{
// Check $text for invalid characters
- if ( $this->_checkInvalid( $text ) ) {
+ if ($this->_checkInvalid($text)) {
return false;
}
$this->text = $text;
- if ( $wThin > 0 ) {
+ if ($wThin > 0 ) {
$this->_barthinwidth = $wThin;
}
- if ( $wThick > 0 ) {
+ if ($wThick > 0 ) {
$this->_barthickwidth = $wThick;
}
@@ -162,33 +162,47 @@ private function _plot()
$final_text = '*' . $this->text . '*';
$barcode = '';
- foreach ( str_split( $final_text ) as $character ) {
- $barcode .= $this->_dumpCode( $this->_coding_map[$character] . '0' );
+ foreach (str_split($final_text) as $character) {
+ $barcode .= $this->_dumpCode($this->_coding_map[$character] . '0');
}
- $barcode_len = strlen( $barcode );
+ $barcode_len = strlen($barcode);
// Create GD image object
- $img = imagecreate( $barcode_len, $this->_barcodeheight );
+ $img = imagecreate($barcode_len, $this->_barcodeheight);
// Allocate black and white colors to the image
- $black = imagecolorallocate( $img, 0, 0, 0 );
- $white = imagecolorallocate( $img, 255, 255, 255 );
- $font_height = imagefontheight( $this->_font_size );
- $font_width = imagefontwidth( $this->_font_size );
+ $black = imagecolorallocate($img, 0, 0, 0);
+ $white = imagecolorallocate($img, 255, 255, 255);
+ $font_height = imagefontheight($this->_font_size);
+ $font_width = imagefontwidth($this->_font_size);
// fill background with white color
- imagefill( $img, 0, 0, $white );
+ imagefill($img, 0, 0, $white);
// Initialize X position
$xpos = 0;
// draw barcode bars to image
- foreach (str_split($barcode) as $character_code ) {
+ foreach (str_split($barcode) as $character_code) {
if ($character_code == 0) {
- imageline($img, $xpos, 0, $xpos, $this->_barcodeheight - $font_height - 1, $white);
+ imageline(
+ $img,
+ $xpos,
+ 0,
+ $xpos,
+ $this->_barcodeheight - $font_height - 1,
+ $white
+ );
} else {
- imageline($img, $xpos, 0, $xpos, $this->_barcodeheight - $font_height - 1, $black);
+ imageline(
+ $img,
+ $xpos,
+ 0,
+ $xpos,
+ $this->_barcodeheight - $font_height - 1,
+ $black
+ );
}
$xpos++;
@@ -198,7 +212,7 @@ private function _plot()
imagestring(
$img,
$this->_font_size,
- ( $barcode_len - $font_width * strlen( $this->text ) )/2,
+ ($barcode_len - $font_width * strlen($this->text))/2,
$this->_barcodeheight - $font_height,
$this->text,
$black
@@ -210,13 +224,12 @@ private function _plot()
/**
- * Send image to the browser; for Image_Barcode2 compaitbility
+ * Send image to the browser; for Image_Barcode2 compatibility
*
- * @param string $text
- * @return gd_image GD image object
+ * @param string $text Text to render
*
+ * @return gd_image GD image object
* @author Ryan Briones <ryanbriones@webxdesign.org>
- *
*/
public function draw($text)
{
@@ -237,11 +250,10 @@ public function draw($text)
* GD::Barcode::Code39. I royally screwed up when trying to do the thing
* my own way the first time. This way works.
*
- * @param string $code Code39 barcode code
- * @return string $result barcode line code
+ * @param string $code Code39 barcode code
*
+ * @return string $result barcode line code
* @access private
- *
* @author Ryan Briones <ryanbriones@webxdesign.org>
*
*
@@ -252,9 +264,14 @@ private function _dumpCode($code)
$color = 1; // 1: Black, 0: White
// if $bit is 1, line is wide; if $bit is 0 line is thin
- foreach ( str_split( $code ) as $bit ) {
- $result .= ( ( $bit == 1 ) ? str_repeat( $color, $this->_barthickwidth ) : str_repeat( $color, $this->_barthinwidth ) );
- $color = ( ( $color == 0 ) ? 1 : 0 );
+ foreach (str_split($code) as $bit) {
+ if ($bit == 1) {
+ $result .= str_repeat($color, $this->_barthickwidth);
+ } else {
+ $result .= str_repeat($color, $this->_barthinwidth);
+ }
+
+ $color = ($color == 0) ? 1 : 0;
}
return $result;
@@ -264,15 +281,15 @@ private function _dumpCode($code)
/**
* Check for invalid characters
*
- * @param string $text text to be ckecked
- * @return bool returns true when invalid characters have been found
+ * @param string $text text to be ckecked
*
+ * @return bool returns true when invalid characters have been found
* @author Ryan Briones <ryanbriones@webxdesign.org>
*
*/
private function _checkInvalid($text)
{
- return preg_match( "/[^0-9A-Z\-*+\$%\/. ]/", $text );
+ return preg_match("/[^0-9A-Z\-*+\$%\/. ]/", $text);
}
}

0 comments on commit eecac94

Please sign in to comment.