Skip to content

Commit

Permalink
Merge branch 'chillerlan:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrospinto authored Sep 27, 2024
2 parents bc3a7e2 + 9964cf8 commit e12279a
Show file tree
Hide file tree
Showing 175 changed files with 3,232 additions and 1,469 deletions.
37 changes: 21 additions & 16 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
/.build export-ignore
/.github export-ignore
/.idea export-ignore
/.phan export-ignore
/.phpdoc export-ignore
/docs export-ignore
/examples export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.readthedocs.yml export-ignore
/phpcs.xml.dist export-ignore
/phpdoc.xml.dist export-ignore
/phpmd.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/.build export-ignore
/.github export-ignore
/.idea export-ignore
/.phan export-ignore
/.phpdoc export-ignore
/benchmark export-ignore
/docs export-ignore
/examples export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.readthedocs.yml export-ignore
/composer.lock export-ignore
/phpbench.json export-ignore
/phpcs.xml.dist export-ignore
/phpdoc.xml.dist export-ignore
/phpmd.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/phpstan.dist.neon export-ignore
/phpstan-baseline.neon export-ignore

*.php diff=php
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ jobs:
- "8.2"
- "8.3"

env:
PHAN_ALLOW_XDEBUG: 0
PHAN_DISABLE_XDEBUG_WARN: 1

