Skip to content

Commit

Permalink
Improve test code (PHPOffice#1002)
Browse files Browse the repository at this point in the history
* Enhancements suggested by scrutiniser

* Styling
  • Loading branch information
Mark Baker authored Jun 9, 2019
1 parent d6018a2 commit dd656b4
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 25 deletions.
12 changes: 6 additions & 6 deletions samples/Autofilter/10_Autofilter_selection_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@
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,
Expand Down
10 changes: 5 additions & 5 deletions samples/Autofilter/10_Autofilter_selection_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@
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,
Expand Down
12 changes: 6 additions & 6 deletions samples/Autofilter/10_Autofilter_selection_display.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@
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,
Expand Down
5 changes: 5 additions & 0 deletions src/PhpSpreadsheet/Reader/BaseReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Csv extends BaseReader
*/
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
parent::__construct();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Gnumeric.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Html extends BaseReader
*/
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
parent::__construct();
$this->securityScanner = XmlScanner::getInstance($this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Ods.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Ods extends BaseReader
*/
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
parent::__construct();
$this->securityScanner = XmlScanner::getInstance($this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Slk.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Slk extends BaseReader
*/
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
parent::__construct();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xls.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class Xls extends BaseReader
*/
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
parent::__construct();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Xml extends BaseReader
*/
public function __construct()
{
$this->readFilter = new DefaultReadFilter();
parent::__construct();
$this->securityScanner = XmlScanner::getInstance($this);
}

Expand Down

0 comments on commit dd656b4

Please sign in to comment.