Improve test code (#1002)

* Enhancements suggested by scrutiniser

* Styling
This commit is contained in:
Mark Baker 2019-06-10 01:48:06 +02:00 committed by GitHub
parent d6018a273e
commit dd656b4c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 30 additions and 25 deletions

View File

@ -52,25 +52,25 @@ $row = 2;
foreach ($years as $year) { foreach ($years as $year) {
foreach ($periods as $period) { foreach ($periods as $period) {
foreach ($countries as $country) { 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) { for ($i = 1; $i <= $endDays; ++$i) {
$eDate = Date::formattedPHPToExcel( $eDate = Date::formattedPHPToExcel(
$year, $year,
$period, $period,
$i $i
); );
$value = rand(500, 1000) * (1 + rand(-0.25, +0.25)); $value = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
$salesValue = $invoiceValue = null; $salesValue = $invoiceValue = null;
$incomeOrExpenditure = rand(-1, 1); $incomeOrExpenditure = rand(-1, 1);
if ($incomeOrExpenditure == -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; $income = null;
} elseif ($incomeOrExpenditure == 1) { } 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)); $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
} else { } else {
$expenditure = null; $expenditure = null;
$income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
} }
$dataArray = [$year, $dataArray = [$year,
$period, $period,

View File

@ -52,25 +52,25 @@ $row = 2;
foreach ($years as $year) { foreach ($years as $year) {
foreach ($periods as $period) { foreach ($periods as $period) {
foreach ($countries as $country) { 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) { for ($i = 1; $i <= $endDays; ++$i) {
$eDate = Date::formattedPHPToExcel( $eDate = Date::formattedPHPToExcel(
$year, $year,
$period, $period,
$i $i
); );
$value = rand(500, 1000) * (1 + rand(-0.25, +0.25)); $value = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
$salesValue = $invoiceValue = null; $salesValue = $invoiceValue = null;
$incomeOrExpenditure = rand(-1, 1); $incomeOrExpenditure = rand(-1, 1);
if ($incomeOrExpenditure == -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; $income = null;
} elseif ($incomeOrExpenditure == 1) { } 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)); $income = rand(500, 1000) * (1 + rand(-0.25, +0.25));
} else { } else {
$expenditure = null; $expenditure = null;
$income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
} }
$dataArray = [$year, $dataArray = [$year,
$period, $period,

View File

@ -52,25 +52,25 @@ $row = 2;
foreach ($years as $year) { foreach ($years as $year) {
foreach ($periods as $period) { foreach ($periods as $period) {
foreach ($countries as $country) { 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) { for ($i = 1; $i <= $endDays; ++$i) {
$eDate = Date::formattedPHPToExcel( $eDate = Date::formattedPHPToExcel(
$year, $year,
$period, $period,
$i $i
); );
$value = rand(500, 1000) * (1 + rand(-0.25, +0.25)); $value = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
$salesValue = $invoiceValue = null; $salesValue = $invoiceValue = null;
$incomeOrExpenditure = rand(-1, 1); $incomeOrExpenditure = rand(-1, 1);
if ($incomeOrExpenditure == -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; $income = null;
} elseif ($incomeOrExpenditure == 1) { } 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)); $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
} else { } else {
$expenditure = null; $expenditure = null;
$income = rand(500, 1000) * (1 + rand(-0.25, +0.25)); $income = rand(500, 1000) * (1 + (rand(-1, 1) / 4));
} }
$dataArray = [$year, $dataArray = [$year,
$period, $period,

View File

@ -55,6 +55,11 @@ abstract class BaseReader implements IReader
*/ */
protected $securityScanner; protected $securityScanner;
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
}
/** /**
* Read data only? * Read data only?
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information. * If this is true, then the Reader will only read data values for cells, it will not read any formatting information.

View File

@ -62,7 +62,7 @@ class Csv extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
} }
/** /**

View File

@ -36,7 +36,7 @@ class Gnumeric extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
$this->referenceHelper = ReferenceHelper::getInstance(); $this->referenceHelper = ReferenceHelper::getInstance();
$this->securityScanner = XmlScanner::getInstance($this); $this->securityScanner = XmlScanner::getInstance($this);
} }

View File

@ -128,7 +128,7 @@ class Html extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
$this->securityScanner = XmlScanner::getInstance($this); $this->securityScanner = XmlScanner::getInstance($this);
} }

View File

@ -25,7 +25,7 @@ class Ods extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
$this->securityScanner = XmlScanner::getInstance($this); $this->securityScanner = XmlScanner::getInstance($this);
} }

View File

@ -43,7 +43,7 @@ class Slk extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
} }
/** /**

View File

@ -412,7 +412,7 @@ class Xls extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
} }
/** /**

View File

@ -52,7 +52,7 @@ class Xlsx extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
$this->referenceHelper = ReferenceHelper::getInstance(); $this->referenceHelper = ReferenceHelper::getInstance();
$this->securityScanner = XmlScanner::getInstance($this); $this->securityScanner = XmlScanner::getInstance($this);
} }

View File

@ -41,7 +41,7 @@ class Xml extends BaseReader
*/ */
public function __construct() public function __construct()
{ {
$this->readFilter = new DefaultReadFilter(); parent::__construct();
$this->securityScanner = XmlScanner::getInstance($this); $this->securityScanner = XmlScanner::getInstance($this);
} }