From 49d821f093d5037f7828ee82288f4b38999103ac Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sat, 13 Aug 2016 23:31:22 +0900 Subject: [PATCH 1/4] Autofix style code with phpcs The entire project now pass phpcs check --- src/PhpSpreadsheet/Calculation/TextData.php | 1 - src/PhpSpreadsheet/Document/Properties.php | 2 -- src/PhpSpreadsheet/Reader/Excel5.php | 3 --- src/PhpSpreadsheet/Shared/Date.php | 19 +++++++++++-------- .../JAMA/SingularValueDecomposition.php | 1 - src/PhpSpreadsheet/Spreadsheet.php | 1 - .../Writer/Excel2007/RelsVBA.php | 1 - src/PhpSpreadsheet/Writer/Excel5/Workbook.php | 1 - src/PhpSpreadsheet/Writer/Excel5/Xf.php | 1 - .../src/Cell/DefaultValueBinderTest.php | 1 - unitTests/Classes/src/Shared/TimeZoneTest.php | 1 - unitTests/classes/src/SettingsTest.php | 1 - 12 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/PhpSpreadsheet/Calculation/TextData.php b/src/PhpSpreadsheet/Calculation/TextData.php index 6c625193..b03f3949 100644 --- a/src/PhpSpreadsheet/Calculation/TextData.php +++ b/src/PhpSpreadsheet/Calculation/TextData.php @@ -215,7 +215,6 @@ class TextData } return \PHPExcel\Style\NumberFormat::toFormattedString($value, $mask); - } diff --git a/src/PhpSpreadsheet/Document/Properties.php b/src/PhpSpreadsheet/Document/Properties.php index a5dfc47e..a171069f 100644 --- a/src/PhpSpreadsheet/Document/Properties.php +++ b/src/PhpSpreadsheet/Document/Properties.php @@ -427,7 +427,6 @@ class Properties if (isset($this->customProperties[$propertyName])) { return $this->customProperties[$propertyName]['value']; } - } /** @@ -441,7 +440,6 @@ class Properties if (isset($this->customProperties[$propertyName])) { return $this->customProperties[$propertyName]['type']; } - } /** diff --git a/src/PhpSpreadsheet/Reader/Excel5.php b/src/PhpSpreadsheet/Reader/Excel5.php index 8bda02ef..acde227e 100644 --- a/src/PhpSpreadsheet/Reader/Excel5.php +++ b/src/PhpSpreadsheet/Reader/Excel5.php @@ -1628,7 +1628,6 @@ class Excel5 extends BaseReader implements IReader // ->setAuthor($author) } } - } @@ -2503,7 +2502,6 @@ class Excel5 extends BaseReader implements IReader $offset += $cb; } } - } @@ -5258,7 +5256,6 @@ class Excel5 extends BaseReader implements IReader ); return $splicedData; - } diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php index 7e3eb32a..cc4d7224 100644 --- a/src/PhpSpreadsheet/Shared/Date.php +++ b/src/PhpSpreadsheet/Shared/Date.php @@ -112,7 +112,8 @@ class Date * @return \DateTimeZone The timezone as a timezone object * @throws \Exception */ - protected static function validateTimeZone($timeZone) { + protected static function validateTimeZone($timeZone) + { if (is_object($timeZone) && $timeZone instanceof \DateTimeZone) { return $timeZone; } elseif (is_string($timeZone)) { @@ -130,14 +131,15 @@ class Date * @return \DateTime PHP date/time object * @throws \Exception */ - public static function excelToDateTimeObject($excelTimestamp = 0, $timeZone = null) { + public static function excelToDateTimeObject($excelTimestamp = 0, $timeZone = null) + { $timeZone = ($timeZone === null) ? self::getDefaultTimezone() : self::validateTimeZone($timeZone); if (self::$excelCalendar == self::CALENDAR_WINDOWS_1900) { $baseDate = ($excelTimestamp < 60) ? new \DateTime('1899-12-31', $timeZone) : new \DateTime('1899-12-30', $timeZone); } else { $baseDate = new \DateTime('1904-01-01', $timeZone); } - $days = floor($excelTimestamp); + $days = floor($excelTimestamp); $partDay = $excelTimestamp - $days; $hours = floor($partDay * 24); $partDay = $partDay * 24 - $hours; @@ -147,9 +149,9 @@ class Date // $fraction = $partDay - $seconds; $interval = '+' . $days . ' days'; - return $baseDate->modify($interval) + return $baseDate->modify($interval) ->setTime($hours, $minutes, $seconds); - } + } /** * Convert a MS serialized datetime value from Excel to a unix timestamp @@ -158,10 +160,11 @@ class Date * @return integer Unix timetamp for this date/time * @throws \Exception */ - public static function excelToTimestamp($excelTimestamp = 0, $timeZone = null) { - return self::excelToDateTimeObject($excelTimestamp, $timeZone) + public static function excelToTimestamp($excelTimestamp = 0, $timeZone = null) + { + return self::excelToDateTimeObject($excelTimestamp, $timeZone) ->format('U'); - } + } /** diff --git a/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php index b25a7708..9daa4d97 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/SingularValueDecomposition.php @@ -428,7 +428,6 @@ class SingularValueDecomposition break; } // end switch } // end while - } // end constructor diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index c2efc9f0..7d8a06a8 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -563,7 +563,6 @@ class Spreadsheet ($pIndex > count($this->workSheetCollection) - 1)) { --$this->activeSheetIndex; } - } /** diff --git a/src/PhpSpreadsheet/Writer/Excel2007/RelsVBA.php b/src/PhpSpreadsheet/Writer/Excel2007/RelsVBA.php index b4854a6c..a0fa1487 100644 --- a/src/PhpSpreadsheet/Writer/Excel2007/RelsVBA.php +++ b/src/PhpSpreadsheet/Writer/Excel2007/RelsVBA.php @@ -59,6 +59,5 @@ class RelsVBA extends WriterPart $objWriter->endElement(); return $objWriter->getData(); - } } diff --git a/src/PhpSpreadsheet/Writer/Excel5/Workbook.php b/src/PhpSpreadsheet/Writer/Excel5/Workbook.php index c8bedfe0..53db80c0 100644 --- a/src/PhpSpreadsheet/Writer/Excel5/Workbook.php +++ b/src/PhpSpreadsheet/Writer/Excel5/Workbook.php @@ -232,7 +232,6 @@ class Workbook extends BIFFwriter $this->addColor($phpSheet->getTabColor()->getRGB()); } } - } /** diff --git a/src/PhpSpreadsheet/Writer/Excel5/Xf.php b/src/PhpSpreadsheet/Writer/Excel5/Xf.php index 5987ecee..5eb42866 100644 --- a/src/PhpSpreadsheet/Writer/Excel5/Xf.php +++ b/src/PhpSpreadsheet/Writer/Excel5/Xf.php @@ -151,7 +151,6 @@ class Xf $this->rightBorderColor = 0x40; $this->_diag_color = 0x40; $this->_style = $style; - } diff --git a/unitTests/Classes/src/Cell/DefaultValueBinderTest.php b/unitTests/Classes/src/Cell/DefaultValueBinderTest.php index 4f219c40..ef4dc71d 100644 --- a/unitTests/Classes/src/Cell/DefaultValueBinderTest.php +++ b/unitTests/Classes/src/Cell/DefaultValueBinderTest.php @@ -26,7 +26,6 @@ class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase $this->cellStub->expects($this->any()) ->method('setValueExplicit') ->will($this->returnValue(true)); - } /** diff --git a/unitTests/Classes/src/Shared/TimeZoneTest.php b/unitTests/Classes/src/Shared/TimeZoneTest.php index a074abe2..9d7fe7bb 100644 --- a/unitTests/Classes/src/Shared/TimeZoneTest.php +++ b/unitTests/Classes/src/Shared/TimeZoneTest.php @@ -18,7 +18,6 @@ class TimeZoneTest extends \PHPUnit_Framework_TestCase $result = call_user_func(array('\PHPExcel\Shared\TimeZone','setTimezone'), $timezoneValue); $this->assertTrue($result); } - } public function testSetTimezoneWithInvalidValue() diff --git a/unitTests/classes/src/SettingsTest.php b/unitTests/classes/src/SettingsTest.php index b2953f18..06161c47 100644 --- a/unitTests/classes/src/SettingsTest.php +++ b/unitTests/classes/src/SettingsTest.php @@ -25,5 +25,4 @@ class SettingsTest extends \PHPUnit_Framework_TestCase $result = call_user_func(array('PHPExcel\\Settings','getLibXmlLoaderOptions')); $this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result)); } - } From a1f8551ccbd9800ecbde42539628ec4f5f680dc7 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sat, 13 Aug 2016 23:40:31 +0900 Subject: [PATCH 2/4] PHP 5.5 is the new minimum requirement This is a decision annouced by @MarkBaker in Gitter to be able to use `DateTimeInterface`. Also remove deprecated composer option, and introduce caching for faster CI tests --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 02661f24..ebefda75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,29 @@ language: php php: - - 5.4 - 5.5 - 5.6 - 7.0 - hhvm - + matrix: allow_failures: - php: hhvm +cache: + directories: + - vendor + - $HOME/.composer/cache + before_script: ## Packages - sudo apt-get -qq update > /dev/null ## Composer - composer self-update - - composer install --prefer-source --dev - - phpenv global "$TRAVIS_PHP_VERSION" + - composer install script: ## PHP_CodeSniffer - ./vendor/bin/phpcs --report-width=200 --report-summary --report-full src/ unitTests/ --standard=PSR2 -n ## PHPUnit - ./vendor/bin/phpunit -c ./unitTests/ - -notifications: - email: false From 3cf1bd9a7c65cde87304a57a5e9c18925a97d1f2 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sat, 13 Aug 2016 23:45:37 +0900 Subject: [PATCH 3/4] Add PHP 7.1 to Travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index ebefda75..68dcb08c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,12 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm matrix: allow_failures: + - php: 7.1 - php: hhvm cache: From 80af21d9628730159c5b745cd8d5bd8f259d8cb4 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 14 Aug 2016 00:31:09 +0900 Subject: [PATCH 4/4] Fix unit tests for date Unit tests were broken in commit 745499cc55e9f2dbeba3045b7457e7a240a6f134 --- src/PhpSpreadsheet/Shared/Date.php | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php index cc4d7224..06afeb8b 100644 --- a/src/PhpSpreadsheet/Shared/Date.php +++ b/src/PhpSpreadsheet/Shared/Date.php @@ -33,6 +33,39 @@ class Date const CALENDAR_WINDOWS_1900 = 1900; // Base date of 1st Jan 1900 = 1.0 const CALENDAR_MAC_1904 = 1904; // Base date of 2nd Jan 1904 = 1.0 + /* + * Names of the months of the year, indexed by shortname + * Planned usage for locale settings + * + * @public + * @var string[] + */ + public static $monthNames = [ + 'Jan' => 'January', + 'Feb' => 'February', + 'Mar' => 'March', + 'Apr' => 'April', + 'May' => 'May', + 'Jun' => 'June', + 'Jul' => 'July', + 'Aug' => 'August', + 'Sep' => 'September', + 'Oct' => 'October', + 'Nov' => 'November', + 'Dec' => 'December', + ]; + + /* + * @public + * @var string[] + */ + public static $numberSuffixes = [ + 'st', + 'nd', + 'rd', + 'th', + ]; + /* * Base calendar year to use for calculations * Value is either CALENDAR_WINDOWS_1900 (1900) or CALENDAR_MAC_1904 (1904)