From ee700f7c7d03f463fa14eac43e7c5f03f7b17163 Mon Sep 17 00:00:00 2001 From: mosa Date: Thu, 19 Oct 2017 11:07:31 +0900 Subject: [PATCH] change array_push() to $array[] (#254) http://php.net/manual/en/function.array-push.php#refsect1-function.array-push-description > Note: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function. --- docs/topics/recipes.md | 4 ++-- samples/Basic/08_Conditional_formatting.php | 6 +++--- samples/Basic/08_Conditional_formatting_2.php | 4 ++-- tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/topics/recipes.md b/docs/topics/recipes.md index e094e2c5..6a8bf44a 100644 --- a/docs/topics/recipes.md +++ b/docs/topics/recipes.md @@ -856,8 +856,8 @@ $conditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsh $conditional2->getStyle()->getFont()->setBold(true); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles(); -array_push($conditionalStyles, $conditional1); -array_push($conditionalStyles, $conditional2); +$conditionalStyles[] = $conditional1; +$conditionalStyles[] = $conditional2; $spreadsheet->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles); ``` diff --git a/samples/Basic/08_Conditional_formatting.php b/samples/Basic/08_Conditional_formatting.php index e73fa3f6..398e9c17 100644 --- a/samples/Basic/08_Conditional_formatting.php +++ b/samples/Basic/08_Conditional_formatting.php @@ -79,9 +79,9 @@ $conditional3->getStyle()->getFont()->setItalic(true); $conditional3->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles(); -array_push($conditionalStyles, $conditional1); -array_push($conditionalStyles, $conditional2); -array_push($conditionalStyles, $conditional3); +$conditionalStyles[] = $conditional1; +$conditionalStyles[] = $conditional2; +$conditionalStyles[] = $conditional3; $spreadsheet->getActiveSheet()->getStyle('B2')->setConditionalStyles($conditionalStyles); // duplicate the conditional styles across a range of cells diff --git a/samples/Basic/08_Conditional_formatting_2.php b/samples/Basic/08_Conditional_formatting_2.php index 0bf4a30c..27e8fd02 100644 --- a/samples/Basic/08_Conditional_formatting_2.php +++ b/samples/Basic/08_Conditional_formatting_2.php @@ -55,8 +55,8 @@ $conditional3->setConditionType(Conditional::CONDITION_CELLIS) $conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1')->getConditionalStyles(); -array_push($conditionalStyles, $conditional1); -array_push($conditionalStyles, $conditional3); +$conditionalStyles[] = $conditional1; +$conditionalStyles[] = $conditional3; $spreadsheet->getActiveSheet()->getStyle('A1')->setConditionalStyles($conditionalStyles); // duplicate the conditional styles across a range of cells diff --git a/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php b/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php index 0fd9dbad..f83c54b6 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php @@ -86,7 +86,7 @@ class WorkbookTest extends PHPUnit_Framework_TestCase // Add new color after all existing color $colorsAddTwo = array_map([$this, 'paletteToColor'], $palette); - array_push($colorsAddTwo, $this->paletteToColor($newColor1)); + $colorsAddTwo[] = $this->paletteToColor($newColor1); $paletteTestSix = $palette; // Add one existing color