QRMatrixDebugTrait.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * QRMatrixDebugTrait.php
  4. *
  5. * @created 26.11.2023
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2023 smiley
  8. * @license MIT
  9. */
  10. declare(strict_types=1);
  11. namespace chillerlan\QRCodeTest;
  12. use chillerlan\QRCode\QROptions;
  13. use chillerlan\QRCode\Data\QRMatrix;
  14. use chillerlan\QRCode\Output\QRStringText;
  15. use function defined, printf;
  16. /**
  17. * Trait QRMatrixDebugTrait
  18. */
  19. trait QRMatrixDebugTrait{
  20. /**
  21. * Matrix debugging console output
  22. */
  23. protected function debugMatrix(QRMatrix $matrix):void{
  24. /** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
  25. if(defined('TEST_IS_CI') && TEST_IS_CI === true){
  26. return;
  27. }
  28. $options = new QROptions;
  29. $options->eol = "\n";
  30. $options->moduleValues = [
  31. // finder
  32. QRMatrix::M_FINDER_DARK => QRStringText::ansi8('██', 124),
  33. QRMatrix::M_FINDER => QRStringText::ansi8('░░', 124),
  34. QRMatrix::M_FINDER_DOT => QRStringText::ansi8('██', 124),
  35. QRMatrix::M_FINDER_DOT_LIGHT => QRStringText::ansi8('░░', 124),
  36. // alignment
  37. QRMatrix::M_ALIGNMENT_DARK => QRStringText::ansi8('██', 2),
  38. QRMatrix::M_ALIGNMENT => QRStringText::ansi8('░░', 2),
  39. // timing
  40. QRMatrix::M_TIMING_DARK => QRStringText::ansi8('██', 184),
  41. QRMatrix::M_TIMING => QRStringText::ansi8('░░', 184),
  42. // format
  43. QRMatrix::M_FORMAT_DARK => QRStringText::ansi8('██', 200),
  44. QRMatrix::M_FORMAT => QRStringText::ansi8('░░', 200),
  45. // version
  46. QRMatrix::M_VERSION_DARK => QRStringText::ansi8('██', 21),
  47. QRMatrix::M_VERSION => QRStringText::ansi8('░░', 21),
  48. // data
  49. QRMatrix::M_DATA_DARK => QRStringText::ansi8('██', 166),
  50. QRMatrix::M_DATA => QRStringText::ansi8('░░', 166),
  51. // dark module
  52. QRMatrix::M_DARKMODULE => QRStringText::ansi8('██', 53),
  53. QRMatrix::M_DARKMODULE_LIGHT => QRStringText::ansi8('░░', 53),
  54. // separator
  55. QRMatrix::M_SEPARATOR_DARK => QRStringText::ansi8('██', 219),
  56. QRMatrix::M_SEPARATOR => QRStringText::ansi8('░░', 219),
  57. // quiet zone
  58. QRMatrix::M_QUIETZONE_DARK => QRStringText::ansi8('██', 195),
  59. QRMatrix::M_QUIETZONE => QRStringText::ansi8('░░', 195),
  60. // logo space
  61. QRMatrix::M_LOGO_DARK => QRStringText::ansi8('██', 105),
  62. QRMatrix::M_LOGO => QRStringText::ansi8('░░', 105),
  63. // empty
  64. QRMatrix::M_NULL => QRStringText::ansi8('░░', 231),
  65. ];
  66. $out = (new QRStringText($options, $matrix))->dump();
  67. printf("\n\n%s\n\n", $out);
  68. }
  69. /**
  70. * debugging shortcut - limit to a single version when using with matrixProvider
  71. *
  72. * @see QRMatrixTest::matrixProvider()
  73. */
  74. protected function dm(QRMatrix $matrix):void{
  75. // limit
  76. /** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
  77. if(!defined('MATRIX_DEBUG_VERSION') || $matrix->getVersion()->getVersionNumber() !== MATRIX_DEBUG_VERSION){
  78. return;
  79. }
  80. $this->debugMatrix($matrix);
  81. }
  82. }