Skip to content

Commit 6439ac4

Browse files
author
SimpleCorey
committed
Add Interfaces
1 parent 5ac7e57 commit 6439ac4

File tree

4 files changed

+82
-23
lines changed

4 files changed

+82
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use BaconQrCode\Encoder\Encoder;
2020
use BaconQrCode\Common\ErrorCorrectionLevel;
2121

22-
class QrCodeGenerator {
22+
class BaconQrCodeGenerator implements QrCodeInterface {
2323

2424
/**
2525
* Holds the BaconQrCode Writer Object

src/QrCodeInterface.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php namespace SimpleSoftwareIO\QrCode;
2+
3+
interface QrCodeInterface {
4+
/**
5+
* Generates a QrCode
6+
*
7+
* @param string $text The text to be converted into a QrCode
8+
* @param null|string $filename The filename and path to save the QrCode file
9+
* @return string|void Returns a QrCode string depending on the format, or saves to a file.
10+
*/
11+
public function generate($text, $filename = null);
12+
13+
/**
14+
* Switches the format of the outputted QrCode or defaults to SVG
15+
*
16+
* @param string $format
17+
* @return $this
18+
*/
19+
public function format($format);
20+
21+
/**
22+
* Changes the size of the QrCode
23+
*
24+
* @param int $pixels The size of the QrCode in pixels
25+
* @return $this
26+
*/
27+
public function size($pixels);
28+
29+
/**
30+
* Changes the foreground color of a QrCode
31+
*
32+
* @param int $red
33+
* @param int $green
34+
* @param int $blue
35+
* @return $this
36+
*/
37+
public function color($red, $green, $blue);
38+
39+
/**
40+
* Changes the background color of a QrCode
41+
*
42+
* @param int $red
43+
* @param int $green
44+
* @param int $blue
45+
* @return $this
46+
*/
47+
public function backgroundColor($red, $green, $blue);
48+
49+
/**
50+
* Changes the error correction level of a QrCode
51+
*
52+
* @param string $level Desired error correction level. L = 7% M = 15% Q = 25% H = 30%
53+
* @return $this
54+
*/
55+
public function errorCorrection($level);
56+
57+
/**
58+
* Creates a margin around the QrCode
59+
*
60+
* @param int $margin The desired margin in pixels around the QrCode
61+
* @return $this
62+
*/
63+
public function margin($margin);
64+
}

src/QrCodeServiceProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class QrCodeServiceProvider extends ServiceProvider {
2626
*/
2727
public function register()
2828
{
29-
$this->app->bindShared('qrcode', function() { return new QrCodeGenerator; });
29+
$this->app->bindShared('qrcode', function()
30+
{
31+
return new BaconQrCodeGenerator;
32+
});
3033
}
3134

3235
/**
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
use Mockery as m;
3-
use SimpleSoftwareIO\QrCode\QrCodeGenerator;
3+
use SimpleSoftwareIO\QrCode\BaconQrCodeGenerator;
44

5-
class QrCodeGeneratorTest extends \PHPUnit_Framework_TestCase {
5+
class BaconQrCodeGeneratorTest extends \PHPUnit_Framework_TestCase {
66

77
public function tearDown()
88
{
@@ -13,6 +13,7 @@ public function setUp()
1313
{
1414
$this->writer = m::mock('\BaconQrCode\Writer');
1515
$this->format = m::mock('\BaconQrCode\Renderer\Image\RendererInterface');
16+
$this->qrCode = new BaconQrCodeGenerator($this->writer, $this->format);
1617
}
1718

1819
public function testSetMargin()
@@ -25,7 +26,7 @@ public function testSetMargin()
2526
->once()
2627
->andReturn($this->format);
2728

28-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
29+
$qrCode = new BaconQrCodeGenerator($this->writer, $this->format);
2930
$qrCode->margin(50);
3031
}
3132

@@ -38,8 +39,7 @@ public function testSetBackgroundColor()
3839
->once()
3940
->andReturn($this->format);
4041

41-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
42-
$qrCode->backgroundColor(255,255,255);
42+
$this->qrCode->backgroundColor(255,255,255);
4343
}
4444

4545
public function testSetColor()
@@ -51,8 +51,7 @@ public function testSetColor()
5151
->once()
5252
->andReturn($this->format);
5353

54-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
55-
$qrCode->color(255,255,255);
54+
$this->qrCode->color(255,255,255);
5655
}
5756

5857
public function testSetSize()
@@ -68,8 +67,7 @@ public function testSetSize()
6867
->twice()
6968
->andReturn($this->format);
7069

71-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
72-
$qrCode->size(50);
70+
$this->qrCode->size(50);
7371
}
7472

7573
public function testSetFormatPng()
@@ -78,8 +76,7 @@ public function testSetFormatPng()
7876
->with('BaconQrCode\Renderer\Image\Png')
7977
->once();
8078

81-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
82-
$qrCode->format('png');
79+
$this->qrCode->format('png');
8380
}
8481

8582
public function testSetFormatEps()
@@ -88,8 +85,7 @@ public function testSetFormatEps()
8885
->with('BaconQrCode\Renderer\Image\Eps')
8986
->once();
9087

91-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
92-
$qrCode->format('eps');
88+
$this->qrCode->format('eps');
9389
}
9490

9591
public function testSetFormatSvg()
@@ -98,8 +94,7 @@ public function testSetFormatSvg()
9894
->with('BaconQrCode\Renderer\Image\Svg')
9995
->once();
10096

101-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
102-
$qrCode->format('svg');
97+
$this->qrCode->format('svg');
10398
}
10499

105100
public function testSetFormatUnknown()
@@ -108,8 +103,7 @@ public function testSetFormatUnknown()
108103
->with('BaconQrCode\Renderer\Image\Svg')
109104
->once();
110105

111-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
112-
$qrCode->format('random');
106+
$this->qrCode->format('random');
113107
}
114108

115109
public function testGenerate()
@@ -118,8 +112,7 @@ public function testGenerate()
118112
->with('qrCode', m::type('string'), m::type('int'))
119113
->once();
120114

121-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
122-
$qrCode->generate('qrCode');
115+
$this->qrCode->generate('qrCode');
123116
}
124117

125118
public function testGenerateFile()
@@ -128,8 +121,7 @@ public function testGenerateFile()
128121
->with('qrCode', 'foo.txt', m::type('string'), m::type('int'))
129122
->once();
130123

131-
$qrCode = new QrCodeGenerator($this->writer, $this->format);
132-
$qrCode->generate('qrCode', 'foo.txt');
124+
$this->qrCode->generate('qrCode', 'foo.txt');
133125
}
134126
}
135127

0 commit comments

Comments
 (0)