Issues (1270)

lib/phpqrcode/qrtools.php (2 issues)

1
<?php
2
/*
3
 * PHP QR Code encoder
4
 *
5
 * Toolset, handy and debug utilites.
6
 *
7
 * PHP QR Code is distributed under LGPL 3
8
 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
9
 *
10
 * This library is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU Lesser General Public
12
 * License as published by the Free Software Foundation; either
13
 * version 3 of the License, or any later version.
14
 *
15
 * This library is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
 * Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public
21
 * License along with this library; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
 */
24
25
    class QRtools {
26
    
27
        //----------------------------------------------------------------------
28
        public static function binarize($frame)
29
        {
30
            $len = count($frame);
31
            foreach ($frame as &$frameLine) {
32
                
33
                for ($i = 0; $i < $len; $i++) {
34
                    $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0';
35
                }
36
            }
37
            
38
            return $frame;
39
        }
40
        
41
        //----------------------------------------------------------------------
42
        public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
0 ignored issues
show
The parameter $tcPdfVersion is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

42
        public static function tcpdfBarcodeArray($code, $mode = 'QR,L', /** @scrutinizer ignore-unused */ $tcPdfVersion = '4.5.037')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
        {
44
            $barcode_array = array();
45
            
46
            if (!is_array($mode)) {
47
                            $mode = explode(',', $mode);
48
            }
49
                
50
            $eccLevel = 'L';
51
                
52
            if (count($mode) > 1) {
53
                $eccLevel = $mode[1];
54
            }
55
                
56
            $qrTab = QRcode::text($code, false, $eccLevel);
57
            $size = count($qrTab);
58
                
59
            $barcode_array['num_rows'] = $size;
60
            $barcode_array['num_cols'] = $size;
61
            $barcode_array['bcode'] = array();
62
                
63
            foreach ($qrTab as $line) {
64
                $arrAdd = array();
65
                foreach (str_split($line) as $char) {
66
                                    $arrAdd[] = ($char == '1') ? 1 : 0;
67
                }
68
                $barcode_array['bcode'][] = $arrAdd;
69
            }
70
                    
71
            return $barcode_array;
72
        }
73
        
74
        //----------------------------------------------------------------------
75
        public static function clearCache()
76
        {
77
            self::$frames = array();
0 ignored issues
show
Bug Best Practice introduced by
The property frames does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
78
        }
79
        
80
        //----------------------------------------------------------------------
81
        public static function buildCache()
82
        {
83
            QRtools::markTime('before_build_cache');
84
			
85
            $mask = new QRmask();
86
            for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
87
                $frame = QRspec::newFrame($a);
88
                if (QR_IMAGE) {
89
                    $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
90
                    QRimage::png(self::binarize($frame), $fileName, 1, 0);
91
                }
92
				
93
                $width = count($frame);
94
                $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
95
                for ($maskNo = 0; $maskNo < 8; $maskNo++) {
96
                                    $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
97
                }
98
            }
99
			
100
            QRtools::markTime('after_build_cache');
101
        }
102
103
        //----------------------------------------------------------------------
104
        public static function log($outfile, $err)
105
        {
106
            if (QR_LOG_DIR !== false) {
107
                if ($err != '') {
108
                    if ($outfile !== false) {
109
                        file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
110
                    } else {
111
                        file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
112
                    }
113
                }    
114
            }
115
        }
116
        
117
        //----------------------------------------------------------------------
118
        public static function dumpMask($frame) 
119
        {
120
            $width = count($frame);
121
            for ($y = 0; $y < $width; $y++) {
122
                for ($x = 0; $x < $width; $x++) {
123
                    echo ord($frame[$y][$x]).',';
124
                }
125
            }
126
        }
127
        
128
        //----------------------------------------------------------------------
129
        public static function markTime($markerId)
130
        {
131
            list($usec, $sec) = explode(" ", microtime());
132
            $time = ((float) $usec + (float) $sec);
133
            
134
            if (!isset($GLOBALS['qr_time_bench'])) {
135
                            $GLOBALS['qr_time_bench'] = array();
136
            }
137
            
138
            $GLOBALS['qr_time_bench'][$markerId] = $time;
139
        }
140
        
141
        //----------------------------------------------------------------------
142
        public static function timeBenchmark()
143
        {
144
            self::markTime('finish');
145
        
146
            $lastTime = 0;
147
            $startTime = 0;
148
            $p = 0;
149
150
            echo '<table cellpadding="3" cellspacing="1">
151
                    <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
152
                    <tbody>';
153
154
            foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
155
                if ($p > 0) {
156
                    echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>';
157
                } else {
158
                    $startTime = $thisTime;
159
                }
160
                
161
                $p++;
162
                $lastTime = $thisTime;
163
            }
164
            
165
            echo '</tbody><tfoot>
166
                <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr>
167
            </tfoot>
168
            </table>';
169
        }
170
        
171
    }
172
    
173
    //##########################################################################
174
    
175
    QRtools::markTime('start');
176