More PSR-2 goodness.... getting there slowly

This commit is contained in:
MarkBaker 2015-05-13 00:40:55 +01:00
parent a86cbaa230
commit f7296f58b4
5 changed files with 4118 additions and 4141 deletions

View File

@ -3949,4 +3949,3 @@ class PHPExcel_Calculation {
} // function listFunctionNames()
} // class PHPExcel_Calculation

View File

@ -1,6 +1,7 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_CodePage
*
* Copyright (c) 2006 - 2015 PHPExcel
*
@ -24,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Shared_CodePage
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_CodePage
{
/**
@ -102,5 +94,4 @@ class PHPExcel_Shared_CodePage
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_Date
*
* Copyright (c) 2006 - 2015 PHPExcel
*
@ -25,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Shared_Date
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Date
{
/** constants */
@ -47,7 +38,8 @@ class PHPExcel_Shared_Date
* @public
* @var string[]
*/
public static $_monthNames = array( 'Jan' => 'January',
public static $monthNames = array(
'Jan' => 'January',
'Feb' => 'February',
'Mar' => 'March',
'Apr' => 'April',
@ -68,7 +60,8 @@ class PHPExcel_Shared_Date
* @public
* @var string[]
*/
public static $_numberSuffixes = array( 'st',
public static $numberSuffixes = array(
'st',
'nd',
'rd',
'th',
@ -80,7 +73,7 @@ class PHPExcel_Shared_Date
* @private
* @var int
*/
protected static $_excelBaseDate = self::CALENDAR_WINDOWS_1900;
protected static $excelBaseDate = self::CALENDAR_WINDOWS_1900;
/**
* Set the Excel calendar (Windows 1900 or Mac 1904)
@ -88,14 +81,15 @@ class PHPExcel_Shared_Date
* @param integer $baseDate Excel base date (1900 or 1904)
* @return boolean Success or failure
*/
public static function setExcelCalendar($baseDate) {
public static function setExcelCalendar($baseDate)
{
if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
($baseDate == self::CALENDAR_MAC_1904)) {
self::$_excelBaseDate = $baseDate;
return TRUE;
self::$excelBaseDate = $baseDate;
return true;
}
return false;
}
return FALSE;
} // function setExcelCalendar()
/**
@ -103,9 +97,10 @@ class PHPExcel_Shared_Date
*
* @return integer Excel base date (1900 or 1904)
*/
public static function getExcelCalendar() {
return self::$_excelBaseDate;
} // function getExcelCalendar()
public static function getExcelCalendar()
{
return self::$excelBaseDate;
}
/**
@ -117,20 +112,21 @@ class PHPExcel_Shared_Date
* @param string $timezone The timezone for finding the adjustment from UST
* @return long PHP serialized date/time
*/
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) {
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
$my_excelBaseDate = 25569;
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = false, $timezone = null)
{
if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
$myexcelBaseDate = 25569;
// Adjust for the spurious 29-Feb-1900 (Day 60)
if ($dateValue < 60) {
--$my_excelBaseDate;
--$myexcelBaseDate;
}
} else {
$my_excelBaseDate = 24107;
$myexcelBaseDate = 24107;
}
// Perform conversion
if ($dateValue >= 1) {
$utcDays = $dateValue - $my_excelBaseDate;
$utcDays = $dateValue - $myexcelBaseDate;
$returnValue = round($utcDays * 86400);
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
$returnValue = (integer) $returnValue;
@ -146,9 +142,8 @@ class PHPExcel_Shared_Date
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
0;
// Return
return $returnValue + $timezoneAdjustment;
} // function ExcelToPHP()
}
/**
@ -157,7 +152,8 @@ class PHPExcel_Shared_Date
* @param integer $dateValue Excel date/time value
* @return DateTime PHP date/time object
*/
public static function ExcelToPHPObject($dateValue = 0) {
public static function ExcelToPHPObject($dateValue = 0)
{
$dateTime = self::ExcelToPHP($dateValue);
$days = floor($dateTime / 86400);
$time = round((($dateTime / 86400) - $days) * 86400);
@ -169,7 +165,7 @@ class PHPExcel_Shared_Date
$dateObj->setTime($hours,$minutes,$seconds);
return $dateObj;
} // function ExcelToPHPObject()
}
/**
@ -182,10 +178,11 @@ class PHPExcel_Shared_Date
* @return mixed Excel date/time value
* or boolean FALSE on failure
*/
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) {
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = false, $timezone = null)
{
$saveTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
$retValue = FALSE;
$retValue = false;
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
$dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
@ -198,7 +195,7 @@ class PHPExcel_Shared_Date
date_default_timezone_set($saveTimeZone);
return $retValue;
} // function PHPToExcel()
}
/**
@ -212,18 +209,21 @@ class PHPExcel_Shared_Date
* @param long $seconds
* @return long Excel date/time value
*/
public static function FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) {
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) {
public static function FormattedPHPToExcel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)
{
if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
//
// Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
// This affects every date following 28th February 1900
//
$excel1900isLeapYear = TRUE;
if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = FALSE; }
$my_excelBaseDate = 2415020;
$excel1900isLeapYear = true;
if (($year == 1900) && ($month <= 2)) {
$excel1900isLeapYear = false;
}
$myexcelBaseDate = 2415020;
} else {
$my_excelBaseDate = 2416481;
$excel1900isLeapYear = FALSE;
$myexcelBaseDate = 2416481;
$excel1900isLeapYear = false;
}
// Julian base date Adjustment
@ -237,12 +237,12 @@ class PHPExcel_Shared_Date
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
$century = substr($year,0,2);
$decade = substr($year,2,2);
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $my_excelBaseDate + $excel1900isLeapYear;
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
return (float) $excelDate + $excelTime;
} // function FormattedPHPToExcel()
}
/**
@ -251,13 +251,14 @@ class PHPExcel_Shared_Date
* @param PHPExcel_Cell $pCell
* @return boolean
*/
public static function isDateTime(PHPExcel_Cell $pCell) {
public static function isDateTime(PHPExcel_Cell $pCell)
{
return self::isDateTimeFormat(
$pCell->getWorksheet()->getStyle(
$pCell->getCoordinate()
)->getNumberFormat()
);
} // function isDateTime()
}
/**
@ -266,9 +267,10 @@ class PHPExcel_Shared_Date
* @param PHPExcel_Style_NumberFormat $pFormat
* @return boolean
*/
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat) {
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat)
{
return self::isDateTimeFormatCode($pFormat->getFormatCode());
} // function isDateTimeFormat()
}
private static $possibleDateFormatCharacters = 'eymdHs';
@ -279,13 +281,14 @@ class PHPExcel_Shared_Date
* @param string $pFormatCode
* @return boolean
*/
public static function isDateTimeFormatCode($pFormatCode = '') {
public static function isDateTimeFormatCode($pFormatCode = '')
{
if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL))
// "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
return FALSE;
return false;
if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
// Scientific format
return FALSE;
return false;
// Switch on formatcode
switch ($pFormatCode) {
// Explicitly defined date formats
@ -311,34 +314,34 @@ class PHPExcel_Shared_Date
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
return TRUE;
return true;
}
// Typically number, currency or accounting (or occasionally fraction) formats
if ((substr($pFormatCode, 0, 1) == '_') || (substr($pFormatCode, 0, 2) == '0 ')) {
return FALSE;
return false;
}
// Try checking for any of the date formatting characters that don't appear within square braces
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $pFormatCode)) {
// We might also have a format mask containing quoted strings...
// we don't want to test for any of our characters within the quoted blocks
if (strpos($pFormatCode,'"') !== FALSE) {
$segMatcher = FALSE;
if (strpos($pFormatCode, '"') !== false) {
$segMatcher = false;
foreach(explode('"', $pFormatCode) as $subVal) {
// Only test in alternate array entries (the non-quoted blocks)
if (($segMatcher = !$segMatcher) &&
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $subVal))) {
return TRUE;
return true;
}
}
return FALSE;
return false;
}
return TRUE;
return true;
}
// No date...
return FALSE;
} // function isDateTimeFormatCode()
return false;
}
/**
@ -347,33 +350,33 @@ class PHPExcel_Shared_Date
* @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
* @return float|FALSE Excel date/time serial value
*/
public static function stringToExcel($dateValue = '') {
public static function stringToExcel($dateValue = '')
{
if (strlen($dateValue) < 2)
return FALSE;
return false;
if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue))
return FALSE;
return false;
$dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue);
if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) {
return FALSE;
} else {
if (strpos($dateValue, ':') !== FALSE) {
return false;
}
if (strpos($dateValue, ':') !== false) {
$timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue);
if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) {
return FALSE;
return false;
}
$dateValueNew += $timeValue;
}
return $dateValueNew;
}
}
public static function monthStringToNumber($month) {
public static function monthStringToNumber($month)
{
$monthIndex = 1;
foreach(self::$_monthNames as $shortMonthName => $longMonthName) {
foreach(self::$monthNames as $shortMonthName => $longMonthName) {
if (($month === $longMonthName) || ($month === $shortMonthName)) {
return $monthIndex;
}
@ -382,12 +385,12 @@ class PHPExcel_Shared_Date
return $month;
}
public static function dayStringToNumber($day) {
$strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day));
public static function dayStringToNumber($day)
{
$strippedDayValue = (str_replace(self::$numberSuffixes, '', $day));
if (is_numeric($strippedDayValue)) {
return $strippedDayValue;
}
return $day;
}
}

View File

@ -1,6 +1,12 @@
<?php
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', PHPExcel_Shared_File::sys_get_temp_dir() . DIRECTORY_SEPARATOR);
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
/**
* PHPExcel
* PHPExcel_Shared_ZipArchive
*
* Copyright (c) 2006 - 2015 PHPExcel
*
@ -24,20 +30,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', PHPExcel_Shared_File::sys_get_temp_dir() . DIRECTORY_SEPARATOR);
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
/**
* PHPExcel_Shared_ZipArchive
*
* @category PHPExcel
* @package PHPExcel_Shared_ZipArchive
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipArchive
{

View File

@ -1,6 +1,7 @@
<?php
/**
* PHPExcel
* PHPExcel_Shared_ZipStreamWrapper
*
* Copyright (c) 2006 - 2015 PHPExcel
*
@ -24,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Shared_ZipStreamWrapper
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipStreamWrapper {
/**
* Internal ZipAcrhive