steps:
- name: "Checkout"
uses: actions/checkout@v4
Expand All @@ -40,15 +36,18 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ast, ${{ env.PHP_EXTENSIONS }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: ${{ env.PHP_INI_VALUES }}
coverage: none

- name: "Install dependencies with composer"
uses: ramsey/composer-install@v3

- name: "Run phan"
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
- name: "Run PHPStan"
run: php vendor/bin/phpstan

- name: "Run PHP_CodeSniffer"
run: php vendor/bin/phpcs


tests:
Expand All @@ -65,6 +64,7 @@ jobs:
php-version:
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ phpcs.xml
phpdoc.xml
phpmd.xml
phpunit.xml
phpstan.neon
tests/Performance/*.json
60 changes: 0 additions & 60 deletions .phan/config.php

This file was deleted.

9 changes: 0 additions & 9 deletions .phan/stubs/misc.php

This file was deleted.

1 change: 1 addition & 0 deletions .phpdoc/template/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
],
"social": [
{ "iconClass": "fab fa-github", "url": "https://github.com/chillerlan/php-qrcode"},
{ "iconClass": "fas fa-envelope-open-text", "url": "https://github.com/chillerlan/php-qrcode/discussions"},
]
}
%}
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A PHP QR Code generator based on the [implementation by Kazuhiko Arase](https://github.com/kazuhikoarase/qrcode-generator), namespaced, cleaned up, improved and other stuff. <br>
It also features a QR Code reader based on a [PHP port](https://github.com/khanamiryan/php-qrcode-detector-decoder) of the [ZXing library](https://github.com/zxing/zxing).

**Attention:** there is now also a javascript port: [chillerlan/js-qrcode](https://github.com/chillerlan/js-qrcode).
**Attention:** there is now also a javascript port on NPM: [@chillerlan/qrcode](https://www.npmjs.com/package/@chillerlan/qrcode).

[![PHP Version Support][php-badge]][php]
[![Packagist version][packagist-badge]][packagist]
Expand Down Expand Up @@ -57,12 +57,13 @@ It also features a QR Code reader based on a [PHP port](https://github.com/khana
- PHP 8.2+
- [`ext-mbstring`](https://www.php.net/manual/book.mbstring.php)
- optional:
- [`ext-gd`](https://www.php.net/manual/book.image)
- [`ext-gd`](https://www.php.net/manual/book.image) for `QRGdImage` based output
- [`ext-imagick`](https://github.com/Imagick/imagick) with [ImageMagick](https://imagemagick.org) installed
- [`ext-fileinfo`](https://www.php.net/manual/book.fileinfo.php) (required by `QRImagick` output)
- [`ext-fileinfo`](https://www.php.net/manual/book.fileinfo.php) required by `QRImagick` output
- [`setasign/fpdf`](https://github.com/setasign/fpdf) for the PDF output module
- [`intervention/image`](https://github.com/Intervention/image) for alternative GD/ImageMagick output

For the QRCode reader, either `ext-gd` or `ext-imagick` is required!
For the QR Code reader, either `ext-gd` or `ext-imagick` is required!


# Documentation
Expand Down
9 changes: 8 additions & 1 deletion benchmark/BenchmarkAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ abstract class BenchmarkAbstract{
protected const ECC_LEVELS = [EccLevel::L, EccLevel::M, EccLevel::Q, EccLevel::H];
protected const DATAMODES = Mode::INTERFACES;

/** @var array<int, string> */
protected array $dataModeData;
protected string $testData;
protected QROptions $options;
Expand All @@ -45,7 +46,7 @@ abstract class BenchmarkAbstract{
protected string $modeFQCN;

/**
*
* @throws \RuntimeException
*/
public function __construct(){

Expand All @@ -64,6 +65,8 @@ public function __construct(){

/**
* Generates test data strings for each mode
*
* @return array<int, string>
*/
protected function generateDataModeData():array{
return [
Expand All @@ -90,6 +93,8 @@ protected function getData(Version $version, EccLevel $eccLevel, int $mode):stri

/**
* Initializes a QROptions instance and assigns it to its temp property
*
* @param array<string, mixed> $options
*/
protected function initQROptions(array $options):void{
$this->options = new QROptions($options);
Expand All @@ -114,6 +119,8 @@ public function generateTestData():void{

/**
* Assigns the parameter array from the providers to properties and enforces the types
*
* @param array<string, mixed> $params
*/
public function assignParams(array $params):void{
foreach($params as $k => $v){
Expand Down
15 changes: 10 additions & 5 deletions benchmark/OutputBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use chillerlan\QRCode\Common\Mode;
use chillerlan\QRCode\Data\Byte;
use chillerlan\QRCode\Output\{
QREps, QRFpdf, QRGdImageAVIF, QRGdImageJPEG, QRGdImagePNG, QRGdImageWEBP, QRImagick, QRMarkupSVG, QRStringJSON
QREps, QRFpdf, QRGdImageJPEG, QRGdImagePNG, QRGdImageWEBP, QRImagick, QRMarkupSVG, QRMarkupXML, QRStringJSON
};
use PhpBench\Attributes\{BeforeMethods, Subject};

Expand Down Expand Up @@ -53,10 +53,10 @@ public function QRFpdf():void{
/**
* for some reason imageavif() is extremely slow, ~50x slower than imagepng()
*/
#[Subject]
public function QRGdImageAVIF():void{
(new QRGdImageAVIF($this->options, $this->matrix))->dump();
}
# #[Subject]
# public function QRGdImageAVIF():void{
# (new \chillerlan\QRCode\Output\QRGdImageAVIF($this->options, $this->matrix))->dump();
# }

#[Subject]
public function QRGdImageJPEG():void{
Expand All @@ -83,6 +83,11 @@ public function QRMarkupSVG():void{
(new QRMarkupSVG($this->options, $this->matrix))->dump();
}

#[Subject]
public function QRMarkupXML():void{
(new QRMarkupXML($this->options, $this->matrix))->dump();
}

#[Subject]
public function QRStringJSON():void{
(new QRStringJSON($this->options, $this->matrix))->dump();
Expand Down
6 changes: 2 additions & 4 deletions benchmark/QRCodeBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace chillerlan\QRCodeBenchmark;

use chillerlan\QRCode\Output\QRStringJSON;
use chillerlan\QRCode\QRCode;
use PhpBench\Attributes\{BeforeMethods, Subject};

Expand All @@ -23,9 +22,8 @@ final class QRCodeBenchmark extends BenchmarkAbstract{
public function initOptions():void{

$options = [
'outputInterface' => QRStringJSON::class,
'version' => $this->version->getVersionNumber(),
'eccLevel' => $this->eccLevel->getLevel(),
'version' => $this->version->getVersionNumber(),
'eccLevel' => $this->eccLevel->getLevel(),
];

$this->initQROptions($options);
Expand Down
1 change: 0 additions & 1 deletion benchmark/QRDataBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function initBitBuffer():void{
#[Subject]
#[BeforeMethods(['assignParams', 'generateTestData', 'initOptions'])]
public function invocation():void{
/** @phan-suppress-next-line PhanNoopNew */
new QRData($this->options, [new $this->modeFQCN($this->testData)]);
}

Expand Down
19 changes: 14 additions & 5 deletions benchmark/generate-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*
* @phan-file-suppress PhanTypeArraySuspiciousNullable
*/
declare(strict_types=1);

Expand All @@ -30,10 +28,16 @@
require_once __DIR__.'/parse-common.php';

if(!file_exists(FILE.'.json')){
throw new RuntimeException('invalid benchmark report');
throw new RuntimeException('invalid benchmark report [file_exists()]');
}

$data = file_get_contents(FILE.'.json');

if($data === false){
throw new RuntimeException('invalid benchmark report [file_get_contents()]');
}

$json = json_decode(file_get_contents(FILE.'.json'), true);
$json = json_decode($data, true);

$htmlHead = '<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -63,7 +67,12 @@
$html['index'][] = '</thead><tbody>';

$html['index'][] = sprintf('<tr><td>date</td><td style="text-align: left;">%s %s</td></tr>', $suite['date'], $suite['time']);
$html['index'][] = sprintf('<tr><td>environment</td><td style="text-align: left;">%s %s, %s</td></tr>', $env['uname_os'], $env['uname_version'], $env['uname_machine']);
$html['index'][] = sprintf(
'<tr><td>environment</td><td style="text-align: left;">%s %s, %s</td></tr>',
$env['uname_os'],
$env['uname_version'],
$env['uname_machine'],
);
$html['index'][] = sprintf('<tr><td>tag</td><td style="text-align: left;">%s</td></tr>', htmlspecialchars($suite['tag']));

foreach(['php_version', 'php_ini', 'php_extensions', 'php_xdebug', 'opcache_extension_loaded', 'opcache_enabled'] as $field){
Expand Down
12 changes: 8 additions & 4 deletions benchmark/generate-markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @author smiley <smiley@chillerlan.net>
* @copyright 2024 smiley
* @license MIT
*
* @phan-file-suppress PhanTypeArraySuspiciousNullable
*/
declare(strict_types=1);

Expand All @@ -30,10 +28,16 @@
require_once __DIR__.'/parse-common.php';

if(!file_exists(FILE.'.json')){
throw new RuntimeException('invalid benchmark report');
throw new RuntimeException('invalid benchmark report [file_exists()]');
}

$data = file_get_contents(FILE.'.json');

if($data === false){
throw new RuntimeException('invalid benchmark report [file_get_contents()]');
}

$json = json_decode(file_get_contents(FILE.'.json'), true);
$json = json_decode($data, true);
$markdown = [];

// General information/overview
Expand Down
8 changes: 8 additions & 0 deletions benchmark/parse-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
const BUILDDIR = __DIR__.'/../.build/phpbench';
const FILE = BUILDDIR.'/benchmark'; // without extension

/**
* @param array<int, array<int, mixed>> $variants
*/
function parseVariants(array $variants):string{
$data = [];

Expand Down Expand Up @@ -65,6 +68,11 @@ function parseVariants(array $variants):string{
return implode("\n", $table);
}

/**
* @param array<int, array<int, mixed>> $results
*
* @return array{0: float, 1: int}
*/
function parseVariantResults(array $results):array{
$iterations = count($results);
$mem_peak = array_column($results, 'mem_peak');
Expand Down
Loading

0 comments on commit e12279a

Please sign in to comment.