Skip to content

Commit 2be71c7

Browse files
author
Martin Brecht-Precht
committed
Fixed some minor code style issues.
1 parent 3e007cb commit 2be71c7

11 files changed

+111
-127
lines changed

.codeclimate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ ratings:
2525
- "**.rb"
2626
exclude_paths:
2727
- test/
28-
- vendor/
28+
- vendor/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/vendor
22
composer.lock
3-
vagrantfile
3+
vagrantfile

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ Contributing to our projects is always very appreciated.
125125

126126
## License
127127

128-
PHP QR Code Suite is under the MIT license.
128+
PHP QR Code Suite is under the MIT license.

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
</exclude>
1515
</whitelist>
1616
</filter>
17-
</phpunit>
17+
</phpunit>

src/QrEncode/QrEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function encodeQrCode($contents)
130130
throw new QrEncoderException('QR encoder internal error');
131131
}
132132

133-
$image = @imagecreatefrompng($pngPath);
133+
$image = imagecreatefrompng($pngPath);
134134
if ($image === false) {
135135
throw new QrEncoderException('GD lib internal error');
136136
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Markenwerk\QrCodeSuite\QrRender;
4+
5+
/**
6+
* Class AbstractPixelRenderer
7+
*
8+
* @package Markenwerk\QrCodeSuite\QrRender
9+
*/
10+
abstract class AbstractPixelRenderer
11+
{
12+
13+
/**
14+
* @var int
15+
*/
16+
private $approximateSize = 1000;
17+
18+
/**
19+
* @var int
20+
*/
21+
private $width;
22+
23+
/**
24+
* @var int
25+
*/
26+
private $height;
27+
28+
/**
29+
* @return int
30+
*/
31+
public function getApproximateSize()
32+
{
33+
return $this->approximateSize;
34+
}
35+
36+
/**
37+
* @param int $approximateSize
38+
* @return $this
39+
*/
40+
public function setApproximateSize($approximateSize)
41+
{
42+
if (!is_int($approximateSize) || $approximateSize < 0 || $approximateSize > 5000) {
43+
throw new \InvalidArgumentException('Approximate size has to be a positive integer less than 5000');
44+
}
45+
$this->approximateSize = $approximateSize;
46+
return $this;
47+
}
48+
49+
/**
50+
* @return int
51+
*/
52+
public function getWidth()
53+
{
54+
return $this->width;
55+
}
56+
57+
/**
58+
* @param int $width
59+
* @return $this
60+
*/
61+
protected function setWidth($width)
62+
{
63+
$this->width = $width;
64+
return $this;
65+
}
66+
67+
/**
68+
* @return int
69+
*/
70+
public function getHeight()
71+
{
72+
return $this->height;
73+
}
74+
75+
/**
76+
* @param int $height
77+
* @return $this
78+
*/
79+
protected function setHeight($height)
80+
{
81+
$this->height = $height;
82+
return $this;
83+
}
84+
85+
}

src/QrRender/Base/QrCodeRendererInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
interface QrCodeRendererInterface
1313
{
1414

15+
const MARGIN = 2;
16+
1517
/**
1618
* @param QrCode $qrCode
1719
* @param $filename

src/QrRender/PathFinder/QrCodePathFinder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ public function perform(QrCode $qrCode)
5151

5252
private function findPaths()
5353
{
54-
for ($y = 1; $y <= $this->qrCode->getHeight(); $y++) {
54+
$qrCodeHeight = $this->qrCode->getHeight();
55+
$qrCodeWidth = $this->qrCode->getWidth();
56+
for ($y = 1; $y <= $qrCodeHeight; $y++) {
5557
$qrCodePointRow = $this->qrCode->getRow($y);
56-
for ($x = 1; $x <= $this->qrCode->getWidth(); $x++) {
58+
for ($x = 1; $x <= $qrCodeWidth; $x++) {
5759
if (!isset($this->visited[$y][$x])) {
5860
$qrCodePoint = $qrCodePointRow->getPoint($x);
5961
if ($this->isCorner($x, $y)) {
@@ -86,7 +88,7 @@ private function isCorner($xPosition, $yPosition)
8688
* @param int $startXPosition
8789
* @param int $startYPosition
8890
* @param bool $active
89-
* @return array
91+
* @return Path
9092
*/
9193
private function traceComposite($startXPosition, $startYPosition, $active)
9294
{

src/QrRender/QrCodeRendererEps.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
class QrCodeRendererEps implements Base\QrCodeRendererInterface
1717
{
1818

19-
const MARGIN = 2;
2019
const POINTS_PER_BLOCK = 5;
2120

2221
/**
@@ -84,7 +83,8 @@ public function render(QrCode $qrCode, $filename)
8483
$epsSource[] = $this->foregroundColor->getEpsNotation() . ' setcmykcolor';
8584

8685
foreach ($paths as $path) {
87-
for ($i = 0; $i < $path->countPoints(); $i++) {
86+
$pointCount = $path->countPoints();
87+
for ($i = 0; $i < $pointCount; $i++) {
8888
if ($i == 0) {
8989
$epsSource[] = $this->convertPoint($path->getFirstPoint()) . ' m';
9090
} else {

src/QrRender/QrCodeRendererPng.php

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
*
1212
* @package Markenwerk\QrCodeSuite\QrRender
1313
*/
14-
class QrCodeRendererPng implements Base\QrCodeRendererInterface
14+
class QrCodeRendererPng extends AbstractPixelRenderer implements Base\QrCodeRendererInterface
1515
{
1616

17-
const MARGIN = 2;
18-
1917
/**
2018
* @var RgbColor
2119
*/
@@ -26,21 +24,6 @@ class QrCodeRendererPng implements Base\QrCodeRendererInterface
2624
*/
2725
private $backgroundColor;
2826

29-
/**
30-
* @var int
31-
*/
32-
private $approximateSize = 1000;
33-
34-
/**
35-
* @var int
36-
*/
37-
private $width;
38-
39-
/**
40-
* @var int
41-
*/
42-
private $height;
43-
4427
/**
4528
* QrCodeRendererPng constructor.
4629
*/
@@ -86,43 +69,6 @@ public function setBackgroundColor(RgbColor $backgroundColor)
8669
return $this;
8770
}
8871

89-
/**
90-
* @return int
91-
*/
92-
public function getApproximateSize()
93-
{
94-
return $this->approximateSize;
95-
}
96-
97-
/**
98-
* @param int $approximateSize
99-
* @return $this
100-
*/
101-
public function setApproximateSize($approximateSize)
102-
{
103-
if (!is_int($approximateSize) || $approximateSize < 0 || $approximateSize > 5000) {
104-
throw new \InvalidArgumentException('Approximate size has to be a positive integer less than 5000');
105-
}
106-
$this->approximateSize = $approximateSize;
107-
return $this;
108-
}
109-
110-
/**
111-
* @return int
112-
*/
113-
public function getWidth()
114-
{
115-
return $this->width;
116-
}
117-
118-
/**
119-
* @return int
120-
*/
121-
public function getHeight()
122-
{
123-
return $this->height;
124-
}
125-
12672
/**
12773
* @param QrCode $qrCode
12874
* @param string $filename
@@ -139,17 +85,17 @@ public function render(QrCode $qrCode, $filename)
13985
$height = $qrCode->getHeight();
14086

14187
// Calculate params
142-
$blockSize = round($this->approximateSize / ($width + 2 * self::MARGIN));
143-
$this->width = (int)($width + 2 * self::MARGIN) * $blockSize;
144-
$this->height = (int)($height + 2 * self::MARGIN) * $blockSize;
88+
$blockSize = round($this->getApproximateSize() / ($width + 2 * self::MARGIN));
89+
$this->setWidth((int)($width + 2 * self::MARGIN) * $blockSize);
90+
$this->setHeight((int)($height + 2 * self::MARGIN) * $blockSize);
14591

14692
// Define colors
14793
$black = new \ImagickPixel($this->foregroundColor->getHex());
14894
$white = new \ImagickPixel($this->backgroundColor->getHex());
14995

15096
// Prepare canvas
15197
$canvas = new \Imagick();
152-
$canvas->newImage($this->width, $this->height, $white, "png");
98+
$canvas->newImage($this->getWidth(), $this->getHeight(), $white, "png");
15399
$canvas->setImageColorspace(\Imagick::COLORSPACE_RGB);
154100
$canvas->setImageDepth(8);
155101

@@ -172,7 +118,7 @@ public function render(QrCode $qrCode, $filename)
172118
$canvas->drawImage($draw);
173119

174120
// Write out the image
175-
$writeSuccess = @$canvas->writeImage($filename);
121+
$writeSuccess = $canvas->writeImage($filename);
176122
$canvas->clear();
177123
$canvas->destroy();
178124

src/QrRender/QrCodeRendererTiff.php

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
*
1212
* @package Markenwerk\QrCodeSuite\QrRender
1313
*/
14-
class QrCodeRendererTiff implements Base\QrCodeRendererInterface
14+
class QrCodeRendererTiff extends AbstractPixelRenderer implements Base\QrCodeRendererInterface
1515
{
1616

17-
const MARGIN = 2;
18-
1917
/**
2018
* @var CmykColor
2119
*/
@@ -26,21 +24,6 @@ class QrCodeRendererTiff implements Base\QrCodeRendererInterface
2624
*/
2725
private $backgroundColor;
2826

29-
/**
30-
* @var int
31-
*/
32-
private $approximateSize = 1000;
33-
34-
/**
35-
* @var int
36-
*/
37-
private $width;
38-
39-
/**
40-
* @var int
41-
*/
42-
private $height;
43-
4427
/**
4528
* QrCodeRendererTiff constructor.
4629
*/
@@ -87,40 +70,6 @@ public function setBackgroundColor(CmykColor $backgroundColor)
8770
return $this;
8871
}
8972

90-
/**
91-
* @return int
92-
*/
93-
public function getApproximateSize()
94-
{
95-
return $this->approximateSize;
96-
}
97-
98-
/**
99-
* @param int $approximateSize
100-
* @return $this
101-
*/
102-
public function setApproximateSize($approximateSize)
103-
{
104-
$this->approximateSize = $approximateSize;
105-
return $this;
106-
}
107-
108-
/**
109-
* @return int
110-
*/
111-
public function getWidth()
112-
{
113-
return $this->width;
114-
}
115-
116-
/**
117-
* @return int
118-
*/
119-
public function getHeight()
120-
{
121-
return $this->height;
122-
}
123-
12473
/**
12574
* @param QrCode $qrCode
12675
* @param string $filename
@@ -137,17 +86,17 @@ public function render(QrCode $qrCode, $filename)
13786
$height = $qrCode->getHeight();
13887

13988
// Calculate params
140-
$blockSize = round($this->approximateSize / ($width + 2 * self::MARGIN));
141-
$this->width = (int)($width + 2 * self::MARGIN) * $blockSize;
142-
$this->height = (int)($height + 2 * self::MARGIN) * $blockSize;
89+
$blockSize = round($this->getApproximateSize() / ($width + 2 * self::MARGIN));
90+
$this->setWidth((int)($width + 2 * self::MARGIN) * $blockSize);
91+
$this->setHeight((int)($height + 2 * self::MARGIN) * $blockSize);
14392

14493
// Define colors
14594
$black = new \ImagickPixel($this->foregroundColor->getImagickNotation());
14695
$white = new \ImagickPixel($this->backgroundColor->getImagickNotation());
14796

14897
// Prepare canvas
14998
$canvas = new \Imagick();
150-
$canvas->newImage($this->width, $this->height, $white, "tiff");
99+
$canvas->newImage($this->getWidth(), $this->getHeight(), $white, "tiff");
151100
$canvas->setImageColorspace(\Imagick::COLORSPACE_CMYK);
152101
$canvas->setImageDepth(8);
153102

@@ -173,7 +122,7 @@ public function render(QrCode $qrCode, $filename)
173122
}
174123

175124
// Write out the image
176-
$writeSuccess = @$canvas->writeImage($filename);
125+
$writeSuccess = $canvas->writeImage($filename);
177126
$canvas->clear();
178127
$canvas->destroy();
179128
$block->clear();

0 commit comments

Comments
 (0)