QrCode   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 21 4
A initQrcodeStyle() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the docodeit/wechat.
5
 *
6
 * (c) docodeit <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace JinWeChat\Kernel\Console;
13
14
use PHPQRCode\QRcode as QrCodeConsole;
15
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
16
use Symfony\Component\Console\Output\ConsoleOutput;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class QrCode extends Console
20
{
21
    /**
22
     * show qrCode on console.
23
     *
24
     * @param $text
25
     */
26 1
    public function show($text)
27
    {
28 1
        $output = new ConsoleOutput();
29 1
        static::initQrcodeStyle($output);
30
31 1
        $pxMap[0] = Console::isWin() ? '<whitec>mm</whitec>' : '<whitec>  </whitec>';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$pxMap was never initialized. Although not strictly required by PHP, it is generally a good practice to add $pxMap = array(); before regardless.
Loading history...
32
//        $pxMap[0] = true ? '<whitec>mm</whitec>' : '<whitec>  </whitec>';
33 1
        $pxMap[1] = '<blackc>  </blackc>';
34
35 1
        $text = QrCodeConsole::text($text);
36
37 1
        $length = strlen($text[0]);
38
39 1
        $output->write("\n");
40 1
        foreach ($text as $line) {
41 1
            $output->write($pxMap[0]);
42 1
            for ($i = 0; $i < $length; ++$i) {
43 1
                $type = substr($line, $i, 1);
44 1
                $output->write($pxMap[$type]);
45
            }
46 1
            $output->writeln($pxMap[0]);
47
        }
48 1
    }
49
50
    /**
51
     * init qrCode style.
52
     *
53
     * @param OutputInterface $output
54
     */
55 1
    private static function initQrcodeStyle(OutputInterface $output)
56
    {
57 1
        $style = new OutputFormatterStyle('black', 'black', ['bold']);
58 1
        $output->getFormatter()->setStyle('blackc', $style);
59 1
        $style = new OutputFormatterStyle('white', 'white', ['bold']);
60 1
        $output->getFormatter()->setStyle('whitec', $style);
61 1
    }
62
}
63