Skip to content

Commit d88ef01

Browse files
author
Martin Brecht-Precht
committed
Initial commit.
0 parents  commit d88ef01

17 files changed

+1198
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

CONTRIBUTING.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Contributing to QR Code Suite
2+
3+
## About
4+
5+
This document provides a set of best practices for contributions - bug reports, code submissions / pull requests, etc.
6+
7+
## Sources
8+
9+
This document is based on the open source document [Contributing to Open Source Projects](http://contribution-guide-org.readthedocs.org/) by [Jeff Forcier](https://github.com/bitprophet).
10+
11+
## Submitting bugs
12+
13+
### Due diligence
14+
15+
Before submitting a bug, please do the following:
16+
17+
- Perform **basic troubleshooting** steps:
18+
- **Make sure you’re on the latest version.** If you’re not on the most recent version, your problem may have been solved already!
19+
Upgrading is always the best first step.
20+
- **Try older versions.** If you’re already on the latest release, try rolling back a few minor versions (e.g. if on 1.7, try 1.5 or 1.6) and see if the problem goes away. This will help the devs narrow down when the problem first arose in the commit log.
21+
- **Try switching up dependency versions.** If the software in question has dependencies (other libraries, etc) try upgrading / downgrading those as well.
22+
- **Search the project’s issue tracker** to make sure it’s not a known issue.
23+
24+
#### What to put in your bug report
25+
26+
Make sure your report gets the attention it deserves: bug reports with missing information may be ignored or punted back to you, delaying a fix. The below constitutes a bare minimum; more info is almost always better:
27+
28+
- **What PHP version** are you using?
29+
- **Which additional core libraries and extensions** in which versions are available?
30+
- **What operating system in which version are you on?** Again, more detail is better.
31+
- **Which version of the software are you using?** Ideally, you followed the advice above and have ruled out (or verified that the problem exists in) a few different versions.
32+
- **How can the developers recreate the bug on their end?** If possible, include a copy of your code, the command you used to invoke it, and the full output of your run (if applicable.)
33+
A common tactic is to pare down your code until a simple (but still bug-causing) “base case” remains. Not only can this help you identify problems which aren’t real bugs, but it means the developer can get to fixing the bug faster.
34+
35+
## Contributing changes
36+
37+
### Version control branching
38+
39+
Always **make a new branch** for your work, no matter how small. This makes it easy for others to take just that one set of changes from your repository, in case you have multiple unrelated changes floating around.
40+
41+
- A corollary: **don’t submit unrelated changes in the same branch / pull request!** The maintainer shouldn’t have to reject your awesome bugfix because the feature you put in with it needs more review.
42+
43+
**Base your new branch off of the appropriate branch** on the main repository:
44+
45+
- **Bug fixes** should be based on the branch named after the oldest supported release line the bug affects.
46+
- E.g. if a feature was introduced in 1.1, the latest release line is 1.3, and a bug is found in that feature - make your branch based on 1.1. The maintainer will then forward-port it to 1.3 and master.
47+
- Bug fixes requiring large changes to the code or which have a chance of being otherwise disruptive, may need to base off of `master` instead. This is a judgement call – ask the devs!
48+
- **New features** should branch off of **the `master` branch.**
49+
- Note that depending on how long it takes for the dev team to merge your patch, the copy of `master` you worked off of may get out of date! If you find yourself ‘bumping’ a pull request that’s been sidelined for a while, **make sure you rebase or merge to latest `master`** to ensure a speedier resolution.
50+
51+
### Code formatting
52+
53+
**Follow the style you see used in the primary repository!** Consistency with the rest of the project always trumps other considerations. It doesn’t matter if you have your own style or if the rest of the code breaks with the greater community - just follow along.
54+
55+
PHP projects usually follow the [PHP Standards Recommendations guidelines](http://www.php-fig.org/psr/) (though many have minor deviations depending on the lead maintainers’ preferences.)
56+
57+
### Documentation isn’t optional
58+
59+
It’s not! Patches without documentation will be returned to sender. By “documentation” we mean:
60+
61+
- **Docstrings / DocBlocks** must be created or updated for public and private API methods.
62+
- New features should ideally include **a brief description of business logic,** including useful example code snippets.
63+
- All submissions should have **changelog styled commit and pull request messages** crediting the contributor and / or any individuals instrumental in identifying the problem.
64+
65+
### Tests aren’t optional
66+
67+
Any bugfix that doesn’t include a test proving the existence of the bug being fixed, may be suspect. Ditto for new features that can’t prove they actually work.
68+
69+
We’ve found that test-first development really helps make features better architected and identifies potential edge cases earlier instead of later. Writing tests before the implementation is strongly encouraged.
70+
71+
## Full example
72+
73+
Here’s an example workflow for `php-qr-code-suite` hosted on Github, which is currently in version 2.0.x. Your username is `yourname` and you’re submitting a basic bugfix.
74+
75+
### Preparing your Fork
76+
77+
- Hit ‘fork’ on Github, creating e.g. `yourname/php-qr-code-suite`
78+
- Clone your project
79+
80+
```
81+
git clone git@github.com:yourname/php-qr-code-suite
82+
```
83+
84+
- Create a branch
85+
86+
```
87+
cd php-qr-code-suite
88+
git checkout -b foo-the-bars 2.0
89+
```
90+
91+
### Making your Changes
92+
93+
- Write tests expecting the correct / fixed functionality; make sure they fail.
94+
- Hack, hack, hack.
95+
- Run tests again, making sure they pass.
96+
- Commit your changes
97+
98+
```
99+
git commit -m "Changelog styled commit message crediting yourself"
100+
```
101+
102+
### Creating Pull Requests
103+
104+
- Push your commit to get it back up to your fork
105+
106+
```
107+
git push origin HEAD
108+
```
109+
110+
- Visit Github, click handy “Pull request” button that it will make upon noticing your new branch.
111+
- In the description field, write down issue number (if submitting code fixing an existing issue) or describe the issue + your fix (if submitting a wholly new bugfix).
112+
- Hit ‘submit’! And please be patient - the maintainers will get to you when they can.
113+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace OathServerSuite\QrEncode\Exception;
4+
5+
/**
6+
* Class QrEncoderException
7+
*
8+
* @package OathServerSuite\QrEncode\Exception
9+
*/
10+
class QrEncoderException extends \Exception
11+
{
12+
13+
}

QrEncode/QrCode/QrCode.php

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<?php
2+
3+
namespace OathServerSuite\QrEncode\QrCode;
4+
5+
/**
6+
* Class QrCode
7+
*
8+
* @package OathServerSuite\QrEncode
9+
*/
10+
class QrCode
11+
{
12+
13+
/**
14+
* @var int
15+
*/
16+
private $width;
17+
18+
/**
19+
* @var int
20+
*/
21+
private $height;
22+
23+
/**
24+
* @var QrCodePointRow[]
25+
*/
26+
private $rows;
27+
28+
/**
29+
* QrCode constructor.
30+
*
31+
* @param int $width
32+
* @param int $height
33+
* @param array $rows
34+
*/
35+
public function __construct($width, $height, array $rows = null)
36+
{
37+
$this->width = $width;
38+
$this->height = $height;
39+
$this->rows = $rows;
40+
}
41+
42+
/**
43+
* @return int
44+
*/
45+
public function getWidth()
46+
{
47+
return $this->width;
48+
}
49+
50+
/**
51+
* @param int $width
52+
* @return $this
53+
*/
54+
public function setWidth($width)
55+
{
56+
$this->width = $width;
57+
return $this;
58+
}
59+
60+
/**
61+
* @return int
62+
*/
63+
public function getHeight()
64+
{
65+
return $this->height;
66+
}
67+
68+
/**
69+
* @param int $height
70+
* @return $this
71+
*/
72+
public function setHeight($height)
73+
{
74+
$this->height = $height;
75+
return $this;
76+
}
77+
78+
/**
79+
* @return QrCodePointRow[]
80+
*/
81+
public function getRows()
82+
{
83+
return $this->rows;
84+
}
85+
86+
/**
87+
* @param int $index
88+
* @return QrCodePointRow
89+
*/
90+
public function getRow($index)
91+
{
92+
if (!isset($this->rows[$index])) {
93+
return null;
94+
}
95+
return $this->rows[$index];
96+
}
97+
98+
/**
99+
* @param QrCodePointRow[] $rows
100+
* @return $this
101+
*/
102+
public function setRows($rows)
103+
{
104+
$this->rows = $rows;
105+
return $this;
106+
}
107+
108+
/**
109+
* @param QrCodePointRow $row
110+
* @return $this
111+
*/
112+
public function addRow(QrCodePointRow $row)
113+
{
114+
$this->rows[] = $row;
115+
return $this;
116+
}
117+
118+
/**
119+
* @param int $index
120+
* @return $this
121+
*/
122+
public function removeRow($index)
123+
{
124+
if (!isset($this->rows[$index])) {
125+
return $this;
126+
}
127+
unset($this->rows[$index]);
128+
return $this;
129+
}
130+
131+
/**
132+
* @param int $index
133+
* @param QrCodePointRow $row
134+
* @return $this
135+
*/
136+
public function replaceRow($index, QrCodePointRow $row)
137+
{
138+
if (!isset($this->rows[$index])) {
139+
return $this;
140+
}
141+
$this->rows[$index] = $row;
142+
return $this;
143+
}
144+
145+
}

QrEncode/QrCode/QrCodePoint.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace OathServerSuite\QrEncode\QrCode;
4+
5+
/**
6+
* Class QrCodePoint
7+
*
8+
* @package OathServerSuite\QrEncode
9+
*/
10+
class QrCodePoint
11+
{
12+
13+
/**
14+
* @var bool
15+
*/
16+
private $active;
17+
18+
/**
19+
* QrCodePoint constructor.
20+
*
21+
* @param $active
22+
*/
23+
public function __construct($active)
24+
{
25+
$this->active = $active;
26+
}
27+
28+
/**
29+
* @return boolean
30+
*/
31+
public function isActive()
32+
{
33+
return $this->active;
34+
}
35+
36+
/**
37+
* @param boolean $active
38+
* @return $this
39+
*/
40+
public function setActive($active)
41+
{
42+
$this->active = $active;
43+
return $this;
44+
}
45+
46+
}

0 commit comments

Comments
 (0)