Skip to content

Commit

Permalink
[MagicNumber] Use constant to store the default QR size
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 committed Jul 4, 2021
1 parent 3d5592f commit 3dcea02
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions QRCode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* @desc Compatible to vCard 4.0 or higher.
*
* @author Pierre-Henry Soria <ph7software@gmail.com>
* @copyright (c) 2012-2018, Pierre-Henry Soria. All Rights Reserved.
* @copyright (c) 2012-2021, Pierre-Henry Soria. All Rights Reserved.
* @license GNU General Public License <http://www.gnu.org/licenses/gpl.html>
* @version 1.2
*/

class QRCode
{
const API_URL = 'https://chart.googleapis.com/chart?chs=';
const DEFAULT_QR_SIZE = 150;

private $sData;

Expand Down Expand Up @@ -273,7 +274,7 @@ public function bookmark($sTitle, $sUrl)
*
* @param string $sLat Latitude
* @param string $sLon Longitude
* @param integer $iHeight Height
* @param int $iHeight Height
*
* @return self
*/
Expand Down Expand Up @@ -324,24 +325,24 @@ public function finish()
/**
* Get the URL of QR Code.
*
* @param integer $iSize Default 150
* @param int $iSize Default 150
* @param string $sECLevel Default L
* @param integer $iMargin Default 1
*
* @return string The API URL configure.
*/
public function get($iSize = 150, $sECLevel = 'L', $iMargin = 1)
public function get($iSize = self::DEFAULT_QR_SIZE, $sECLevel = 'L', $iMargin = 1)
{
return self::API_URL . $iSize . 'x' . $iSize . '&cht=qr&chld=' . $sECLevel . '|' . $iMargin . '&chl=' . $this->sData;
}

/**
* The HTML code for displaying the QR Code.
*
* @param integer $iSize Default 150
* @param int $iSize Default 150
* @return void
*/
public function display( $iSize = 150)
public function display($iSize = self::DEFAULT_QR_SIZE)
{
echo '<p class="center"><img src="' . $this->_cleanUrl($this->get($iSize)) . '" alt="QR Code" /></p>';
}
Expand Down

0 comments on commit 3dcea02

Please sign in to comment.