1 | <?php |
||
2 | |||
3 | require __DIR__ . '/vendor/autoload.php'; |
||
4 | |||
5 | use Zhaqq\Xlsx\Writer\Builder; |
||
6 | |||
7 | date_default_timezone_set('PRC'); |
||
8 | $start = microtime(true); |
||
9 | times($start); |
||
10 | |||
11 | try { |
||
12 | $writer = new Builder(); |
||
13 | $fileName = __DIR__ . '/data/xlsx_writer' . date('Ymd-His') . '.xlsx'; |
||
14 | $writer->buildHeader('sheet_name_1', [ |
||
15 | 'title' => 'string', |
||
16 | 'content' => 'string', |
||
17 | 'weight' => 'number', |
||
18 | ]); |
||
19 | $writer->buildHeader('sheet_name_2', [ |
||
20 | 'title' => 'string', |
||
21 | 'content' => 'string', |
||
22 | 'price' => 'price', |
||
23 | ]); |
||
24 | |||
25 | foreach (rows(250000) as $row) { |
||
0 ignored issues
–
show
|
|||
26 | $writer->writeSheetRow($row[0], $row[1]); |
||
27 | } |
||
28 | times($start); |
||
29 | |||
30 | $writer->writeToFile($fileName); |
||
31 | times($start); |
||
32 | |||
33 | } catch (\Exception $exception) { |
||
34 | var_dump($exception->getMessage()); |
||
35 | } |
||
36 | |||
37 | function rows($n = 10) |
||
38 | { |
||
39 | for ($i = 0; $i < $n; $i++) { |
||
40 | if ($i % 2) { |
||
41 | yield ['sheet_name_1', [ |
||
42 | 'title' . $i, |
||
43 | 'content' . $i, |
||
44 | $i+$i, |
||
45 | ]]; |
||
46 | } else { |
||
47 | yield ['sheet_name_2', [ |
||
48 | 'title' . $i, |
||
49 | 'content' . $i, |
||
50 | $i+$i, |
||
51 | ]]; |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | function times($start, $object = 'XlsxWriter') |
||
57 | { |
||
58 | echo $object, PHP_EOL; |
||
59 | echo microtime(true) - $start, PHP_EOL; |
||
60 | echo '#', floor((memory_get_peak_usage(true)) / 1024 / 1024), "MB", PHP_EOL; |
||
61 | echo '#', floor((memory_get_usage(true)) / 1024 / 1024), "MB", PHP_EOL, PHP_EOL; |
||
62 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.