From dd656b4c5399bee0f0fe95efd1fe3ce2e856b67a Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 10 Jun 2019 01:48:06 +0200 Subject: [PATCH] Improve test code (#1002) * Enhancements suggested by scrutiniser * Styling --- samples/Autofilter/10_Autofilter_selection_1.php | 12 ++++++------ samples/Autofilter/10_Autofilter_selection_2.php | 10 +++++----- .../Autofilter/10_Autofilter_selection_display.php | 12 ++++++------ src/PhpSpreadsheet/Reader/BaseReader.php | 5 +++++ src/PhpSpreadsheet/Reader/Csv.php | 2 +- src/PhpSpreadsheet/Reader/Gnumeric.php | 2 +- src/PhpSpreadsheet/Reader/Html.php | 2 +- src/PhpSpreadsheet/Reader/Ods.php | 2 +- src/PhpSpreadsheet/Reader/Slk.php | 2 +- src/PhpSpreadsheet/Reader/Xls.php | 2 +- src/PhpSpreadsheet/Reader/Xlsx.php | 2 +- src/PhpSpreadsheet/Reader/Xml.php | 2 +- 12 files changed, 30 insertions(+), 25 deletions(-) diff --git a/samples/Autofilter/10_Autofilter_selection_1.php b/samples/Autofilter/10_Autofilter_selection_1.php index 30efc194..7a88403e 100644 --- a/samples/Autofilter/10_Autofilter_selection_1.php +++ b/samples/Autofilter/10_Autofilter_selection_1.php @@ -52,25 +52,25 @@ $row = 2; foreach ($years as $year) { foreach ($periods as $period) { foreach ($countries as $country) { - $endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); + $endDays = date('t', mktime(0, 0, 0, $period, 1, (int) $year)); for ($i = 1; $i <= $endDays; ++$i) { $eDate = Date::formattedPHPToExcel( $year, $period, $i ); - $value = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $value = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); $salesValue = $invoiceValue = null; $incomeOrExpenditure = rand(-1, 1); if ($incomeOrExpenditure == -1) { - $expenditure = rand(-500, -1000) * (1 + rand(-0.25, +0.25)); + $expenditure = rand(-500, -1000) * (1 + (rand(-1, 1) / 4)); $income = null; } elseif ($incomeOrExpenditure == 1) { - $expenditure = rand(-500, -1000) * (1 + rand(-0.25, +0.25)); - $income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $expenditure = rand(-500, -1000) * (1 + (rand(-1, 1) / 4)); + $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); } else { $expenditure = null; - $income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); } $dataArray = [$year, $period, diff --git a/samples/Autofilter/10_Autofilter_selection_2.php b/samples/Autofilter/10_Autofilter_selection_2.php index 1520c972..28b069ed 100644 --- a/samples/Autofilter/10_Autofilter_selection_2.php +++ b/samples/Autofilter/10_Autofilter_selection_2.php @@ -52,25 +52,25 @@ $row = 2; foreach ($years as $year) { foreach ($periods as $period) { foreach ($countries as $country) { - $endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); + $endDays = date('t', mktime(0, 0, 0, $period, 1, (int) $year)); for ($i = 1; $i <= $endDays; ++$i) { $eDate = Date::formattedPHPToExcel( $year, $period, $i ); - $value = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $value = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); $salesValue = $invoiceValue = null; $incomeOrExpenditure = rand(-1, 1); if ($incomeOrExpenditure == -1) { - $expenditure = rand(-500, -1000) * (1 + rand(-0.25, +0.25)); + $expenditure = rand(-500, -1000) * (1 + (rand(-1, 1) / 4)); $income = null; } elseif ($incomeOrExpenditure == 1) { - $expenditure = rand(-500, -1000) * (1 + rand(-0.25, +0.25)); + $expenditure = rand(-500, -1000) * (1 + (rand(-1, 1) / 4)); $income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); } else { $expenditure = null; - $income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); } $dataArray = [$year, $period, diff --git a/samples/Autofilter/10_Autofilter_selection_display.php b/samples/Autofilter/10_Autofilter_selection_display.php index 50986bfa..faea9b22 100644 --- a/samples/Autofilter/10_Autofilter_selection_display.php +++ b/samples/Autofilter/10_Autofilter_selection_display.php @@ -52,25 +52,25 @@ $row = 2; foreach ($years as $year) { foreach ($periods as $period) { foreach ($countries as $country) { - $endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); + $endDays = date('t', mktime(0, 0, 0, $period, 1, (int) $year)); for ($i = 1; $i <= $endDays; ++$i) { $eDate = Date::formattedPHPToExcel( $year, $period, $i ); - $value = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $value = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); $salesValue = $invoiceValue = null; $incomeOrExpenditure = rand(-1, 1); if ($incomeOrExpenditure == -1) { - $expenditure = rand(-500, -1000) * (1 + rand(-0.25, +0.25)); + $expenditure = rand(-500, -1000) * (1 + (rand(-1, 1) / 4)); $income = null; } elseif ($incomeOrExpenditure == 1) { - $expenditure = rand(-500, -1000) * (1 + rand(-0.25, +0.25)); - $income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $expenditure = rand(-500, -1000) * (1 + (rand(-1, 1) / 4)); + $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); } else { $expenditure = null; - $income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); + $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4)); } $dataArray = [$year, $period, diff --git a/src/PhpSpreadsheet/Reader/BaseReader.php b/src/PhpSpreadsheet/Reader/BaseReader.php index c191c3f8..5a932cc1 100644 --- a/src/PhpSpreadsheet/Reader/BaseReader.php +++ b/src/PhpSpreadsheet/Reader/BaseReader.php @@ -55,6 +55,11 @@ abstract class BaseReader implements IReader */ protected $securityScanner; + public function __construct() + { + $this->readFilter = new DefaultReadFilter(); + } + /** * Read data only? * If this is true, then the Reader will only read data values for cells, it will not read any formatting information. diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index e10da31a..47f3d1a3 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -62,7 +62,7 @@ class Csv extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); } /** diff --git a/src/PhpSpreadsheet/Reader/Gnumeric.php b/src/PhpSpreadsheet/Reader/Gnumeric.php index 16f1925a..7445ef1b 100644 --- a/src/PhpSpreadsheet/Reader/Gnumeric.php +++ b/src/PhpSpreadsheet/Reader/Gnumeric.php @@ -36,7 +36,7 @@ class Gnumeric extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); $this->referenceHelper = ReferenceHelper::getInstance(); $this->securityScanner = XmlScanner::getInstance($this); } diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php index 6a6ca73e..2e823f03 100644 --- a/src/PhpSpreadsheet/Reader/Html.php +++ b/src/PhpSpreadsheet/Reader/Html.php @@ -128,7 +128,7 @@ class Html extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); $this->securityScanner = XmlScanner::getInstance($this); } diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index 0941f035..94ac467d 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -25,7 +25,7 @@ class Ods extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); $this->securityScanner = XmlScanner::getInstance($this); } diff --git a/src/PhpSpreadsheet/Reader/Slk.php b/src/PhpSpreadsheet/Reader/Slk.php index 61e52334..c1013c2e 100644 --- a/src/PhpSpreadsheet/Reader/Slk.php +++ b/src/PhpSpreadsheet/Reader/Slk.php @@ -43,7 +43,7 @@ class Slk extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); } /** diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index 514adae2..bd2c9c1d 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -412,7 +412,7 @@ class Xls extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); } /** diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 31f0cd70..79972e6a 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -52,7 +52,7 @@ class Xlsx extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); $this->referenceHelper = ReferenceHelper::getInstance(); $this->securityScanner = XmlScanner::getInstance($this); } diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php index 2b7959f4..8ab7a9c3 100644 --- a/src/PhpSpreadsheet/Reader/Xml.php +++ b/src/PhpSpreadsheet/Reader/Xml.php @@ -41,7 +41,7 @@ class Xml extends BaseReader */ public function __construct() { - $this->readFilter = new DefaultReadFilter(); + parent::__construct(); $this->securityScanner = XmlScanner::getInstance($this); }