QRMatrixDebugTrait.php 3.0 KB

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