diff --git a/Classes/PHPExcel/Calculation/DateTime.php b/Classes/PHPExcel/Calculation/DateTime.php index fabd60c6..359f6ef5 100644 --- a/Classes/PHPExcel/Calculation/DateTime.php +++ b/Classes/PHPExcel/Calculation/DateTime.php @@ -1,6 +1,16 @@ = $startDate) && ($holidayDate <= $endDate)) { @@ -1035,7 +1026,7 @@ class PHPExcel_Calculation_DateTime array_shift($dateArgs); array_shift($dateArgs); - if ((is_string($startDate = self::_getDateValue($startDate))) || (!is_numeric($endDays))) { + if ((is_string($startDate = self::getDateValue($startDate))) || (!is_numeric($endDays))) { return PHPExcel_Calculation_Functions::VALUE(); } $startDate = (float) floor($startDate); @@ -1069,7 +1060,7 @@ class PHPExcel_Calculation_DateTime $holidayCountedArray = $holidayDates = array(); foreach ($dateArgs as $holidayDate) { if (($holidayDate !== null) && (trim($holidayDate) > '')) { - if (is_string($holidayDate = self::_getDateValue($holidayDate))) { + if (is_string($holidayDate = self::getDateValue($holidayDate))) { return PHPExcel_Calculation_Functions::VALUE(); } if (self::DAYOFWEEK($holidayDate, 3) < 5) { @@ -1136,7 +1127,7 @@ class PHPExcel_Calculation_DateTime if ($dateValue === null) { $dateValue = 1; - } elseif (is_string($dateValue = self::_getDateValue($dateValue))) { + } elseif (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue == 0.0) { return 0; @@ -1182,7 +1173,7 @@ class PHPExcel_Calculation_DateTime if ($dateValue === null) { $dateValue = 1; - } elseif (is_string($dateValue = self::_getDateValue($dateValue))) { + } elseif (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); @@ -1258,7 +1249,7 @@ class PHPExcel_Calculation_DateTime if ($dateValue === null) { $dateValue = 1; - } elseif (is_string($dateValue = self::_getDateValue($dateValue))) { + } elseif (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); @@ -1297,7 +1288,7 @@ class PHPExcel_Calculation_DateTime if ($dateValue === null) { $dateValue = 1; - } elseif (is_string($dateValue = self::_getDateValue($dateValue))) { + } elseif (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); @@ -1329,7 +1320,7 @@ class PHPExcel_Calculation_DateTime if ($dateValue === null) { $dateValue = 1; - } elseif (is_string($dateValue = self::_getDateValue($dateValue))) { + } elseif (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } elseif ($dateValue < 0.0) { return PHPExcel_Calculation_Functions::NaN(); @@ -1366,7 +1357,7 @@ class PHPExcel_Calculation_DateTime return PHPExcel_Calculation_Functions::VALUE(); } } - $timeValue = self::_getTimeValue($timeValue); + $timeValue = self::getTimeValue($timeValue); if (is_string($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } @@ -1407,7 +1398,7 @@ class PHPExcel_Calculation_DateTime return PHPExcel_Calculation_Functions::VALUE(); } } - $timeValue = self::_getTimeValue($timeValue); + $timeValue = self::getTimeValue($timeValue); if (is_string($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } @@ -1448,7 +1439,7 @@ class PHPExcel_Calculation_DateTime return PHPExcel_Calculation_Functions::VALUE(); } } - $timeValue = self::_getTimeValue($timeValue); + $timeValue = self::getTimeValue($timeValue); if (is_string($timeValue)) { return PHPExcel_Calculation_Functions::VALUE(); } @@ -1494,12 +1485,12 @@ class PHPExcel_Calculation_DateTime } $adjustmentMonths = floor($adjustmentMonths); - if (is_string($dateValue = self::_getDateValue($dateValue))) { + if (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } // Execute function - $PHPDateObject = self::_adjustDateByMonths($dateValue, $adjustmentMonths); + $PHPDateObject = self::adjustDateByMonths($dateValue, $adjustmentMonths); switch (PHPExcel_Calculation_Functions::getReturnDateType()) { case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL: @@ -1540,12 +1531,12 @@ class PHPExcel_Calculation_DateTime } $adjustmentMonths = floor($adjustmentMonths); - if (is_string($dateValue = self::_getDateValue($dateValue))) { + if (is_string($dateValue = self::getDateValue($dateValue))) { return PHPExcel_Calculation_Functions::VALUE(); } // Execute function - $PHPDateObject = self::_adjustDateByMonths($dateValue, $adjustmentMonths+1); + $PHPDateObject = self::adjustDateByMonths($dateValue, $adjustmentMonths+1); $adjustDays = (int) $PHPDateObject->format('d'); $adjustDaysString = '-' . $adjustDays . ' days'; $PHPDateObject->modify($adjustDaysString); diff --git a/Classes/PHPExcel/Calculation/Engineering.php b/Classes/PHPExcel/Calculation/Engineering.php index d7c63298..8c027d12 100644 --- a/Classes/PHPExcel/Calculation/Engineering.php +++ b/Classes/PHPExcel/Calculation/Engineering.php @@ -1,6 +1,19 @@ array('Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => true), 'sg' => array('Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => false), 'lbm' => array('Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => false), @@ -125,7 +115,7 @@ class PHPExcel_Calculation_Engineering * * @var mixed[] */ - private static $_conversionMultipliers = array( + private static $conversionMultipliers = array( 'Y' => array('multiplier' => 1E24, 'name' => 'yotta'), 'Z' => array('multiplier' => 1E21, 'name' => 'zetta'), 'E' => array('multiplier' => 1E18, 'name' => 'exa'), @@ -153,616 +143,616 @@ class PHPExcel_Calculation_Engineering * * @var mixed[] */ - private static $_unitConversions = array( - 'Mass' => array( - 'g' => array( - 'g' => 1.0, - 'sg' => 6.85220500053478E-05, + private static $unitConversions = array( + 'Mass' => array( + 'g' => array( + 'g' => 1.0, + 'sg' => 6.85220500053478E-05, 'lbm' => 2.20462291469134E-03, - 'u' => 6.02217000000000E+23, + 'u' => 6.02217000000000E+23, 'ozm' => 3.52739718003627E-02, ), 'sg' => array( - 'g' => 1.45938424189287E+04, - 'sg' => 1.0, + 'g' => 1.45938424189287E+04, + 'sg' => 1.0, 'lbm' => 3.21739194101647E+01, - 'u' => 8.78866000000000E+27, + 'u' => 8.78866000000000E+27, 'ozm' => 5.14782785944229E+02, ), 'lbm' => array( - 'g' => 4.5359230974881148E+02, - 'sg' => 3.10810749306493E-02, + 'g' => 4.5359230974881148E+02, + 'sg' => 3.10810749306493E-02, 'lbm' => 1.0, - 'u' => 2.73161000000000E+26, + 'u' => 2.73161000000000E+26, 'ozm' => 1.60000023429410E+01, ), - 'u' => array( - 'g' => 1.66053100460465E-24, - 'sg' => 1.13782988532950E-28, + 'u' => array( + 'g' => 1.66053100460465E-24, + 'sg' => 1.13782988532950E-28, 'lbm' => 3.66084470330684E-27, - 'u' => 1.0, + 'u' => 1.0, 'ozm' => 5.85735238300524E-26, ), 'ozm' => array( - 'g' => 2.83495152079732E+01, - 'sg' => 1.94256689870811E-03, + 'g' => 2.83495152079732E+01, + 'sg' => 1.94256689870811E-03, 'lbm' => 6.24999908478882E-02, - 'u' => 1.70725600000000E+25, + 'u' => 1.70725600000000E+25, 'ozm' => 1.0, ), ), 'Distance' => array( - 'm' => array( - 'm' => 1.0, - 'mi' => 6.21371192237334E-04, - 'Nmi' => 5.39956803455724E-04, - 'in' => 3.93700787401575E+01, - 'ft' => 3.28083989501312E+00, - 'yd' => 1.09361329797891E+00, - 'ang' => 1.00000000000000E+10, + 'm' => array( + 'm' => 1.0, + 'mi' => 6.21371192237334E-04, + 'Nmi' => 5.39956803455724E-04, + 'in' => 3.93700787401575E+01, + 'ft' => 3.28083989501312E+00, + 'yd' => 1.09361329797891E+00, + 'ang' => 1.00000000000000E+10, 'Pica' => 2.83464566929116E+03, ), 'mi' => array( - 'm' => 1.60934400000000E+03, - 'mi' => 1.0, - 'Nmi' => 8.68976241900648E-01, - 'in' => 6.33600000000000E+04, - 'ft' => 5.28000000000000E+03, - 'yd' => 1.76000000000000E+03, - 'ang' => 1.60934400000000E+13, + 'm' => 1.60934400000000E+03, + 'mi' => 1.0, + 'Nmi' => 8.68976241900648E-01, + 'in' => 6.33600000000000E+04, + 'ft' => 5.28000000000000E+03, + 'yd' => 1.76000000000000E+03, + 'ang' => 1.60934400000000E+13, 'Pica' => 4.56191999999971E+06, ), 'Nmi' => array( - 'm' => 1.85200000000000E+03, - 'mi' => 1.15077944802354E+00, - 'Nmi' => 1.0, - 'in' => 7.29133858267717E+04, - 'ft' => 6.07611548556430E+03, - 'yd' => 2.02537182785694E+03, - 'ang' => 1.85200000000000E+13, + 'm' => 1.85200000000000E+03, + 'mi' => 1.15077944802354E+00, + 'Nmi' => 1.0, + 'in' => 7.29133858267717E+04, + 'ft' => 6.07611548556430E+03, + 'yd' => 2.02537182785694E+03, + 'ang' => 1.85200000000000E+13, 'Pica' => 5.24976377952723E+06, ), 'in' => array( - 'm' => 2.54000000000000E-02, - 'mi' => 1.57828282828283E-05, - 'Nmi' => 1.37149028077754E-05, - 'in' => 1.0, - 'ft' => 8.33333333333333E-02, - 'yd' => 2.77777777686643E-02, - 'ang' => 2.54000000000000E+08, + 'm' => 2.54000000000000E-02, + 'mi' => 1.57828282828283E-05, + 'Nmi' => 1.37149028077754E-05, + 'in' => 1.0, + 'ft' => 8.33333333333333E-02, + 'yd' => 2.77777777686643E-02, + 'ang' => 2.54000000000000E+08, 'Pica' => 7.19999999999955E+01, ), 'ft' => array( - 'm' => 3.04800000000000E-01, - 'mi' => 1.89393939393939E-04, - 'Nmi' => 1.64578833693305E-04, - 'in' => 1.20000000000000E+01, - 'ft' => 1.0, - 'yd' => 3.33333333223972E-01, - 'ang' => 3.04800000000000E+09, + 'm' => 3.04800000000000E-01, + 'mi' => 1.89393939393939E-04, + 'Nmi' => 1.64578833693305E-04, + 'in' => 1.20000000000000E+01, + 'ft' => 1.0, + 'yd' => 3.33333333223972E-01, + 'ang' => 3.04800000000000E+09, 'Pica' => 8.63999999999946E+02, ), 'yd' => array( - 'm' => 9.14400000300000E-01, - 'mi' => 5.68181818368230E-04, - 'Nmi' => 4.93736501241901E-04, - 'in' => 3.60000000118110E+01, - 'ft' => 3.00000000000000E+00, - 'yd' => 1.0, - 'ang' => 9.14400000300000E+09, + 'm' => 9.14400000300000E-01, + 'mi' => 5.68181818368230E-04, + 'Nmi' => 4.93736501241901E-04, + 'in' => 3.60000000118110E+01, + 'ft' => 3.00000000000000E+00, + 'yd' => 1.0, + 'ang' => 9.14400000300000E+09, 'Pica' => 2.59200000085023E+03, ), 'ang' => array( - 'm' => 1.00000000000000E-10, - 'mi' => 6.21371192237334E-14, - 'Nmi' => 5.39956803455724E-14, - 'in' => 3.93700787401575E-09, - 'ft' => 3.28083989501312E-10, - 'yd' => 1.09361329797891E-10, - 'ang' => 1.0, + 'm' => 1.00000000000000E-10, + 'mi' => 6.21371192237334E-14, + 'Nmi' => 5.39956803455724E-14, + 'in' => 3.93700787401575E-09, + 'ft' => 3.28083989501312E-10, + 'yd' => 1.09361329797891E-10, + 'ang' => 1.0, 'Pica' => 2.83464566929116E-07, ), 'Pica' => array( - 'm' => 3.52777777777800E-04, - 'mi' => 2.19205948372629E-07, - 'Nmi' => 1.90484761219114E-07, - 'in' => 1.38888888888898E-02, - 'ft' => 1.15740740740748E-03, - 'yd' => 3.85802469009251E-04, - 'ang' => 3.52777777777800E+06, + 'm' => 3.52777777777800E-04, + 'mi' => 2.19205948372629E-07, + 'Nmi' => 1.90484761219114E-07, + 'in' => 1.38888888888898E-02, + 'ft' => 1.15740740740748E-03, + 'yd' => 3.85802469009251E-04, + 'ang' => 3.52777777777800E+06, 'Pica' => 1.0, ), ), - 'Time' => array( + 'Time' => array( 'yr' => array( - 'yr' => 1.0, - 'day' => 365.25, - 'hr' => 8766.0, - 'mn' => 525960.0, - 'sec' => 31557600.0, + 'yr' => 1.0, + 'day' => 365.25, + 'hr' => 8766.0, + 'mn' => 525960.0, + 'sec' => 31557600.0, ), 'day' => array( - 'yr' => 2.73785078713210E-03, - 'day' => 1.0, - 'hr' => 24.0, - 'mn' => 1440.0, - 'sec' => 86400.0, + 'yr' => 2.73785078713210E-03, + 'day' => 1.0, + 'hr' => 24.0, + 'mn' => 1440.0, + 'sec' => 86400.0, ), 'hr' => array( - 'yr' => 1.14077116130504E-04, - 'day' => 4.16666666666667E-02, - 'hr' => 1.0, - 'mn' => 60.0, - 'sec' => 3600.0, + 'yr' => 1.14077116130504E-04, + 'day' => 4.16666666666667E-02, + 'hr' => 1.0, + 'mn' => 60.0, + 'sec' => 3600.0, ), 'mn' => array( - 'yr' => 1.90128526884174E-06, - 'day' => 6.94444444444444E-04, - 'hr' => 1.66666666666667E-02, - 'mn' => 1.0, - 'sec' => 60.0, + 'yr' => 1.90128526884174E-06, + 'day' => 6.94444444444444E-04, + 'hr' => 1.66666666666667E-02, + 'mn' => 1.0, + 'sec' => 60.0, ), 'sec' => array( - 'yr' => 3.16880878140289E-08, - 'day' => 1.15740740740741E-05, - 'hr' => 2.77777777777778E-04, - 'mn' => 1.66666666666667E-02, - 'sec' => 1.0, + 'yr' => 3.16880878140289E-08, + 'day' => 1.15740740740741E-05, + 'hr' => 2.77777777777778E-04, + 'mn' => 1.66666666666667E-02, + 'sec' => 1.0, ), ), 'Pressure' => array( 'Pa' => array( - 'Pa' => 1.0, - 'p' => 1.0, - 'atm' => 9.86923299998193E-06, - 'at' => 9.86923299998193E-06, - 'mmHg' => 7.50061707998627E-03, + 'Pa' => 1.0, + 'p' => 1.0, + 'atm' => 9.86923299998193E-06, + 'at' => 9.86923299998193E-06, + 'mmHg' => 7.50061707998627E-03, ), - 'p' => array( - 'Pa' => 1.0, - 'p' => 1.0, - 'atm' => 9.86923299998193E-06, - 'at' => 9.86923299998193E-06, - 'mmHg' => 7.50061707998627E-03, + 'p' => array( + 'Pa' => 1.0, + 'p' => 1.0, + 'atm' => 9.86923299998193E-06, + 'at' => 9.86923299998193E-06, + 'mmHg' => 7.50061707998627E-03, ), 'atm' => array( - 'Pa' => 1.01324996583000E+05, - 'p' => 1.01324996583000E+05, - 'atm' => 1.0, - 'at' => 1.0, - 'mmHg' => 760.0, + 'Pa' => 1.01324996583000E+05, + 'p' => 1.01324996583000E+05, + 'atm' => 1.0, + 'at' => 1.0, + 'mmHg' => 760.0, ), 'at' => array( - 'Pa' => 1.01324996583000E+05, - 'p' => 1.01324996583000E+05, - 'atm' => 1.0, - 'at' => 1.0, - 'mmHg' => 760.0, + 'Pa' => 1.01324996583000E+05, + 'p' => 1.01324996583000E+05, + 'atm' => 1.0, + 'at' => 1.0, + 'mmHg' => 760.0, ), 'mmHg' => array( - 'Pa' => 1.33322363925000E+02, - 'p' => 1.33322363925000E+02, - 'atm' => 1.31578947368421E-03, - 'at' => 1.31578947368421E-03, - 'mmHg' => 1.0, + 'Pa' => 1.33322363925000E+02, + 'p' => 1.33322363925000E+02, + 'atm' => 1.31578947368421E-03, + 'at' => 1.31578947368421E-03, + 'mmHg' => 1.0, ), ), - 'Force' => array( - 'N' => array( - 'N' => 1.0, - 'dyn' => 1.0E+5, - 'dy' => 1.0E+5, - 'lbf' => 2.24808923655339E-01, + 'Force' => array( + 'N' => array( + 'N' => 1.0, + 'dyn' => 1.0E+5, + 'dy' => 1.0E+5, + 'lbf' => 2.24808923655339E-01, ), 'dyn' => array( - 'N' => 1.0E-5, - 'dyn' => 1.0, - 'dy' => 1.0, - 'lbf' => 2.24808923655339E-06, + 'N' => 1.0E-5, + 'dyn' => 1.0, + 'dy' => 1.0, + 'lbf' => 2.24808923655339E-06, ), 'dy' => array( - 'N' => 1.0E-5, - 'dyn' => 1.0, - 'dy' => 1.0, - 'lbf' => 2.24808923655339E-06, + 'N' => 1.0E-5, + 'dyn' => 1.0, + 'dy' => 1.0, + 'lbf' => 2.24808923655339E-06, ), 'lbf' => array( - 'N' => 4.448222, - 'dyn' => 4.448222E+5, - 'dy' => 4.448222E+5, - 'lbf' => 1.0, + 'N' => 4.448222, + 'dyn' => 4.448222E+5, + 'dy' => 4.448222E+5, + 'lbf' => 1.0, ), ), 'Energy' => array( - 'J' => array( - 'J' => 1.0, - 'e' => 9.99999519343231E+06, - 'c' => 2.39006249473467E-01, - 'cal' => 2.38846190642017E-01, - 'eV' => 6.24145700000000E+18, - 'ev' => 6.24145700000000E+18, - 'HPh' => 3.72506430801000E-07, - 'hh' => 3.72506430801000E-07, - 'Wh' => 2.77777916238711E-04, - 'wh' => 2.77777916238711E-04, - 'flb' => 2.37304222192651E+01, - 'BTU' => 9.47815067349015E-04, - 'btu' => 9.47815067349015E-04, + 'J' => array( + 'J' => 1.0, + 'e' => 9.99999519343231E+06, + 'c' => 2.39006249473467E-01, + 'cal' => 2.38846190642017E-01, + 'eV' => 6.24145700000000E+18, + 'ev' => 6.24145700000000E+18, + 'HPh' => 3.72506430801000E-07, + 'hh' => 3.72506430801000E-07, + 'Wh' => 2.77777916238711E-04, + 'wh' => 2.77777916238711E-04, + 'flb' => 2.37304222192651E+01, + 'BTU' => 9.47815067349015E-04, + 'btu' => 9.47815067349015E-04, ), - 'e' => array( - 'J' => 1.00000048065700E-07, - 'e' => 1.0, - 'c' => 2.39006364353494E-08, - 'cal' => 2.38846305445111E-08, - 'eV' => 6.24146000000000E+11, - 'ev' => 6.24146000000000E+11, - 'HPh' => 3.72506609848824E-14, - 'hh' => 3.72506609848824E-14, - 'Wh' => 2.77778049754611E-11, - 'wh' => 2.77778049754611E-11, - 'flb' => 2.37304336254586E-06, - 'BTU' => 9.47815522922962E-11, - 'btu' => 9.47815522922962E-11, + 'e' => array( + 'J' => 1.00000048065700E-07, + 'e' => 1.0, + 'c' => 2.39006364353494E-08, + 'cal' => 2.38846305445111E-08, + 'eV' => 6.24146000000000E+11, + 'ev' => 6.24146000000000E+11, + 'HPh' => 3.72506609848824E-14, + 'hh' => 3.72506609848824E-14, + 'Wh' => 2.77778049754611E-11, + 'wh' => 2.77778049754611E-11, + 'flb' => 2.37304336254586E-06, + 'BTU' => 9.47815522922962E-11, + 'btu' => 9.47815522922962E-11, ), - 'c' => array( - 'J' => 4.18399101363672E+00, - 'e' => 4.18398900257312E+07, - 'c' => 1.0, - 'cal' => 9.99330315287563E-01, - 'eV' => 2.61142000000000E+19, - 'ev' => 2.61142000000000E+19, - 'HPh' => 1.55856355899327E-06, - 'hh' => 1.55856355899327E-06, - 'Wh' => 1.16222030532950E-03, - 'wh' => 1.16222030532950E-03, - 'flb' => 9.92878733152102E+01, - 'BTU' => 3.96564972437776E-03, - 'btu' => 3.96564972437776E-03, + 'c' => array( + 'J' => 4.18399101363672E+00, + 'e' => 4.18398900257312E+07, + 'c' => 1.0, + 'cal' => 9.99330315287563E-01, + 'eV' => 2.61142000000000E+19, + 'ev' => 2.61142000000000E+19, + 'HPh' => 1.55856355899327E-06, + 'hh' => 1.55856355899327E-06, + 'Wh' => 1.16222030532950E-03, + 'wh' => 1.16222030532950E-03, + 'flb' => 9.92878733152102E+01, + 'BTU' => 3.96564972437776E-03, + 'btu' => 3.96564972437776E-03, ), 'cal' => array( - 'J' => 4.18679484613929E+00, - 'e' => 4.18679283372801E+07, - 'c' => 1.00067013349059E+00, - 'cal' => 1.0, - 'eV' => 2.61317000000000E+19, - 'ev' => 2.61317000000000E+19, - 'HPh' => 1.55960800463137E-06, - 'hh' => 1.55960800463137E-06, - 'Wh' => 1.16299914807955E-03, - 'wh' => 1.16299914807955E-03, - 'flb' => 9.93544094443283E+01, - 'BTU' => 3.96830723907002E-03, - 'btu' => 3.96830723907002E-03, + 'J' => 4.18679484613929E+00, + 'e' => 4.18679283372801E+07, + 'c' => 1.00067013349059E+00, + 'cal' => 1.0, + 'eV' => 2.61317000000000E+19, + 'ev' => 2.61317000000000E+19, + 'HPh' => 1.55960800463137E-06, + 'hh' => 1.55960800463137E-06, + 'Wh' => 1.16299914807955E-03, + 'wh' => 1.16299914807955E-03, + 'flb' => 9.93544094443283E+01, + 'BTU' => 3.96830723907002E-03, + 'btu' => 3.96830723907002E-03, ), 'eV' => array( - 'J' => 1.60219000146921E-19, - 'e' => 1.60218923136574E-12, - 'c' => 3.82933423195043E-20, - 'cal' => 3.82676978535648E-20, - 'eV' => 1.0, - 'ev' => 1.0, - 'HPh' => 5.96826078912344E-26, - 'hh' => 5.96826078912344E-26, - 'Wh' => 4.45053000026614E-23, - 'wh' => 4.45053000026614E-23, - 'flb' => 3.80206452103492E-18, - 'BTU' => 1.51857982414846E-22, - 'btu' => 1.51857982414846E-22, + 'J' => 1.60219000146921E-19, + 'e' => 1.60218923136574E-12, + 'c' => 3.82933423195043E-20, + 'cal' => 3.82676978535648E-20, + 'eV' => 1.0, + 'ev' => 1.0, + 'HPh' => 5.96826078912344E-26, + 'hh' => 5.96826078912344E-26, + 'Wh' => 4.45053000026614E-23, + 'wh' => 4.45053000026614E-23, + 'flb' => 3.80206452103492E-18, + 'BTU' => 1.51857982414846E-22, + 'btu' => 1.51857982414846E-22, ), 'ev' => array( - 'J' => 1.60219000146921E-19, - 'e' => 1.60218923136574E-12, - 'c' => 3.82933423195043E-20, - 'cal' => 3.82676978535648E-20, - 'eV' => 1.0, - 'ev' => 1.0, - 'HPh' => 5.96826078912344E-26, - 'hh' => 5.96826078912344E-26, - 'Wh' => 4.45053000026614E-23, - 'wh' => 4.45053000026614E-23, - 'flb' => 3.80206452103492E-18, - 'BTU' => 1.51857982414846E-22, - 'btu' => 1.51857982414846E-22, + 'J' => 1.60219000146921E-19, + 'e' => 1.60218923136574E-12, + 'c' => 3.82933423195043E-20, + 'cal' => 3.82676978535648E-20, + 'eV' => 1.0, + 'ev' => 1.0, + 'HPh' => 5.96826078912344E-26, + 'hh' => 5.96826078912344E-26, + 'Wh' => 4.45053000026614E-23, + 'wh' => 4.45053000026614E-23, + 'flb' => 3.80206452103492E-18, + 'BTU' => 1.51857982414846E-22, + 'btu' => 1.51857982414846E-22, ), 'HPh' => array( - 'J' => 2.68451741316170E+06, - 'e' => 2.68451612283024E+13, - 'c' => 6.41616438565991E+05, - 'cal' => 6.41186757845835E+05, - 'eV' => 1.67553000000000E+25, - 'ev' => 1.67553000000000E+25, - 'HPh' => 1.0, - 'hh' => 1.0, - 'Wh' => 7.45699653134593E+02, - 'wh' => 7.45699653134593E+02, - 'flb' => 6.37047316692964E+07, - 'BTU' => 2.54442605275546E+03, - 'btu' => 2.54442605275546E+03, + 'J' => 2.68451741316170E+06, + 'e' => 2.68451612283024E+13, + 'c' => 6.41616438565991E+05, + 'cal' => 6.41186757845835E+05, + 'eV' => 1.67553000000000E+25, + 'ev' => 1.67553000000000E+25, + 'HPh' => 1.0, + 'hh' => 1.0, + 'Wh' => 7.45699653134593E+02, + 'wh' => 7.45699653134593E+02, + 'flb' => 6.37047316692964E+07, + 'BTU' => 2.54442605275546E+03, + 'btu' => 2.54442605275546E+03, ), 'hh' => array( - 'J' => 2.68451741316170E+06, - 'e' => 2.68451612283024E+13, - 'c' => 6.41616438565991E+05, - 'cal' => 6.41186757845835E+05, - 'eV' => 1.67553000000000E+25, - 'ev' => 1.67553000000000E+25, - 'HPh' => 1.0, - 'hh' => 1.0, - 'Wh' => 7.45699653134593E+02, - 'wh' => 7.45699653134593E+02, - 'flb' => 6.37047316692964E+07, - 'BTU' => 2.54442605275546E+03, - 'btu' => 2.54442605275546E+03, + 'J' => 2.68451741316170E+06, + 'e' => 2.68451612283024E+13, + 'c' => 6.41616438565991E+05, + 'cal' => 6.41186757845835E+05, + 'eV' => 1.67553000000000E+25, + 'ev' => 1.67553000000000E+25, + 'HPh' => 1.0, + 'hh' => 1.0, + 'Wh' => 7.45699653134593E+02, + 'wh' => 7.45699653134593E+02, + 'flb' => 6.37047316692964E+07, + 'BTU' => 2.54442605275546E+03, + 'btu' => 2.54442605275546E+03, ), 'Wh' => array( - 'J' => 3.59999820554720E+03, - 'e' => 3.59999647518369E+10, - 'c' => 8.60422069219046E+02, - 'cal' => 8.59845857713046E+02, - 'eV' => 2.24692340000000E+22, - 'ev' => 2.24692340000000E+22, - 'HPh' => 1.34102248243839E-03, - 'hh' => 1.34102248243839E-03, - 'Wh' => 1.0, - 'wh' => 1.0, - 'flb' => 8.54294774062316E+04, - 'BTU' => 3.41213254164705E+00, - 'btu' => 3.41213254164705E+00, + 'J' => 3.59999820554720E+03, + 'e' => 3.59999647518369E+10, + 'c' => 8.60422069219046E+02, + 'cal' => 8.59845857713046E+02, + 'eV' => 2.24692340000000E+22, + 'ev' => 2.24692340000000E+22, + 'HPh' => 1.34102248243839E-03, + 'hh' => 1.34102248243839E-03, + 'Wh' => 1.0, + 'wh' => 1.0, + 'flb' => 8.54294774062316E+04, + 'BTU' => 3.41213254164705E+00, + 'btu' => 3.41213254164705E+00, ), 'wh' => array( - 'J' => 3.59999820554720E+03, - 'e' => 3.59999647518369E+10, - 'c' => 8.60422069219046E+02, - 'cal' => 8.59845857713046E+02, - 'eV' => 2.24692340000000E+22, - 'ev' => 2.24692340000000E+22, - 'HPh' => 1.34102248243839E-03, - 'hh' => 1.34102248243839E-03, - 'Wh' => 1.0, - 'wh' => 1.0, - 'flb' => 8.54294774062316E+04, - 'BTU' => 3.41213254164705E+00, - 'btu' => 3.41213254164705E+00, + 'J' => 3.59999820554720E+03, + 'e' => 3.59999647518369E+10, + 'c' => 8.60422069219046E+02, + 'cal' => 8.59845857713046E+02, + 'eV' => 2.24692340000000E+22, + 'ev' => 2.24692340000000E+22, + 'HPh' => 1.34102248243839E-03, + 'hh' => 1.34102248243839E-03, + 'Wh' => 1.0, + 'wh' => 1.0, + 'flb' => 8.54294774062316E+04, + 'BTU' => 3.41213254164705E+00, + 'btu' => 3.41213254164705E+00, ), 'flb' => array( - 'J' => 4.21400003236424E-02, - 'e' => 4.21399800687660E+05, - 'c' => 1.00717234301644E-02, - 'cal' => 1.00649785509554E-02, - 'eV' => 2.63015000000000E+17, - 'ev' => 2.63015000000000E+17, - 'HPh' => 1.56974211145130E-08, - 'hh' => 1.56974211145130E-08, - 'Wh' => 1.17055614802000E-05, - 'wh' => 1.17055614802000E-05, - 'flb' => 1.0, - 'BTU' => 3.99409272448406E-05, - 'btu' => 3.99409272448406E-05, + 'J' => 4.21400003236424E-02, + 'e' => 4.21399800687660E+05, + 'c' => 1.00717234301644E-02, + 'cal' => 1.00649785509554E-02, + 'eV' => 2.63015000000000E+17, + 'ev' => 2.63015000000000E+17, + 'HPh' => 1.56974211145130E-08, + 'hh' => 1.56974211145130E-08, + 'Wh' => 1.17055614802000E-05, + 'wh' => 1.17055614802000E-05, + 'flb' => 1.0, + 'BTU' => 3.99409272448406E-05, + 'btu' => 3.99409272448406E-05, ), 'BTU' => array( - 'J' => 1.05505813786749E+03, - 'e' => 1.05505763074665E+10, - 'c' => 2.52165488508168E+02, - 'cal' => 2.51996617135510E+02, - 'eV' => 6.58510000000000E+21, - 'ev' => 6.58510000000000E+21, - 'HPh' => 3.93015941224568E-04, - 'hh' => 3.93015941224568E-04, - 'Wh' => 2.93071851047526E-01, - 'wh' => 2.93071851047526E-01, - 'flb' => 2.50369750774671E+04, - 'BTU' => 1.0, - 'btu' => 1.0, + 'J' => 1.05505813786749E+03, + 'e' => 1.05505763074665E+10, + 'c' => 2.52165488508168E+02, + 'cal' => 2.51996617135510E+02, + 'eV' => 6.58510000000000E+21, + 'ev' => 6.58510000000000E+21, + 'HPh' => 3.93015941224568E-04, + 'hh' => 3.93015941224568E-04, + 'Wh' => 2.93071851047526E-01, + 'wh' => 2.93071851047526E-01, + 'flb' => 2.50369750774671E+04, + 'BTU' => 1.0, + 'btu' => 1.0, ), 'btu' => array( - 'J' => 1.05505813786749E+03, - 'e' => 1.05505763074665E+10, - 'c' => 2.52165488508168E+02, - 'cal' => 2.51996617135510E+02, - 'eV' => 6.58510000000000E+21, - 'ev' => 6.58510000000000E+21, - 'HPh' => 3.93015941224568E-04, - 'hh' => 3.93015941224568E-04, - 'Wh' => 2.93071851047526E-01, - 'wh' => 2.93071851047526E-01, - 'flb' => 2.50369750774671E+04, - 'BTU' => 1.0, - 'btu' => 1.0, + 'J' => 1.05505813786749E+03, + 'e' => 1.05505763074665E+10, + 'c' => 2.52165488508168E+02, + 'cal' => 2.51996617135510E+02, + 'eV' => 6.58510000000000E+21, + 'ev' => 6.58510000000000E+21, + 'HPh' => 3.93015941224568E-04, + 'hh' => 3.93015941224568E-04, + 'Wh' => 2.93071851047526E-01, + 'wh' => 2.93071851047526E-01, + 'flb' => 2.50369750774671E+04, + 'BTU' => 1.0, + 'btu' => 1.0, ), ), - 'Power' => array( + 'Power' => array( 'HP' => array( - 'HP' => 1.0, - 'h' => 1.0, - 'W' => 7.45701000000000E+02, - 'w' => 7.45701000000000E+02, + 'HP' => 1.0, + 'h' => 1.0, + 'W' => 7.45701000000000E+02, + 'w' => 7.45701000000000E+02, ), - 'h' => array( - 'HP' => 1.0, - 'h' => 1.0, - 'W' => 7.45701000000000E+02, - 'w' => 7.45701000000000E+02, + 'h' => array( + 'HP' => 1.0, + 'h' => 1.0, + 'W' => 7.45701000000000E+02, + 'w' => 7.45701000000000E+02, ), - 'W' => array( - 'HP' => 1.34102006031908E-03, - 'h' => 1.34102006031908E-03, - 'W' => 1.0, - 'w' => 1.0, + 'W' => array( + 'HP' => 1.34102006031908E-03, + 'h' => 1.34102006031908E-03, + 'W' => 1.0, + 'w' => 1.0, ), - 'w' => array( - 'HP' => 1.34102006031908E-03, - 'h' => 1.34102006031908E-03, - 'W' => 1.0, - 'w' => 1.0, + 'w' => array( + 'HP' => 1.34102006031908E-03, + 'h' => 1.34102006031908E-03, + 'W' => 1.0, + 'w' => 1.0, ), ), 'Magnetism' => array( - 'T' => array( - 'T' => 1.0, - 'ga' => 10000.0, + 'T' => array( + 'T' => 1.0, + 'ga' => 10000.0, ), 'ga' => array( - 'T' => 0.0001, - 'ga' => 1.0, + 'T' => 0.0001, + 'ga' => 1.0, ), ), 'Liquid' => array( 'tsp' => array( - 'tsp' => 1.0, - 'tbs' => 3.33333333333333E-01, - 'oz' => 1.66666666666667E-01, - 'cup' => 2.08333333333333E-02, - 'pt' => 1.04166666666667E-02, - 'us_pt' => 1.04166666666667E-02, - 'uk_pt' => 8.67558516821960E-03, - 'qt' => 5.20833333333333E-03, - 'gal' => 1.30208333333333E-03, - 'l' => 4.92999408400710E-03, - 'lt' => 4.92999408400710E-03, + 'tsp' => 1.0, + 'tbs' => 3.33333333333333E-01, + 'oz' => 1.66666666666667E-01, + 'cup' => 2.08333333333333E-02, + 'pt' => 1.04166666666667E-02, + 'us_pt' => 1.04166666666667E-02, + 'uk_pt' => 8.67558516821960E-03, + 'qt' => 5.20833333333333E-03, + 'gal' => 1.30208333333333E-03, + 'l' => 4.92999408400710E-03, + 'lt' => 4.92999408400710E-03, ), 'tbs' => array( - 'tsp' => 3.00000000000000E+00, - 'tbs' => 1.0, - 'oz' => 5.00000000000000E-01, - 'cup' => 6.25000000000000E-02, - 'pt' => 3.12500000000000E-02, - 'us_pt' => 3.12500000000000E-02, - 'uk_pt' => 2.60267555046588E-02, - 'qt' => 1.56250000000000E-02, - 'gal' => 3.90625000000000E-03, - 'l' => 1.47899822520213E-02, - 'lt' => 1.47899822520213E-02, + 'tsp' => 3.00000000000000E+00, + 'tbs' => 1.0, + 'oz' => 5.00000000000000E-01, + 'cup' => 6.25000000000000E-02, + 'pt' => 3.12500000000000E-02, + 'us_pt' => 3.12500000000000E-02, + 'uk_pt' => 2.60267555046588E-02, + 'qt' => 1.56250000000000E-02, + 'gal' => 3.90625000000000E-03, + 'l' => 1.47899822520213E-02, + 'lt' => 1.47899822520213E-02, ), 'oz' => array( - 'tsp' => 6.00000000000000E+00, - 'tbs' => 2.00000000000000E+00, - 'oz' => 1.0, - 'cup' => 1.25000000000000E-01, - 'pt' => 6.25000000000000E-02, - 'us_pt' => 6.25000000000000E-02, - 'uk_pt' => 5.20535110093176E-02, - 'qt' => 3.12500000000000E-02, - 'gal' => 7.81250000000000E-03, - 'l' => 2.95799645040426E-02, - 'lt' => 2.95799645040426E-02, + 'tsp' => 6.00000000000000E+00, + 'tbs' => 2.00000000000000E+00, + 'oz' => 1.0, + 'cup' => 1.25000000000000E-01, + 'pt' => 6.25000000000000E-02, + 'us_pt' => 6.25000000000000E-02, + 'uk_pt' => 5.20535110093176E-02, + 'qt' => 3.12500000000000E-02, + 'gal' => 7.81250000000000E-03, + 'l' => 2.95799645040426E-02, + 'lt' => 2.95799645040426E-02, ), 'cup' => array( - 'tsp' => 4.80000000000000E+01, - 'tbs' => 1.60000000000000E+01, - 'oz' => 8.00000000000000E+00, - 'cup' => 1.0, - 'pt' => 5.00000000000000E-01, - 'us_pt' => 5.00000000000000E-01, - 'uk_pt' => 4.16428088074541E-01, - 'qt' => 2.50000000000000E-01, - 'gal' => 6.25000000000000E-02, - 'l' => 2.36639716032341E-01, - 'lt' => 2.36639716032341E-01, + 'tsp' => 4.80000000000000E+01, + 'tbs' => 1.60000000000000E+01, + 'oz' => 8.00000000000000E+00, + 'cup' => 1.0, + 'pt' => 5.00000000000000E-01, + 'us_pt' => 5.00000000000000E-01, + 'uk_pt' => 4.16428088074541E-01, + 'qt' => 2.50000000000000E-01, + 'gal' => 6.25000000000000E-02, + 'l' => 2.36639716032341E-01, + 'lt' => 2.36639716032341E-01, ), 'pt' => array( - 'tsp' => 9.60000000000000E+01, - 'tbs' => 3.20000000000000E+01, - 'oz' => 1.60000000000000E+01, - 'cup' => 2.00000000000000E+00, - 'pt' => 1.0, - 'us_pt' => 1.0, - 'uk_pt' => 8.32856176149081E-01, - 'qt' => 5.00000000000000E-01, - 'gal' => 1.25000000000000E-01, - 'l' => 4.73279432064682E-01, - 'lt' => 4.73279432064682E-01, + 'tsp' => 9.60000000000000E+01, + 'tbs' => 3.20000000000000E+01, + 'oz' => 1.60000000000000E+01, + 'cup' => 2.00000000000000E+00, + 'pt' => 1.0, + 'us_pt' => 1.0, + 'uk_pt' => 8.32856176149081E-01, + 'qt' => 5.00000000000000E-01, + 'gal' => 1.25000000000000E-01, + 'l' => 4.73279432064682E-01, + 'lt' => 4.73279432064682E-01, ), 'us_pt' => array( - 'tsp' => 9.60000000000000E+01, - 'tbs' => 3.20000000000000E+01, - 'oz' => 1.60000000000000E+01, - 'cup' => 2.00000000000000E+00, - 'pt' => 1.0, - 'us_pt' => 1.0, - 'uk_pt' => 8.32856176149081E-01, - 'qt' => 5.00000000000000E-01, - 'gal' => 1.25000000000000E-01, - 'l' => 4.73279432064682E-01, - 'lt' => 4.73279432064682E-01, + 'tsp' => 9.60000000000000E+01, + 'tbs' => 3.20000000000000E+01, + 'oz' => 1.60000000000000E+01, + 'cup' => 2.00000000000000E+00, + 'pt' => 1.0, + 'us_pt' => 1.0, + 'uk_pt' => 8.32856176149081E-01, + 'qt' => 5.00000000000000E-01, + 'gal' => 1.25000000000000E-01, + 'l' => 4.73279432064682E-01, + 'lt' => 4.73279432064682E-01, ), 'uk_pt' => array( - 'tsp' => 1.15266000000000E+02, - 'tbs' => 3.84220000000000E+01, - 'oz' => 1.92110000000000E+01, - 'cup' => 2.40137500000000E+00, - 'pt' => 1.20068750000000E+00, - 'us_pt' => 1.20068750000000E+00, - 'uk_pt' => 1.0, - 'qt' => 6.00343750000000E-01, - 'gal' => 1.50085937500000E-01, - 'l' => 5.68260698087162E-01, - 'lt' => 5.68260698087162E-01, + 'tsp' => 1.15266000000000E+02, + 'tbs' => 3.84220000000000E+01, + 'oz' => 1.92110000000000E+01, + 'cup' => 2.40137500000000E+00, + 'pt' => 1.20068750000000E+00, + 'us_pt' => 1.20068750000000E+00, + 'uk_pt' => 1.0, + 'qt' => 6.00343750000000E-01, + 'gal' => 1.50085937500000E-01, + 'l' => 5.68260698087162E-01, + 'lt' => 5.68260698087162E-01, ), 'qt' => array( - 'tsp' => 1.92000000000000E+02, - 'tbs' => 6.40000000000000E+01, - 'oz' => 3.20000000000000E+01, - 'cup' => 4.00000000000000E+00, - 'pt' => 2.00000000000000E+00, - 'us_pt' => 2.00000000000000E+00, - 'uk_pt' => 1.66571235229816E+00, - 'qt' => 1.0, - 'gal' => 2.50000000000000E-01, - 'l' => 9.46558864129363E-01, - 'lt' => 9.46558864129363E-01, + 'tsp' => 1.92000000000000E+02, + 'tbs' => 6.40000000000000E+01, + 'oz' => 3.20000000000000E+01, + 'cup' => 4.00000000000000E+00, + 'pt' => 2.00000000000000E+00, + 'us_pt' => 2.00000000000000E+00, + 'uk_pt' => 1.66571235229816E+00, + 'qt' => 1.0, + 'gal' => 2.50000000000000E-01, + 'l' => 9.46558864129363E-01, + 'lt' => 9.46558864129363E-01, ), 'gal' => array( - 'tsp' => 7.68000000000000E+02, - 'tbs' => 2.56000000000000E+02, - 'oz' => 1.28000000000000E+02, - 'cup' => 1.60000000000000E+01, - 'pt' => 8.00000000000000E+00, - 'us_pt' => 8.00000000000000E+00, - 'uk_pt' => 6.66284940919265E+00, - 'qt' => 4.00000000000000E+00, - 'gal' => 1.0, - 'l' => 3.78623545651745E+00, - 'lt' => 3.78623545651745E+00, + 'tsp' => 7.68000000000000E+02, + 'tbs' => 2.56000000000000E+02, + 'oz' => 1.28000000000000E+02, + 'cup' => 1.60000000000000E+01, + 'pt' => 8.00000000000000E+00, + 'us_pt' => 8.00000000000000E+00, + 'uk_pt' => 6.66284940919265E+00, + 'qt' => 4.00000000000000E+00, + 'gal' => 1.0, + 'l' => 3.78623545651745E+00, + 'lt' => 3.78623545651745E+00, ), - 'l' => array( - 'tsp' => 2.02840000000000E+02, - 'tbs' => 6.76133333333333E+01, - 'oz' => 3.38066666666667E+01, - 'cup' => 4.22583333333333E+00, - 'pt' => 2.11291666666667E+00, - 'us_pt' => 2.11291666666667E+00, - 'uk_pt' => 1.75975569552166E+00, - 'qt' => 1.05645833333333E+00, - 'gal' => 2.64114583333333E-01, - 'l' => 1.0, - 'lt' => 1.0, + 'l' => array( + 'tsp' => 2.02840000000000E+02, + 'tbs' => 6.76133333333333E+01, + 'oz' => 3.38066666666667E+01, + 'cup' => 4.22583333333333E+00, + 'pt' => 2.11291666666667E+00, + 'us_pt' => 2.11291666666667E+00, + 'uk_pt' => 1.75975569552166E+00, + 'qt' => 1.05645833333333E+00, + 'gal' => 2.64114583333333E-01, + 'l' => 1.0, + 'lt' => 1.0, ), 'lt' => array( - 'tsp' => 2.02840000000000E+02, - 'tbs' => 6.76133333333333E+01, - 'oz' => 3.38066666666667E+01, - 'cup' => 4.22583333333333E+00, - 'pt' => 2.11291666666667E+00, - 'us_pt' => 2.11291666666667E+00, - 'uk_pt' => 1.75975569552166E+00, - 'qt' => 1.05645833333333E+00, - 'gal' => 2.64114583333333E-01, - 'l' => 1.0, - 'lt' => 1.0, + 'tsp' => 2.02840000000000E+02, + 'tbs' => 6.76133333333333E+01, + 'oz' => 3.38066666666667E+01, + 'cup' => 4.22583333333333E+00, + 'pt' => 2.11291666666667E+00, + 'us_pt' => 2.11291666666667E+00, + 'uk_pt' => 1.75975569552166E+00, + 'qt' => 1.05645833333333E+00, + 'gal' => 2.64114583333333E-01, + 'l' => 1.0, + 'lt' => 1.0, ), ), ); /** - * _parseComplex + * parseComplex * * Parses a complex number into its real and imaginary parts, and an I or J suffix * * @param string $complexNumber The complex number * @return string[] Indexed on "real", "imaginary" and "suffix" */ - public static function _parseComplex($complexNumber) + public static function parseComplex($complexNumber) { $workString = (string) $complexNumber; @@ -817,7 +807,7 @@ class PHPExcel_Calculation_Engineering * @param string $complexNumber The complex number to clean * @return string The "cleaned" complex number */ - private static function _cleanComplex($complexNumber) + private static function cleanComplex($complexNumber) { if ($complexNumber{0} == '+') { $complexNumber = substr($complexNumber, 1); @@ -841,7 +831,7 @@ class PHPExcel_Calculation_Engineering * @param integer $places The length that we want to pad this value * @return string The padded "number" */ - private static function _nbrConversionFormat($xVal, $places) + private static function nbrConversionFormat($xVal, $places) { if (!is_null($places)) { if (strlen($xVal) <= $places) { @@ -964,7 +954,7 @@ class PHPExcel_Calculation_Engineering } - private static function _Besselk0($fNum) + private static function besselK0($fNum) { if ($fNum <= 2) { $fNum2 = $fNum * 0.5; @@ -982,7 +972,7 @@ class PHPExcel_Calculation_Engineering } - private static function _Besselk1($fNum) + private static function besselK1($fNum) { if ($fNum <= 2) { $fNum2 = $fNum * 0.5; @@ -1031,13 +1021,13 @@ class PHPExcel_Calculation_Engineering switch(floor($ord)) { case 0: - return self::_Besselk0($x); + return self::besselK0($x); case 1: - return self::_Besselk1($x); + return self::besselK1($x); default: $fTox = 2 / $x; - $fBkm = self::_Besselk0($x); - $fBk = self::_Besselk1($x); + $fBkm = self::besselK0($x); + $fBk = self::besselK1($x); for ($n = 1; $n < $ord; ++$n) { $fBkp = $fBkm + $n * $fTox * $fBk; $fBkm = $fBk; @@ -1050,7 +1040,7 @@ class PHPExcel_Calculation_Engineering } - private static function _Bessely0($fNum) + private static function besselY0($fNum) { if ($fNum < 8.0) { $y = ($fNum * $fNum); @@ -1069,7 +1059,7 @@ class PHPExcel_Calculation_Engineering } - private static function _Bessely1($fNum) + private static function besselY1($fNum) { if ($fNum < 8.0) { $y = ($fNum * $fNum); @@ -1115,13 +1105,13 @@ class PHPExcel_Calculation_Engineering switch(floor($ord)) { case 0: - return self::_Bessely0($x); + return self::besselY0($x); case 1: - return self::_Bessely1($x); + return self::besselY1($x); default: $fTox = 2 / $x; - $fBym = self::_Bessely0($x); - $fBy = self::_Bessely1($x); + $fBym = self::besselY0($x); + $fBy = self::besselY1($x); for ($n = 1; $n < $ord; ++$n) { $fByp = $n * $fTox * $fBy - $fBym; $fBym = $fBy; @@ -1232,7 +1222,7 @@ class PHPExcel_Calculation_Engineering } $hexVal = (string) strtoupper(dechex(bindec($x))); - return self::_nbrConversionFormat($hexVal, $places); + return self::nbrConversionFormat($hexVal, $places); } @@ -1287,7 +1277,7 @@ class PHPExcel_Calculation_Engineering } $octVal = (string) decoct(bindec($x)); - return self::_nbrConversionFormat($octVal, $places); + return self::nbrConversionFormat($octVal, $places); } @@ -1344,7 +1334,7 @@ class PHPExcel_Calculation_Engineering return PHPExcel_Calculation_Functions::NaN(); } - return self::_nbrConversionFormat($r, $places); + return self::nbrConversionFormat($r, $places); } @@ -1399,7 +1389,7 @@ class PHPExcel_Calculation_Engineering $r = 'FF'.$r; } - return self::_nbrConversionFormat($r, $places); + return self::nbrConversionFormat($r, $places); } @@ -1454,7 +1444,7 @@ class PHPExcel_Calculation_Engineering $r = substr($r, -10); } - return self::_nbrConversionFormat($r, $places); + return self::nbrConversionFormat($r, $places); } @@ -1503,7 +1493,7 @@ class PHPExcel_Calculation_Engineering } $binVal = decbin(hexdec($x)); - return substr(self::_nbrConversionFormat($binVal, $places), -10); + return substr(self::nbrConversionFormat($binVal, $places), -10); } @@ -1587,7 +1577,7 @@ class PHPExcel_Calculation_Engineering } $octVal = decoct(hexdec($x)); - return self::_nbrConversionFormat($octVal, $places); + return self::nbrConversionFormat($octVal, $places); } // function HEXTOOCT() @@ -1639,7 +1629,7 @@ class PHPExcel_Calculation_Engineering } $r = decbin(octdec($x)); - return self::_nbrConversionFormat($r, $places); + return self::nbrConversionFormat($r, $places); } @@ -1720,7 +1710,7 @@ class PHPExcel_Calculation_Engineering } $hexVal = strtoupper(dechex(octdec($x))); - return self::_nbrConversionFormat($hexVal, $places); + return self::nbrConversionFormat($hexVal, $places); } @@ -1798,7 +1788,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); return $parsedComplex['imaginary']; } @@ -1820,7 +1810,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); return $parsedComplex['real']; } @@ -1840,7 +1830,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); return sqrt( ($parsedComplex['real'] * $parsedComplex['real']) + @@ -1865,7 +1855,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if ($parsedComplex['real'] == 0.0) { if ($parsedComplex['imaginary'] == 0.0) { @@ -1900,12 +1890,12 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if ($parsedComplex['imaginary'] == 0.0) { return $parsedComplex['real']; } else { - return self::_cleanComplex( + return self::cleanComplex( self::COMPLEX( $parsedComplex['real'], 0 - $parsedComplex['imaginary'], @@ -1931,7 +1921,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if ($parsedComplex['imaginary'] == 0.0) { return cos($parsedComplex['real']); @@ -1962,7 +1952,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if ($parsedComplex['imaginary'] == 0.0) { return sin($parsedComplex['real']); @@ -1991,7 +1981,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); $theta = self::IMARGUMENT($complexNumber); $d1 = cos($theta / 2); @@ -2021,7 +2011,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); @@ -2053,7 +2043,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); @@ -2080,7 +2070,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return PHPExcel_Calculation_Functions::NaN(); @@ -2107,7 +2097,7 @@ class PHPExcel_Calculation_Engineering { $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber); - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) { return '1'; @@ -2146,7 +2136,7 @@ class PHPExcel_Calculation_Engineering return PHPExcel_Calculation_Functions::VALUE(); } - $parsedComplex = self::_parseComplex($complexNumber); + $parsedComplex = self::parseComplex($complexNumber); $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])); $rPower = pow($r, $realNumber); @@ -2178,8 +2168,8 @@ class PHPExcel_Calculation_Engineering $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend); $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor); - $parsedComplexDividend = self::_parseComplex($complexDividend); - $parsedComplexDivisor = self::_parseComplex($complexDivisor); + $parsedComplexDividend = self::parseComplex($complexDividend); + $parsedComplexDivisor = self::parseComplex($complexDivisor); if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') && ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) { @@ -2197,9 +2187,9 @@ class PHPExcel_Calculation_Engineering $i = $d2 / $d3; if ($i > 0.0) { - return self::_cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']); + return self::cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']); } elseif ($i < 0.0) { - return self::_cleanComplex($r.$i.$parsedComplexDivisor['suffix']); + return self::cleanComplex($r.$i.$parsedComplexDivisor['suffix']); } else { return $r; } @@ -2223,8 +2213,8 @@ class PHPExcel_Calculation_Engineering $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1); $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2); - $parsedComplex1 = self::_parseComplex($complexNumber1); - $parsedComplex2 = self::_parseComplex($complexNumber2); + $parsedComplex1 = self::parseComplex($complexNumber1); + $parsedComplex2 = self::parseComplex($complexNumber2); if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) && ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) { @@ -2236,7 +2226,7 @@ class PHPExcel_Calculation_Engineering $d1 = $parsedComplex1['real'] - $parsedComplex2['real']; $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary']; - return self::COMPLEX($d1,$d2,$parsedComplex1['suffix']); + return self::COMPLEX($d1, $d2, $parsedComplex1['suffix']); } @@ -2254,13 +2244,13 @@ class PHPExcel_Calculation_Engineering public static function IMSUM() { // Return value - $returnValue = self::_parseComplex('0'); + $returnValue = self::parseComplex('0'); $activeSuffix = ''; // Loop through the arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); foreach ($aArgs as $arg) { - $parsedComplex = self::_parseComplex($arg); + $parsedComplex = self::parseComplex($arg); if ($activeSuffix == '') { $activeSuffix = $parsedComplex['suffix']; @@ -2275,7 +2265,7 @@ class PHPExcel_Calculation_Engineering if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; } - return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix); + return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix); } @@ -2293,13 +2283,13 @@ class PHPExcel_Calculation_Engineering public static function IMPRODUCT() { // Return value - $returnValue = self::_parseComplex('1'); + $returnValue = self::parseComplex('1'); $activeSuffix = ''; // Loop through the arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); foreach ($aArgs as $arg) { - $parsedComplex = self::_parseComplex($arg); + $parsedComplex = self::parseComplex($arg); $workValue = $returnValue; if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) { @@ -2314,7 +2304,7 @@ class PHPExcel_Calculation_Engineering if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; } - return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix); + return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix); } @@ -2369,12 +2359,12 @@ class PHPExcel_Calculation_Engineering // // Private method to calculate the erf value // - private static $_two_sqrtpi = 1.128379167095512574; + private static $twoSqrtPi = 1.128379167095512574; - public static function _erfVal($x) + public static function erfVal($x) { if (abs($x) > 2.2) { - return 1 - self::_erfcVal($x); + return 1 - self::erfcVal($x); } $sum = $term = $x; $xsqr = ($x * $x); @@ -2390,7 +2380,7 @@ class PHPExcel_Calculation_Engineering break; } } while (abs($term / $sum) > PRECISION); - return self::$_two_sqrtpi * $sum; + return self::$twoSqrtPi * $sum; } @@ -2419,10 +2409,10 @@ class PHPExcel_Calculation_Engineering if (is_numeric($lower)) { if (is_null($upper)) { - return self::_erfVal($lower); + return self::erfVal($lower); } if (is_numeric($upper)) { - return self::_erfVal($upper) - self::_erfVal($lower); + return self::erfVal($upper) - self::erfVal($lower); } } return PHPExcel_Calculation_Functions::VALUE(); @@ -2432,12 +2422,12 @@ class PHPExcel_Calculation_Engineering // // Private method to calculate the erfc value // - private static $_one_sqrtpi = 0.564189583547756287; + private static $oneSqrtPi = 0.564189583547756287; - private static function _erfcVal($x) + private static function erfcVal($x) { if (abs($x) < 2.2) { - return 1 - self::_erfVal($x); + return 1 - self::erfVal($x); } if ($x < 0) { return 2 - self::ERFC(-$x); @@ -2458,7 +2448,7 @@ class PHPExcel_Calculation_Engineering $q1 = $q2; $q2 = $b / $d; } while ((abs($q1 - $q2) / $q2) > PRECISION); - return self::$_one_sqrtpi * exp(-$x * $x) * $q2; + return self::$oneSqrtPi * exp(-$x * $x) * $q2; } @@ -2483,7 +2473,7 @@ class PHPExcel_Calculation_Engineering $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); if (is_numeric($x)) { - return self::_erfcVal($x); + return self::erfcVal($x); } return PHPExcel_Calculation_Functions::VALUE(); } @@ -2498,7 +2488,7 @@ class PHPExcel_Calculation_Engineering public static function getConversionGroups() { $conversionGroups = array(); - foreach (self::$_conversionUnits as $conversionUnit) { + foreach (self::$conversionUnits as $conversionUnit) { $conversionGroups[] = $conversionUnit['Group']; } return array_merge(array_unique($conversionGroups)); @@ -2515,7 +2505,7 @@ class PHPExcel_Calculation_Engineering public static function getConversionGroupUnits($group = null) { $conversionGroups = array(); - foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) { + foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) { if ((is_null($group)) || ($conversionGroup['Group'] == $group)) { $conversionGroups[$conversionGroup['Group']][] = $conversionUnit; } @@ -2533,7 +2523,7 @@ class PHPExcel_Calculation_Engineering public static function getConversionGroupUnitDetails($group = null) { $conversionGroups = array(); - foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) { + foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) { if ((is_null($group)) || ($conversionGroup['Group'] == $group)) { $conversionGroups[$conversionGroup['Group']][] = array( 'unit' => $conversionUnit, @@ -2553,7 +2543,7 @@ class PHPExcel_Calculation_Engineering */ public static function getConversionMultipliers() { - return self::$_conversionMultipliers; + return self::$conversionMultipliers; } @@ -2583,18 +2573,18 @@ class PHPExcel_Calculation_Engineering return PHPExcel_Calculation_Functions::VALUE(); } $fromMultiplier = 1.0; - if (isset(self::$_conversionUnits[$fromUOM])) { - $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group']; + if (isset(self::$conversionUnits[$fromUOM])) { + $unitGroup1 = self::$conversionUnits[$fromUOM]['Group']; } else { - $fromMultiplier = substr($fromUOM,0,1); - $fromUOM = substr($fromUOM,1); - if (isset(self::$_conversionMultipliers[$fromMultiplier])) { - $fromMultiplier = self::$_conversionMultipliers[$fromMultiplier]['multiplier']; + $fromMultiplier = substr($fromUOM, 0, 1); + $fromUOM = substr($fromUOM, 1); + if (isset(self::$conversionMultipliers[$fromMultiplier])) { + $fromMultiplier = self::$conversionMultipliers[$fromMultiplier]['multiplier']; } else { return PHPExcel_Calculation_Functions::NA(); } - if ((isset(self::$_conversionUnits[$fromUOM])) && (self::$_conversionUnits[$fromUOM]['AllowPrefix'])) { - $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group']; + if ((isset(self::$conversionUnits[$fromUOM])) && (self::$conversionUnits[$fromUOM]['AllowPrefix'])) { + $unitGroup1 = self::$conversionUnits[$fromUOM]['Group']; } else { return PHPExcel_Calculation_Functions::NA(); } @@ -2602,18 +2592,18 @@ class PHPExcel_Calculation_Engineering $value *= $fromMultiplier; $toMultiplier = 1.0; - if (isset(self::$_conversionUnits[$toUOM])) { - $unitGroup2 = self::$_conversionUnits[$toUOM]['Group']; + if (isset(self::$conversionUnits[$toUOM])) { + $unitGroup2 = self::$conversionUnits[$toUOM]['Group']; } else { - $toMultiplier = substr($toUOM,0,1); - $toUOM = substr($toUOM,1); - if (isset(self::$_conversionMultipliers[$toMultiplier])) { - $toMultiplier = self::$_conversionMultipliers[$toMultiplier]['multiplier']; + $toMultiplier = substr($toUOM, 0, 1); + $toUOM = substr($toUOM, 1); + if (isset(self::$conversionMultipliers[$toMultiplier])) { + $toMultiplier = self::$conversionMultipliers[$toMultiplier]['multiplier']; } else { return PHPExcel_Calculation_Functions::NA(); } - if ((isset(self::$_conversionUnits[$toUOM])) && (self::$_conversionUnits[$toUOM]['AllowPrefix'])) { - $unitGroup2 = self::$_conversionUnits[$toUOM]['Group']; + if ((isset(self::$conversionUnits[$toUOM])) && (self::$conversionUnits[$toUOM]['AllowPrefix'])) { + $unitGroup2 = self::$conversionUnits[$toUOM]['Group']; } else { return PHPExcel_Calculation_Functions::NA(); } @@ -2655,6 +2645,6 @@ class PHPExcel_Calculation_Engineering } return $value + 273.15; } - return ($value * self::$_unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier; + return ($value * self::$unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier; } } diff --git a/Classes/PHPExcel/Calculation/Exception.php b/Classes/PHPExcel/Calculation/Exception.php index bd6e22f1..52d73fc4 100644 --- a/Classes/PHPExcel/Calculation/Exception.php +++ b/Classes/PHPExcel/Calculation/Exception.php @@ -1,6 +1,7 @@ line = $line; $e->file = $file; diff --git a/Classes/PHPExcel/Calculation/ExceptionHandler.php b/Classes/PHPExcel/Calculation/ExceptionHandler.php index 4f3d247d..4cb0a688 100644 --- a/Classes/PHPExcel/Calculation/ExceptionHandler.php +++ b/Classes/PHPExcel/Calculation/ExceptionHandler.php @@ -1,6 +1,7 @@ format('d') == $testDate->format('t')); - } // function _lastDayOfMonth() + } /** - * _firstDayOfMonth + * isFirstDayOfMonth * * Returns a boolean TRUE/FALSE indicating if this date is the first date of the month * * @param DateTime $testDate The date for testing * @return boolean */ - private static function _firstDayOfMonth($testDate) + private static function isFirstDayOfMonth($testDate) { return ($testDate->format('d') == 1); - } // function _firstDayOfMonth() + } - private static function _coupFirstPeriodDate($settlement, $maturity, $frequency, $next) + private static function couponFirstPeriodDate($settlement, $maturity, $frequency, $next) { $months = 12 / $frequency; $result = PHPExcel_Shared_Date::ExcelToPHPObject($maturity); - $eom = self::_lastDayOfMonth($result); + $eom = self::isLastDayOfMonth($result); while ($settlement < PHPExcel_Shared_Date::PHPToExcel($result)) { $result->modify('-'.$months.' months'); @@ -99,10 +89,10 @@ class PHPExcel_Calculation_Financial { } return PHPExcel_Shared_Date::PHPToExcel($result); - } // function _coupFirstPeriodDate() + } - private static function _validFrequency($frequency) + private static function isValidFrequency($frequency) { if (($frequency == 1) || ($frequency == 2) || ($frequency == 4)) { return true; @@ -112,11 +102,11 @@ class PHPExcel_Calculation_Financial { return true; } return false; - } // function _validFrequency() + } /** - * _daysPerYear + * daysPerYear * * Returns the number of days in a specified year, as defined by the "basis" value * @@ -129,28 +119,28 @@ class PHPExcel_Calculation_Financial { * 4 European 360 * @return integer */ - private static function _daysPerYear($year, $basis=0) + private static function daysPerYear($year, $basis = 0) { switch ($basis) { - case 0 : - case 2 : - case 4 : + case 0: + case 2: + case 4: $daysPerYear = 360; break; - case 3 : + case 3: $daysPerYear = 365; break; - case 1 : + case 1: $daysPerYear = (PHPExcel_Calculation_DateTime::isLeapYear($year)) ? 366 : 365; break; - default : + default: return PHPExcel_Calculation_Functions::NaN(); } return $daysPerYear; - } // function _daysPerYear() + } - private static function _interestAndPrincipal($rate=0, $per=0, $nper=0, $pv=0, $fv=0, $type=0) + private static function interestAndPrincipal($rate = 0, $per = 0, $nper = 0, $pv = 0, $fv = 0, $type = 0) { $pmt = self::PMT($rate, $nper, $pv, $fv, $type); $capital = $pv; @@ -160,7 +150,7 @@ class PHPExcel_Calculation_Financial { $capital += $principal; } return array($interest, $principal); - } // function _interestAndPrincipal() + } /** @@ -198,7 +188,7 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function ACCRINT($issue, $firstinterest, $settlement, $rate, $par=1000, $frequency=1, $basis=0) + public static function ACCRINT($issue, $firstinterest, $settlement, $rate, $par = 1000, $frequency = 1, $basis = 0) { $issue = PHPExcel_Calculation_Functions::flattenSingleValue($issue); $firstinterest = PHPExcel_Calculation_Functions::flattenSingleValue($firstinterest); @@ -224,7 +214,7 @@ class PHPExcel_Calculation_Financial { return $par * $rate * $daysBetweenIssueAndSettlement; } return PHPExcel_Calculation_Functions::VALUE(); - } // function ACCRINT() + } /** @@ -250,7 +240,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function ACCRINTM($issue, $settlement, $rate, $par=1000, $basis=0) { + public static function ACCRINTM($issue, $settlement, $rate, $par = 1000, $basis = 0) + { $issue = PHPExcel_Calculation_Functions::flattenSingleValue($issue); $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); @@ -272,7 +263,7 @@ class PHPExcel_Calculation_Financial { return $par * $rate * $daysBetweenIssueAndSettlement; } return PHPExcel_Calculation_Functions::VALUE(); - } // function ACCRINTM() + } /** @@ -306,7 +297,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function AMORDEGRC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis=0) { + public static function AMORDEGRC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis = 0) + { $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); $purchased = PHPExcel_Calculation_Functions::flattenSingleValue($purchased); $firstPeriod = PHPExcel_Calculation_Functions::flattenSingleValue($firstPeriod); @@ -333,27 +325,27 @@ class PHPExcel_Calculation_Financial { } $rate *= $amortiseCoeff; - $fNRate = round(PHPExcel_Calculation_DateTime::YEARFRAC($purchased, $firstPeriod, $basis) * $rate * $cost,0); + $fNRate = round(PHPExcel_Calculation_DateTime::YEARFRAC($purchased, $firstPeriod, $basis) * $rate * $cost, 0); $cost -= $fNRate; $fRest = $cost - $salvage; for ($n = 0; $n < $period; ++$n) { - $fNRate = round($rate * $cost,0); + $fNRate = round($rate * $cost, 0); $fRest -= $fNRate; if ($fRest < 0.0) { switch ($period - $n) { - case 0 : - case 1 : return round($cost * 0.5, 0); - break; - default : return 0.0; - break; + case 0: + case 1: + return round($cost * 0.5, 0); + default: + return 0.0; } } $cost -= $fNRate; } return $fNRate; - } // function AMORDEGRC() + } /** @@ -382,14 +374,15 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function AMORLINC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis=0) { - $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); - $purchased = PHPExcel_Calculation_Functions::flattenSingleValue($purchased); - $firstPeriod = PHPExcel_Calculation_Functions::flattenSingleValue($firstPeriod); - $salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage); - $period = PHPExcel_Calculation_Functions::flattenSingleValue($period); - $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); - $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); + public static function AMORLINC($cost, $purchased, $firstPeriod, $salvage, $period, $rate, $basis = 0) + { + $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); + $purchased = PHPExcel_Calculation_Functions::flattenSingleValue($purchased); + $firstPeriod = PHPExcel_Calculation_Functions::flattenSingleValue($firstPeriod); + $salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage); + $period = PHPExcel_Calculation_Functions::flattenSingleValue($period); + $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); + $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); $fOneRate = $cost * $rate; $fCostDelta = $cost - $salvage; @@ -413,7 +406,7 @@ class PHPExcel_Calculation_Financial { } else { return 0.0; } - } // function AMORLINC() + } /** @@ -448,30 +441,31 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function COUPDAYBS($settlement, $maturity, $frequency, $basis=0) { - $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); - $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); - $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); - $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); + public static function COUPDAYBS($settlement, $maturity, $frequency, $basis = 0) + { + $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); + $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); + $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); + $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } - $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement),$basis); - $prev = self::_coupFirstPeriodDate($settlement, $maturity, $frequency, False); + $daysPerYear = self::daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement), $basis); + $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, false); return PHPExcel_Calculation_DateTime::YEARFRAC($prev, $settlement, $basis) * $daysPerYear; - } // function COUPDAYBS() + } /** @@ -506,42 +500,45 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function COUPDAYS($settlement, $maturity, $frequency, $basis=0) { - $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); - $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); - $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); - $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); + public static function COUPDAYS($settlement, $maturity, $frequency, $basis = 0) + { + $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); + $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); + $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); + $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } switch ($basis) { - case 3: // Actual/365 - return 365 / $frequency; - case 1: // Actual/actual - if ($frequency == 1) { - $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($maturity),$basis); - return ($daysPerYear / $frequency); - } else { - $prev = self::_coupFirstPeriodDate($settlement, $maturity, $frequency, False); - $next = self::_coupFirstPeriodDate($settlement, $maturity, $frequency, True); - return ($next - $prev); - } - default: // US (NASD) 30/360, Actual/360 or European 30/360 - return 360 / $frequency; + case 3: + // Actual/365 + return 365 / $frequency; + case 1: + // Actual/actual + if ($frequency == 1) { + $daysPerYear = self::daysPerYear(PHPExcel_Calculation_DateTime::YEAR($maturity), $basis); + return ($daysPerYear / $frequency); + } + $prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, false); + $next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, true); + return ($next - $prev); + default: + // US (NASD) 30/360, Actual/360 or European 30/360 + return 360 / $frequency; } return PHPExcel_Calculation_Functions::VALUE(); - } // function COUPDAYS() + } /** @@ -576,30 +573,31 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function COUPDAYSNC($settlement, $maturity, $frequency, $basis=0) { - $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); - $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); - $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); - $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); + public static function COUPDAYSNC($settlement, $maturity, $frequency, $basis = 0) + { + $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); + $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); + $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); + $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } - $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement),$basis); - $next = self::_coupFirstPeriodDate($settlement, $maturity, $frequency, True); + $daysPerYear = self::daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement), $basis); + $next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, true); return PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $next, $basis) * $daysPerYear; - } // function COUPDAYSNC() + } /** @@ -635,27 +633,28 @@ class PHPExcel_Calculation_Financial { * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function COUPNCD($settlement, $maturity, $frequency, $basis=0) { + public static function COUPNCD($settlement, $maturity, $frequency, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } - return self::_coupFirstPeriodDate($settlement, $maturity, $frequency, True); - } // function COUPNCD() + return self::couponFirstPeriodDate($settlement, $maturity, $frequency, true); + } /** @@ -691,42 +690,43 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return integer */ - public static function COUPNUM($settlement, $maturity, $frequency, $basis=0) { + public static function COUPNUM($settlement, $maturity, $frequency, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } - $settlement = self::_coupFirstPeriodDate($settlement, $maturity, $frequency, True); + $settlement = self::couponFirstPeriodDate($settlement, $maturity, $frequency, true); $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $maturity, $basis) * 365; switch ($frequency) { case 1: // annual payments - return ceil($daysBetweenSettlementAndMaturity / 360); + return ceil($daysBetweenSettlementAndMaturity / 360); case 2: // half-yearly - return ceil($daysBetweenSettlementAndMaturity / 180); + return ceil($daysBetweenSettlementAndMaturity / 180); case 4: // quarterly - return ceil($daysBetweenSettlementAndMaturity / 90); + return ceil($daysBetweenSettlementAndMaturity / 90); case 6: // bimonthly - return ceil($daysBetweenSettlementAndMaturity / 60); + return ceil($daysBetweenSettlementAndMaturity / 60); case 12: // monthly - return ceil($daysBetweenSettlementAndMaturity / 30); + return ceil($daysBetweenSettlementAndMaturity / 30); } return PHPExcel_Calculation_Functions::VALUE(); - } // function COUPNUM() + } /** @@ -762,27 +762,28 @@ class PHPExcel_Calculation_Financial { * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object, * depending on the value of the ReturnDateType flag */ - public static function COUPPCD($settlement, $maturity, $frequency, $basis=0) { + public static function COUPPCD($settlement, $maturity, $frequency, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } - return self::_coupFirstPeriodDate($settlement, $maturity, $frequency, False); - } // function COUPPCD() + return self::couponFirstPeriodDate($settlement, $maturity, $frequency, false); + } /** @@ -806,7 +807,8 @@ class PHPExcel_Calculation_Financial { * 1 At the beginning of the period. * @return float */ - public static function CUMIPMT($rate, $nper, $pv, $start, $end, $type = 0) { + public static function CUMIPMT($rate, $nper, $pv, $start, $end, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $nper = (int) PHPExcel_Calculation_Functions::flattenSingleValue($nper); $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv); @@ -829,7 +831,7 @@ class PHPExcel_Calculation_Financial { } return $interest; - } // function CUMIPMT() + } /** @@ -853,7 +855,8 @@ class PHPExcel_Calculation_Financial { * 1 At the beginning of the period. * @return float */ - public static function CUMPRINC($rate, $nper, $pv, $start, $end, $type = 0) { + public static function CUMPRINC($rate, $nper, $pv, $start, $end, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $nper = (int) PHPExcel_Calculation_Functions::flattenSingleValue($nper); $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv); @@ -876,7 +879,7 @@ class PHPExcel_Calculation_Financial { } return $principal; - } // function CUMPRINC() + } /** @@ -905,7 +908,8 @@ class PHPExcel_Calculation_Financial { * it defaults to 12. * @return float */ - public static function DB($cost, $salvage, $life, $period, $month=12) { + public static function DB($cost, $salvage, $life, $period, $month = 12) + { $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); $salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage); $life = PHPExcel_Calculation_Functions::flattenSingleValue($life); @@ -914,11 +918,11 @@ class PHPExcel_Calculation_Financial { // Validate if ((is_numeric($cost)) && (is_numeric($salvage)) && (is_numeric($life)) && (is_numeric($period)) && (is_numeric($month))) { - $cost = (float) $cost; - $salvage = (float) $salvage; - $life = (int) $life; - $period = (int) $period; - $month = (int) $month; + $cost = (float) $cost; + $salvage = (float) $salvage; + $life = (int) $life; + $period = (int) $period; + $month = (int) $month; if ($cost == 0) { return 0.0; } elseif (($cost < 0) || (($salvage / $cost) < 0) || ($life <= 0) || ($period < 1) || ($month < 1)) { @@ -941,12 +945,12 @@ class PHPExcel_Calculation_Financial { $previousDepreciation += $depreciation; } if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { - $depreciation = round($depreciation,2); + $depreciation = round($depreciation, 2); } return $depreciation; } return PHPExcel_Calculation_Functions::VALUE(); - } // function DB() + } /** @@ -972,7 +976,8 @@ class PHPExcel_Calculation_Financial { * double-declining balance method). * @return float */ - public static function DDB($cost, $salvage, $life, $period, $factor=2.0) { + public static function DDB($cost, $salvage, $life, $period, $factor = 2.0) + { $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); $salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage); $life = PHPExcel_Calculation_Functions::flattenSingleValue($life); @@ -981,11 +986,11 @@ class PHPExcel_Calculation_Financial { // Validate if ((is_numeric($cost)) && (is_numeric($salvage)) && (is_numeric($life)) && (is_numeric($period)) && (is_numeric($factor))) { - $cost = (float) $cost; - $salvage = (float) $salvage; - $life = (int) $life; - $period = (int) $period; - $factor = (float) $factor; + $cost = (float) $cost; + $salvage = (float) $salvage; + $life = (int) $life; + $period = (int) $period; + $factor = (float) $factor; if (($cost <= 0) || (($salvage / $cost) < 0) || ($life <= 0) || ($period < 1) || ($factor <= 0.0) || ($period > $life)) { return PHPExcel_Calculation_Functions::NaN(); } @@ -996,16 +1001,16 @@ class PHPExcel_Calculation_Financial { // Loop through each period calculating the depreciation $previousDepreciation = 0; for ($per = 1; $per <= $period; ++$per) { - $depreciation = min( ($cost - $previousDepreciation) * ($factor / $life), ($cost - $salvage - $previousDepreciation) ); + $depreciation = min(($cost - $previousDepreciation) * ($factor / $life), ($cost - $salvage - $previousDepreciation)); $previousDepreciation += $depreciation; } if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { - $depreciation = round($depreciation,2); + $depreciation = round($depreciation, 2); } return $depreciation; } return PHPExcel_Calculation_Functions::VALUE(); - } // function DDB() + } /** @@ -1033,7 +1038,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function DISC($settlement, $maturity, $price, $redemption, $basis=0) { + public static function DISC($settlement, $maturity, $price, $redemption, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $price = PHPExcel_Calculation_Functions::flattenSingleValue($price); @@ -1057,7 +1063,7 @@ class PHPExcel_Calculation_Financial { return ((1 - $price / $redemption) / $daysBetweenSettlementAndMaturity); } return PHPExcel_Calculation_Functions::VALUE(); - } // function DISC() + } /** @@ -1076,7 +1082,8 @@ class PHPExcel_Calculation_Financial { * @param integer $fraction Fraction * @return float */ - public static function DOLLARDE($fractional_dollar = Null, $fraction = 0) { + public static function DOLLARDE($fractional_dollar = null, $fraction = 0) + { $fractional_dollar = PHPExcel_Calculation_Functions::flattenSingleValue($fractional_dollar); $fraction = (int)PHPExcel_Calculation_Functions::flattenSingleValue($fraction); @@ -1089,11 +1096,11 @@ class PHPExcel_Calculation_Financial { } $dollars = floor($fractional_dollar); - $cents = fmod($fractional_dollar,1); + $cents = fmod($fractional_dollar, 1); $cents /= $fraction; - $cents *= pow(10,ceil(log10($fraction))); + $cents *= pow(10, ceil(log10($fraction))); return $dollars + $cents; - } // function DOLLARDE() + } /** @@ -1112,7 +1119,8 @@ class PHPExcel_Calculation_Financial { * @param integer $fraction Fraction * @return float */ - public static function DOLLARFR($decimal_dollar = Null, $fraction = 0) { + public static function DOLLARFR($decimal_dollar = null, $fraction = 0) + { $decimal_dollar = PHPExcel_Calculation_Functions::flattenSingleValue($decimal_dollar); $fraction = (int)PHPExcel_Calculation_Functions::flattenSingleValue($fraction); @@ -1125,11 +1133,11 @@ class PHPExcel_Calculation_Financial { } $dollars = floor($decimal_dollar); - $cents = fmod($decimal_dollar,1); + $cents = fmod($decimal_dollar, 1); $cents *= $fraction; - $cents *= pow(10,-ceil(log10($fraction))); + $cents *= pow(10, -ceil(log10($fraction))); return $dollars + $cents; - } // function DOLLARFR() + } /** @@ -1147,7 +1155,8 @@ class PHPExcel_Calculation_Financial { * @param integer $npery Number of compounding payments per year * @return float */ - public static function EFFECT($nominal_rate = 0, $npery = 0) { + public static function EFFECT($nominal_rate = 0, $npery = 0) + { $nominal_rate = PHPExcel_Calculation_Functions::flattenSingleValue($nominal_rate); $npery = (int)PHPExcel_Calculation_Functions::flattenSingleValue($npery); @@ -1157,7 +1166,7 @@ class PHPExcel_Calculation_Financial { } return pow((1 + $nominal_rate / $npery), $npery) - 1; - } // function EFFECT() + } /** @@ -1182,7 +1191,8 @@ class PHPExcel_Calculation_Financial { * 1 At the beginning of the period. * @return float */ - public static function FV($rate = 0, $nper = 0, $pmt = 0, $pv = 0, $type = 0) { + public static function FV($rate = 0, $nper = 0, $pmt = 0, $pv = 0, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $nper = PHPExcel_Calculation_Functions::flattenSingleValue($nper); $pmt = PHPExcel_Calculation_Functions::flattenSingleValue($pmt); @@ -1197,10 +1207,9 @@ class PHPExcel_Calculation_Financial { // Calculate if (!is_null($rate) && $rate != 0) { return -$pv * pow(1 + $rate, $nper) - $pmt * (1 + $rate * $type) * (pow(1 + $rate, $nper) - 1) / $rate; - } else { - return -$pv - $pmt * $nper; } - } // function FV() + return -$pv - $pmt * $nper; + } /** @@ -1216,16 +1225,17 @@ class PHPExcel_Calculation_Financial { * @param float[] $schedule An array of interest rates to apply. * @return float */ - public static function FVSCHEDULE($principal, $schedule) { + public static function FVSCHEDULE($principal, $schedule) + { $principal = PHPExcel_Calculation_Functions::flattenSingleValue($principal); $schedule = PHPExcel_Calculation_Functions::flattenArray($schedule); - foreach($schedule as $rate) { + foreach ($schedule as $rate) { $principal *= 1 + $rate; } return $principal; - } // function FVSCHEDULE() + } /** @@ -1250,7 +1260,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function INTRATE($settlement, $maturity, $investment, $redemption, $basis=0) { + public static function INTRATE($settlement, $maturity, $investment, $redemption, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $investment = PHPExcel_Calculation_Functions::flattenSingleValue($investment); @@ -1274,7 +1285,7 @@ class PHPExcel_Calculation_Financial { return (($redemption / $investment) - 1) / ($daysBetweenSettlementAndMaturity); } return PHPExcel_Calculation_Functions::VALUE(); - } // function INTRATE() + } /** @@ -1293,7 +1304,8 @@ class PHPExcel_Calculation_Financial { * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float */ - public static function IPMT($rate, $per, $nper, $pv, $fv = 0, $type = 0) { + public static function IPMT($rate, $per, $nper, $pv, $fv = 0, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $per = (int) PHPExcel_Calculation_Functions::flattenSingleValue($per); $nper = (int) PHPExcel_Calculation_Functions::flattenSingleValue($nper); @@ -1310,17 +1322,17 @@ class PHPExcel_Calculation_Financial { } // Calculate - $interestAndPrincipal = self::_interestAndPrincipal($rate, $per, $nper, $pv, $fv, $type); + $interestAndPrincipal = self::interestAndPrincipal($rate, $per, $nper, $pv, $fv, $type); return $interestAndPrincipal[0]; - } // function IPMT() + } /** * IRR * - * Returns the internal rate of return for a series of cash flows represented by the numbers in values. - * These cash flows do not have to be even, as they would be for an annuity. However, the cash flows must occur + * Returns the internal rate of return for a series of cash flows represented by the numbers in values. + * These cash flows do not have to be even, as they would be for an annuity. However, the cash flows must occur * at regular intervals, such as monthly or annually. The internal rate of return is the interest rate received - * for an investment consisting of payments (negative values) and income (positive values) that occur at regular + * for an investment consisting of payments (negative values) and income (positive values) that occur at regular * periods. * * Excel Function: @@ -1328,13 +1340,16 @@ class PHPExcel_Calculation_Financial { * * @param float[] $values An array or a reference to cells that contain numbers for which you want * to calculate the internal rate of return. - * Values must contain at least one positive value and one negative value to + * Values must contain at least one positive value and one negative value to * calculate the internal rate of return. * @param float $guess A number that you guess is close to the result of IRR * @return float */ - public static function IRR($values, $guess = 0.1) { - if (!is_array($values)) return PHPExcel_Calculation_Functions::VALUE(); + public static function IRR($values, $guess = 0.1) + { + if (!is_array($values)) { + return PHPExcel_Calculation_Functions::VALUE(); + } $values = PHPExcel_Calculation_Functions::flattenArray($values); $guess = PHPExcel_Calculation_Functions::flattenSingleValue($guess); @@ -1344,14 +1359,18 @@ class PHPExcel_Calculation_Financial { $f1 = self::NPV($x1, $values); $f2 = self::NPV($x2, $values); for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { - if (($f1 * $f2) < 0.0) break; + if (($f1 * $f2) < 0.0) { + break; + } if (abs($f1) < abs($f2)) { $f1 = self::NPV($x1 += 1.6 * ($x1 - $x2), $values); } else { $f2 = self::NPV($x2 += 1.6 * ($x2 - $x1), $values); } } - if (($f1 * $f2) > 0.0) return PHPExcel_Calculation_Functions::VALUE(); + if (($f1 * $f2) > 0.0) { + return PHPExcel_Calculation_Functions::VALUE(); + } $f = self::NPV($x1, $values); if ($f < 0.0) { @@ -1362,17 +1381,19 @@ class PHPExcel_Calculation_Financial { $dx = $x1 - $x2; } - for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { + for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { $dx *= 0.5; $x_mid = $rtb + $dx; $f_mid = self::NPV($x_mid, $values); - if ($f_mid <= 0.0) + if ($f_mid <= 0.0) { $rtb = $x_mid; - if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) + } + if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) { return $x_mid; + } } return PHPExcel_Calculation_Functions::VALUE(); - } // function IRR() + } /** @@ -1391,7 +1412,8 @@ class PHPExcel_Calculation_Financial { * * PV is the loan amount or present value of the payments */ - public static function ISPMT() { + public static function ISPMT() + { // Return value $returnValue = 0; @@ -1404,22 +1426,22 @@ class PHPExcel_Calculation_Financial { // Calculate $principlePayment = ($principleRemaining * 1.0) / ($numberPeriods * 1.0); - for($i=0; $i <= $period; ++$i) { + for ($i=0; $i <= $period; ++$i) { $returnValue = $interestRate * $principleRemaining * -1; $principleRemaining -= $principlePayment; // principle needs to be 0 after the last payment, don't let floating point screw it up - if($i == $numberPeriods) { + if ($i == $numberPeriods) { $returnValue = 0; } } return($returnValue); - } // function ISPMT() + } /** * MIRR * - * Returns the modified internal rate of return for a series of periodic cash flows. MIRR considers both + * Returns the modified internal rate of return for a series of periodic cash flows. MIRR considers both * the cost of the investment and the interest received on reinvestment of cash. * * Excel Function: @@ -1432,8 +1454,11 @@ class PHPExcel_Calculation_Financial { * @param float $reinvestment_rate The interest rate you receive on the cash flows as you reinvest them * @return float */ - public static function MIRR($values, $finance_rate, $reinvestment_rate) { - if (!is_array($values)) return PHPExcel_Calculation_Functions::VALUE(); + public static function MIRR($values, $finance_rate, $reinvestment_rate) + { + if (!is_array($values)) { + return PHPExcel_Calculation_Functions::VALUE(); + } $values = PHPExcel_Calculation_Functions::flattenArray($values); $finance_rate = PHPExcel_Calculation_Functions::flattenSingleValue($finance_rate); $reinvestment_rate = PHPExcel_Calculation_Functions::flattenSingleValue($reinvestment_rate); @@ -1443,7 +1468,7 @@ class PHPExcel_Calculation_Financial { $fr = 1.0 + $finance_rate; $npv_pos = $npv_neg = 0.0; - foreach($values as $i => $v) { + foreach ($values as $i => $v) { if ($v >= 0) { $npv_pos += $v / pow($rr, $i); } else { @@ -1459,7 +1484,7 @@ class PHPExcel_Calculation_Financial { / ($npv_neg * ($rr)), (1.0 / ($n - 1))) - 1.0; return (is_finite($mirr) ? $mirr : PHPExcel_Calculation_Functions::VALUE()); - } // function MIRR() + } /** @@ -1471,7 +1496,8 @@ class PHPExcel_Calculation_Financial { * @param int $npery Number of compounding payments per year * @return float */ - public static function NOMINAL($effect_rate = 0, $npery = 0) { + public static function NOMINAL($effect_rate = 0, $npery = 0) + { $effect_rate = PHPExcel_Calculation_Functions::flattenSingleValue($effect_rate); $npery = (int)PHPExcel_Calculation_Functions::flattenSingleValue($npery); @@ -1482,7 +1508,7 @@ class PHPExcel_Calculation_Financial { // Calculate return $npery * (pow($effect_rate + 1, 1 / $npery) - 1); - } // function NOMINAL() + } /** @@ -1497,7 +1523,8 @@ class PHPExcel_Calculation_Financial { * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float */ - public static function NPER($rate = 0, $pmt = 0, $pv = 0, $fv = 0, $type = 0) { + public static function NPER($rate = 0, $pmt = 0, $pv = 0, $fv = 0, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $pmt = PHPExcel_Calculation_Functions::flattenSingleValue($pmt); $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv); @@ -1515,13 +1542,12 @@ class PHPExcel_Calculation_Financial { return PHPExcel_Calculation_Functions::NaN(); } return log(($pmt * (1 + $rate * $type) / $rate - $fv) / ($pv + $pmt * (1 + $rate * $type) / $rate)) / log(1 + $rate); - } else { - if ($pmt == 0) { - return PHPExcel_Calculation_Functions::NaN(); - } - return (-$pv -$fv) / $pmt; } - } // function NPER() + if ($pmt == 0) { + return PHPExcel_Calculation_Functions::NaN(); + } + return (-$pv -$fv) / $pmt; + } /** * NPV @@ -1530,7 +1556,8 @@ class PHPExcel_Calculation_Financial { * * @return float */ - public static function NPV() { + public static function NPV() + { // Return value $returnValue = 0; @@ -1548,7 +1575,7 @@ class PHPExcel_Calculation_Financial { // Return return $returnValue; - } // function NPV() + } /** * PMT @@ -1562,7 +1589,8 @@ class PHPExcel_Calculation_Financial { * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float */ - public static function PMT($rate = 0, $nper = 0, $pv = 0, $fv = 0, $type = 0) { + public static function PMT($rate = 0, $nper = 0, $pv = 0, $fv = 0, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $nper = PHPExcel_Calculation_Functions::flattenSingleValue($nper); $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv); @@ -1577,10 +1605,9 @@ class PHPExcel_Calculation_Financial { // Calculate if (!is_null($rate) && $rate != 0) { return (-$fv - $pv * pow(1 + $rate, $nper)) / (1 + $rate * $type) / ((pow(1 + $rate, $nper) - 1) / $rate); - } else { - return (-$pv - $fv) / $nper; } - } // function PMT() + return (-$pv - $fv) / $nper; + } /** @@ -1596,7 +1623,8 @@ class PHPExcel_Calculation_Financial { * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float */ - public static function PPMT($rate, $per, $nper, $pv, $fv = 0, $type = 0) { + public static function PPMT($rate, $per, $nper, $pv, $fv = 0, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $per = (int) PHPExcel_Calculation_Functions::flattenSingleValue($per); $nper = (int) PHPExcel_Calculation_Functions::flattenSingleValue($nper); @@ -1613,12 +1641,13 @@ class PHPExcel_Calculation_Financial { } // Calculate - $interestAndPrincipal = self::_interestAndPrincipal($rate, $per, $nper, $pv, $fv, $type); + $interestAndPrincipal = self::interestAndPrincipal($rate, $per, $nper, $pv, $fv, $type); return $interestAndPrincipal[1]; - } // function PPMT() + } - public static function PRICE($settlement, $maturity, $rate, $yield, $redemption, $frequency, $basis=0) { + public static function PRICE($settlement, $maturity, $rate, $yield, $redemption, $frequency, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $rate = (float) PHPExcel_Calculation_Functions::flattenSingleValue($rate); @@ -1627,15 +1656,15 @@ class PHPExcel_Calculation_Financial { $frequency = (int) PHPExcel_Calculation_Functions::flattenSingleValue($frequency); $basis = (is_null($basis)) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($basis); - if (is_string($settlement = PHPExcel_Calculation_DateTime::_getDateValue($settlement))) { + if (is_string($settlement = PHPExcel_Calculation_DateTime::getDateValue($settlement))) { return PHPExcel_Calculation_Functions::VALUE(); } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } if (($settlement > $maturity) || - (!self::_validFrequency($frequency)) || + (!self::isValidFrequency($frequency)) || (($basis < 0) || ($basis > 4))) { return PHPExcel_Calculation_Functions::NaN(); } @@ -1650,13 +1679,13 @@ class PHPExcel_Calculation_Financial { $de = $dsc / $e; $result = $redemption / pow($baseYF, (--$n + $de)); - for($k = 0; $k <= $n; ++$k) { + for ($k = 0; $k <= $n; ++$k) { $result += $rfp / (pow($baseYF, ($k + $de))); } $result -= $rfp * ($a / $e); return $result; - } // function PRICE() + } /** @@ -1678,7 +1707,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function PRICEDISC($settlement, $maturity, $discount, $redemption, $basis=0) { + public static function PRICEDISC($settlement, $maturity, $discount, $redemption, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $discount = (float) PHPExcel_Calculation_Functions::flattenSingleValue($discount); @@ -1699,7 +1729,7 @@ class PHPExcel_Calculation_Financial { return $redemption * (1 - $discount * $daysBetweenSettlementAndMaturity); } return PHPExcel_Calculation_Functions::VALUE(); - } // function PRICEDISC() + } /** @@ -1722,7 +1752,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function PRICEMAT($settlement, $maturity, $issue, $rate, $yield, $basis=0) { + public static function PRICEMAT($settlement, $maturity, $issue, $rate, $yield, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $issue = PHPExcel_Calculation_Functions::flattenSingleValue($issue); @@ -1735,7 +1766,7 @@ class PHPExcel_Calculation_Financial { if (($rate <= 0) || ($yield <= 0)) { return PHPExcel_Calculation_Functions::NaN(); } - $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement),$basis); + $daysPerYear = self::daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement), $basis); if (!is_numeric($daysPerYear)) { return $daysPerYear; } @@ -1763,7 +1794,7 @@ class PHPExcel_Calculation_Financial { (($daysBetweenIssueAndSettlement / $daysPerYear) * $rate * 100)); } return PHPExcel_Calculation_Functions::VALUE(); - } // function PRICEMAT() + } /** @@ -1778,7 +1809,8 @@ class PHPExcel_Calculation_Financial { * @param int $type Payment type: 0 = at the end of each period, 1 = at the beginning of each period * @return float */ - public static function PV($rate = 0, $nper = 0, $pmt = 0, $fv = 0, $type = 0) { + public static function PV($rate = 0, $nper = 0, $pmt = 0, $fv = 0, $type = 0) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); $nper = PHPExcel_Calculation_Functions::flattenSingleValue($nper); $pmt = PHPExcel_Calculation_Functions::flattenSingleValue($pmt); @@ -1793,10 +1825,9 @@ class PHPExcel_Calculation_Financial { // Calculate if (!is_null($rate) && $rate != 0) { return (-$pmt * (1 + $rate * $type) * ((pow(1 + $rate, $nper) - 1) / $rate) - $fv) / pow(1 + $rate, $nper); - } else { - return -$fv - $pmt * $nper; } - } // function PV() + return -$fv - $pmt * $nper; + } /** @@ -1829,7 +1860,8 @@ class PHPExcel_Calculation_Financial { * If you omit guess, it is assumed to be 10 percent. * @return float **/ - public static function RATE($nper, $pmt, $pv, $fv = 0.0, $type = 0, $guess = 0.1) { + public static function RATE($nper, $pmt, $pv, $fv = 0.0, $type = 0, $guess = 0.1) + { $nper = (int) PHPExcel_Calculation_Functions::flattenSingleValue($nper); $pmt = PHPExcel_Calculation_Functions::flattenSingleValue($pmt); $pv = PHPExcel_Calculation_Functions::flattenSingleValue($pv); @@ -1854,9 +1886,9 @@ class PHPExcel_Calculation_Financial { $rate = ($y1 * $x0 - $y0 * $x1) / ($y1 - $y0); $x0 = $x1; $x1 = $rate; - if (($nper * abs($pmt)) > ($pv - $fv)) + if (($nper * abs($pmt)) > ($pv - $fv)) { $x1 = abs($x1); - + } if (abs($rate) < FINANCIAL_PRECISION) { $y = $pv * (1 + $nper * $rate) + $pmt * (1 + $rate * $type) * $nper + $fv; } else { @@ -1869,7 +1901,7 @@ class PHPExcel_Calculation_Financial { ++$i; } return $rate; - } // function RATE() + } /** @@ -1891,7 +1923,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function RECEIVED($settlement, $maturity, $investment, $discount, $basis=0) { + public static function RECEIVED($settlement, $maturity, $investment, $discount, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $investment = (float) PHPExcel_Calculation_Functions::flattenSingleValue($investment); @@ -1912,7 +1945,7 @@ class PHPExcel_Calculation_Financial { return $investment / ( 1 - ($discount * $daysBetweenSettlementAndMaturity)); } return PHPExcel_Calculation_Functions::VALUE(); - } // function RECEIVED() + } /** @@ -1925,7 +1958,8 @@ class PHPExcel_Calculation_Financial { * @param life Number of periods over which the asset is depreciated * @return float */ - public static function SLN($cost, $salvage, $life) { + public static function SLN($cost, $salvage, $life) + { $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); $salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage); $life = PHPExcel_Calculation_Functions::flattenSingleValue($life); @@ -1938,7 +1972,7 @@ class PHPExcel_Calculation_Financial { return ($cost - $salvage) / $life; } return PHPExcel_Calculation_Functions::VALUE(); - } // function SLN() + } /** @@ -1952,7 +1986,8 @@ class PHPExcel_Calculation_Financial { * @param period Period * @return float */ - public static function SYD($cost, $salvage, $life, $period) { + public static function SYD($cost, $salvage, $life, $period) + { $cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost); $salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage); $life = PHPExcel_Calculation_Functions::flattenSingleValue($life); @@ -1966,7 +2001,7 @@ class PHPExcel_Calculation_Financial { return (($cost - $salvage) * ($life - $period + 1) * 2) / ($life * ($life + 1)); } return PHPExcel_Calculation_Functions::VALUE(); - } // function SYD() + } /** @@ -1981,7 +2016,8 @@ class PHPExcel_Calculation_Financial { * @param int discount The Treasury bill's discount rate. * @return float */ - public static function TBILLEQ($settlement, $maturity, $discount) { + public static function TBILLEQ($settlement, $maturity, $discount) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $discount = PHPExcel_Calculation_Functions::flattenSingleValue($discount); @@ -1992,7 +2028,7 @@ class PHPExcel_Calculation_Financial { return $testValue; } - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } @@ -2000,11 +2036,11 @@ class PHPExcel_Calculation_Financial { ++$maturity; $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $maturity) * 360; } else { - $daysBetweenSettlementAndMaturity = (PHPExcel_Calculation_DateTime::_getDateValue($maturity) - PHPExcel_Calculation_DateTime::_getDateValue($settlement)); + $daysBetweenSettlementAndMaturity = (PHPExcel_Calculation_DateTime::getDateValue($maturity) - PHPExcel_Calculation_DateTime::getDateValue($settlement)); } return (365 * $discount) / (360 - $discount * $daysBetweenSettlementAndMaturity); - } // function TBILLEQ() + } /** @@ -2019,12 +2055,13 @@ class PHPExcel_Calculation_Financial { * @param int discount The Treasury bill's discount rate. * @return float */ - public static function TBILLPRICE($settlement, $maturity, $discount) { + public static function TBILLPRICE($settlement, $maturity, $discount) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $discount = PHPExcel_Calculation_Functions::flattenSingleValue($discount); - if (is_string($maturity = PHPExcel_Calculation_DateTime::_getDateValue($maturity))) { + if (is_string($maturity = PHPExcel_Calculation_DateTime::getDateValue($maturity))) { return PHPExcel_Calculation_Functions::VALUE(); } @@ -2042,7 +2079,7 @@ class PHPExcel_Calculation_Financial { return $daysBetweenSettlementAndMaturity; } } else { - $daysBetweenSettlementAndMaturity = (PHPExcel_Calculation_DateTime::_getDateValue($maturity) - PHPExcel_Calculation_DateTime::_getDateValue($settlement)); + $daysBetweenSettlementAndMaturity = (PHPExcel_Calculation_DateTime::getDateValue($maturity) - PHPExcel_Calculation_DateTime::getDateValue($settlement)); } if ($daysBetweenSettlementAndMaturity > 360) { @@ -2056,7 +2093,7 @@ class PHPExcel_Calculation_Financial { return $price; } return PHPExcel_Calculation_Functions::VALUE(); - } // function TBILLPRICE() + } /** @@ -2071,7 +2108,8 @@ class PHPExcel_Calculation_Financial { * @param int price The Treasury bill's price per $100 face value. * @return float */ - public static function TBILLYIELD($settlement, $maturity, $price) { + public static function TBILLYIELD($settlement, $maturity, $price) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $price = PHPExcel_Calculation_Functions::flattenSingleValue($price); @@ -2090,7 +2128,7 @@ class PHPExcel_Calculation_Financial { return $daysBetweenSettlementAndMaturity; } } else { - $daysBetweenSettlementAndMaturity = (PHPExcel_Calculation_DateTime::_getDateValue($maturity) - PHPExcel_Calculation_DateTime::_getDateValue($settlement)); + $daysBetweenSettlementAndMaturity = (PHPExcel_Calculation_DateTime::getDateValue($maturity) - PHPExcel_Calculation_DateTime::getDateValue($settlement)); } if ($daysBetweenSettlementAndMaturity > 360) { @@ -2100,15 +2138,20 @@ class PHPExcel_Calculation_Financial { return ((100 - $price) / $price) * (360 / $daysBetweenSettlementAndMaturity); } return PHPExcel_Calculation_Functions::VALUE(); - } // function TBILLYIELD() + } - public static function XIRR($values, $dates, $guess = 0.1) { - if ((!is_array($values)) && (!is_array($dates))) return PHPExcel_Calculation_Functions::VALUE(); + public static function XIRR($values, $dates, $guess = 0.1) + { + if ((!is_array($values)) && (!is_array($dates))) { + return PHPExcel_Calculation_Functions::VALUE(); + } $values = PHPExcel_Calculation_Functions::flattenArray($values); $dates = PHPExcel_Calculation_Functions::flattenArray($dates); $guess = PHPExcel_Calculation_Functions::flattenSingleValue($guess); - if (count($values) != count($dates)) return PHPExcel_Calculation_Functions::NaN(); + if (count($values) != count($dates)) { + return PHPExcel_Calculation_Functions::NaN(); + } // create an initial range, with a root somewhere between 0 and guess $x1 = 0.0; @@ -2116,14 +2159,17 @@ class PHPExcel_Calculation_Financial { $f1 = self::XNPV($x1, $values, $dates); $f2 = self::XNPV($x2, $values, $dates); for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { - if (($f1 * $f2) < 0.0) break; - if (abs($f1) < abs($f2)) { + if (($f1 * $f2) < 0.0) { + break; + } elseif (abs($f1) < abs($f2)) { $f1 = self::XNPV($x1 += 1.6 * ($x1 - $x2), $values, $dates); } else { $f2 = self::XNPV($x2 += 1.6 * ($x2 - $x1), $values, $dates); } } - if (($f1 * $f2) > 0.0) return PHPExcel_Calculation_Functions::VALUE(); + if (($f1 * $f2) > 0.0) { + return PHPExcel_Calculation_Functions::VALUE(); + } $f = self::XNPV($x1, $values, $dates); if ($f < 0.0) { @@ -2134,12 +2180,16 @@ class PHPExcel_Calculation_Financial { $dx = $x1 - $x2; } - for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { + for ($i = 0; $i < FINANCIAL_MAX_ITERATIONS; ++$i) { $dx *= 0.5; $x_mid = $rtb + $dx; $f_mid = self::XNPV($x_mid, $values, $dates); - if ($f_mid <= 0.0) $rtb = $x_mid; - if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) return $x_mid; + if ($f_mid <= 0.0) { + $rtb = $x_mid; + } + if ((abs($f_mid) < FINANCIAL_PRECISION) || (abs($dx) < FINANCIAL_PRECISION)) { + return $x_mid; + } } return PHPExcel_Calculation_Functions::VALUE(); } @@ -2155,27 +2205,43 @@ class PHPExcel_Calculation_Financial { * =XNPV(rate,values,dates) * * @param float $rate The discount rate to apply to the cash flows. - * @param array of float $values A series of cash flows that corresponds to a schedule of payments in dates. The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. The series of values must contain at least one positive value and one negative value. - * @param array of mixed $dates A schedule of payment dates that corresponds to the cash flow payments. The first payment date indicates the beginning of the schedule of payments. All other dates must be later than this date, but they may occur in any order. + * @param array of float $values A series of cash flows that corresponds to a schedule of payments in dates. + * The first payment is optional and corresponds to a cost or payment that occurs at the beginning of the investment. + * If the first value is a cost or payment, it must be a negative value. All succeeding payments are discounted based on a 365-day year. + * The series of values must contain at least one positive value and one negative value. + * @param array of mixed $dates A schedule of payment dates that corresponds to the cash flow payments. + * The first payment date indicates the beginning of the schedule of payments. + * All other dates must be later than this date, but they may occur in any order. * @return float */ - public static function XNPV($rate, $values, $dates) { + public static function XNPV($rate, $values, $dates) + { $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate); - if (!is_numeric($rate)) return PHPExcel_Calculation_Functions::VALUE(); - if ((!is_array($values)) || (!is_array($dates))) return PHPExcel_Calculation_Functions::VALUE(); + if (!is_numeric($rate)) { + return PHPExcel_Calculation_Functions::VALUE(); + } + if ((!is_array($values)) || (!is_array($dates))) { + return PHPExcel_Calculation_Functions::VALUE(); + } $values = PHPExcel_Calculation_Functions::flattenArray($values); $dates = PHPExcel_Calculation_Functions::flattenArray($dates); $valCount = count($values); - if ($valCount != count($dates)) return PHPExcel_Calculation_Functions::NaN(); - if ((min($values) > 0) || (max($values) < 0)) return PHPExcel_Calculation_Functions::VALUE(); + if ($valCount != count($dates)) { + return PHPExcel_Calculation_Functions::NaN(); + } + if ((min($values) > 0) || (max($values) < 0)) { + return PHPExcel_Calculation_Functions::VALUE(); + } $xnpv = 0.0; for ($i = 0; $i < $valCount; ++$i) { - if (!is_numeric($values[$i])) return PHPExcel_Calculation_Functions::VALUE(); - $xnpv += $values[$i] / pow(1 + $rate, PHPExcel_Calculation_DateTime::DATEDIF($dates[0],$dates[$i],'d') / 365); + if (!is_numeric($values[$i])) { + return PHPExcel_Calculation_Functions::VALUE(); + } + $xnpv += $values[$i] / pow(1 + $rate, PHPExcel_Calculation_DateTime::DATEDIF($dates[0], $dates[$i], 'd') / 365); } return (is_finite($xnpv)) ? $xnpv : PHPExcel_Calculation_Functions::VALUE(); - } // function XNPV() + } /** @@ -2183,13 +2249,13 @@ class PHPExcel_Calculation_Financial { * * Returns the annual yield of a security that pays interest at maturity. * - * @param mixed settlement The security's settlement date. - * The security's settlement date is the date after the issue date when the security is traded to the buyer. - * @param mixed maturity The security's maturity date. - * The maturity date is the date when the security expires. - * @param int price The security's price per $100 face value. + * @param mixed settlement The security's settlement date. + * The security's settlement date is the date after the issue date when the security is traded to the buyer. + * @param mixed maturity The security's maturity date. + * The maturity date is the date when the security expires. + * @param int price The security's price per $100 face value. * @param int redemption The security's redemption value per $100 face value. - * @param int basis The type of day count to use. + * @param int basis The type of day count to use. * 0 or omitted US (NASD) 30/360 * 1 Actual/actual * 2 Actual/360 @@ -2197,7 +2263,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function YIELDDISC($settlement, $maturity, $price, $redemption, $basis=0) { + public static function YIELDDISC($settlement, $maturity, $price, $redemption, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $price = PHPExcel_Calculation_Functions::flattenSingleValue($price); @@ -2209,11 +2276,11 @@ class PHPExcel_Calculation_Financial { if (($price <= 0) || ($redemption <= 0)) { return PHPExcel_Calculation_Functions::NaN(); } - $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement),$basis); + $daysPerYear = self::daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement), $basis); if (!is_numeric($daysPerYear)) { return $daysPerYear; } - $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $maturity,$basis); + $daysBetweenSettlementAndMaturity = PHPExcel_Calculation_DateTime::YEARFRAC($settlement, $maturity, $basis); if (!is_numeric($daysBetweenSettlementAndMaturity)) { // return date error return $daysBetweenSettlementAndMaturity; @@ -2223,7 +2290,7 @@ class PHPExcel_Calculation_Financial { return (($redemption - $price) / $price) * ($daysPerYear / $daysBetweenSettlementAndMaturity); } return PHPExcel_Calculation_Functions::VALUE(); - } // function YIELDDISC() + } /** @@ -2231,12 +2298,12 @@ class PHPExcel_Calculation_Financial { * * Returns the annual yield of a security that pays interest at maturity. * - * @param mixed settlement The security's settlement date. - * The security's settlement date is the date after the issue date when the security is traded to the buyer. - * @param mixed maturity The security's maturity date. - * The maturity date is the date when the security expires. - * @param mixed issue The security's issue date. - * @param int rate The security's interest rate at date of issue. + * @param mixed settlement The security's settlement date. + * The security's settlement date is the date after the issue date when the security is traded to the buyer. + * @param mixed maturity The security's maturity date. + * The maturity date is the date when the security expires. + * @param mixed issue The security's issue date. + * @param int rate The security's interest rate at date of issue. * @param int price The security's price per $100 face value. * @param int basis The type of day count to use. * 0 or omitted US (NASD) 30/360 @@ -2246,7 +2313,8 @@ class PHPExcel_Calculation_Financial { * 4 European 30/360 * @return float */ - public static function YIELDMAT($settlement, $maturity, $issue, $rate, $price, $basis=0) { + public static function YIELDMAT($settlement, $maturity, $issue, $rate, $price, $basis = 0) + { $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement); $maturity = PHPExcel_Calculation_Functions::flattenSingleValue($maturity); $issue = PHPExcel_Calculation_Functions::flattenSingleValue($issue); @@ -2259,7 +2327,7 @@ class PHPExcel_Calculation_Financial { if (($rate <= 0) || ($price <= 0)) { return PHPExcel_Calculation_Functions::NaN(); } - $daysPerYear = self::_daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement),$basis); + $daysPerYear = self::daysPerYear(PHPExcel_Calculation_DateTime::YEAR($settlement), $basis); if (!is_numeric($daysPerYear)) { return $daysPerYear; } @@ -2287,6 +2355,5 @@ class PHPExcel_Calculation_Financial { ($daysPerYear / $daysBetweenSettlementAndMaturity); } return PHPExcel_Calculation_Functions::VALUE(); - } // function YIELDMAT() - -} // class PHPExcel_Calculation_Financial + } +} diff --git a/Classes/PHPExcel/Calculation/FormulaParser.php b/Classes/PHPExcel/Calculation/FormulaParser.php index 1a97c7d6..893f19e9 100644 --- a/Classes/PHPExcel/Calculation/FormulaParser.php +++ b/Classes/PHPExcel/Calculation/FormulaParser.php @@ -1,30 +1,4 @@ _formula = trim($pFormula); + $this->formula = trim($pFormula); // Parse! - $this->_parseToTokens(); + $this->parseToTokens(); } /** @@ -113,8 +108,9 @@ class PHPExcel_Calculation_FormulaParser { * * @return string */ - public function getFormula() { - return $this->_formula; + public function getFormula() + { + return $this->formula; } /** @@ -124,9 +120,10 @@ class PHPExcel_Calculation_FormulaParser { * @return string * @throws PHPExcel_Calculation_Exception */ - public function getToken($pId = 0) { - if (isset($this->_tokens[$pId])) { - return $this->_tokens[$pId]; + public function getToken($pId = 0) + { + if (isset($this->tokens[$pId])) { + return $this->tokens[$pId]; } else { throw new PHPExcel_Calculation_Exception("Token with id $pId does not exist."); } @@ -137,8 +134,9 @@ class PHPExcel_Calculation_FormulaParser { * * @return string */ - public function getTokenCount() { - return count($this->_tokens); + public function getTokenCount() + { + return count($this->tokens); } /** @@ -146,20 +144,24 @@ class PHPExcel_Calculation_FormulaParser { * * @return PHPExcel_Calculation_FormulaToken[] */ - public function getTokens() { - return $this->_tokens; + public function getTokens() + { + return $this->tokens; } /** * Parse to tokens */ - private function _parseToTokens() { + private function parseToTokens() + { // No attempt is made to verify formulas; assumes formulas are derived from Excel, where // they can only exist if valid; stack overflows/underflows sunk as nulls without exceptions. // Check if the formula has a valid starting = - $formulaLength = strlen($this->_formula); - if ($formulaLength < 2 || $this->_formula{0} != '=') return; + $formulaLength = strlen($this->formula); + if ($formulaLength < 2 || $this->formula{0} != '=') { + return; + } // Helper variables $tokens1 = $tokens2 = $stack = array(); @@ -179,8 +181,8 @@ class PHPExcel_Calculation_FormulaParser { // embeds are doubled // end marks token if ($inString) { - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { - if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { + if ((($index + 2) <= $formulaLength) && ($this->formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) { $value .= PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE; ++$index; } else { @@ -189,7 +191,7 @@ class PHPExcel_Calculation_FormulaParser { $value = ""; } } else { - $value .= $this->_formula{$index}; + $value .= $this->formula{$index}; } ++$index; continue; @@ -199,15 +201,15 @@ class PHPExcel_Calculation_FormulaParser { // embeds are double // end does not mark a token if ($inPath) { - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { - if ((($index + 2) <= $formulaLength) && ($this->_formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { + if ((($index + 2) <= $formulaLength) && ($this->formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) { $value .= PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE; ++$index; } else { $inPath = false; } } else { - $value .= $this->_formula{$index}; + $value .= $this->formula{$index}; } ++$index; continue; @@ -217,10 +219,10 @@ class PHPExcel_Calculation_FormulaParser { // no embeds (changed to "()" by Excel) // end does not mark a token if ($inRange) { - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) { $inRange = false; } - $value .= $this->_formula{$index}; + $value .= $this->formula{$index}; ++$index; continue; } @@ -228,7 +230,7 @@ class PHPExcel_Calculation_FormulaParser { // error values // end marks a token, determined from absolute list of values if ($inError) { - $value .= $this->_formula{$index}; + $value .= $this->formula{$index}; ++$index; if (in_array($value, $ERRORS)) { $inError = false; @@ -239,10 +241,10 @@ class PHPExcel_Calculation_FormulaParser { } // scientific notation check - if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->_formula{$index}) !== false) { + if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->formula{$index}) !== false) { if (strlen($value) > 1) { - if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->_formula{$index}) != 0) { - $value .= $this->_formula{$index}; + if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->formula{$index}) != 0) { + $value .= $this->formula{$index}; ++$index; continue; } @@ -252,18 +254,20 @@ class PHPExcel_Calculation_FormulaParser { // independent character evaluation (order not important) // establish state-dependent character evaluations - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { - if (strlen($value > 0)) { // unexpected + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) { + if (strlen($value > 0)) { + // unexpected $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); $value = ""; } $inString = true; ++$index; continue; - } + } - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { - if (strlen($value) > 0) { // unexpected + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) { + if (strlen($value) > 0) { + // unexpected $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); $value = ""; } @@ -272,15 +276,16 @@ class PHPExcel_Calculation_FormulaParser { continue; } - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) { $inRange = true; $value .= PHPExcel_Calculation_FormulaParser::BRACKET_OPEN; ++$index; continue; } - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) { - if (strlen($value) > 0) { // unexpected + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) { + if (strlen($value) > 0) { + // unexpected $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); $value = ""; } @@ -291,8 +296,9 @@ class PHPExcel_Calculation_FormulaParser { } // mark start and end of arrays and array rows - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) { - if (strlen($value) > 0) { // unexpected + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) { + if (strlen($value) > 0) { + // unexpected $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN); $value = ""; } @@ -309,7 +315,7 @@ class PHPExcel_Calculation_FormulaParser { continue; } - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; @@ -331,7 +337,7 @@ class PHPExcel_Calculation_FormulaParser { continue; } - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; @@ -352,14 +358,14 @@ class PHPExcel_Calculation_FormulaParser { } // trim white-space - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; } $tokens1[] = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE); ++$index; - while (($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) { + while (($this->formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) { ++$index; } continue; @@ -367,41 +373,41 @@ class PHPExcel_Calculation_FormulaParser { // multi-character comparators if (($index + 2) <= $formulaLength) { - if (in_array(substr($this->_formula, $index, 2), $COMPARATORS_MULTI)) { + if (in_array(substr($this->formula, $index, 2), $COMPARATORS_MULTI)) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; } - $tokens1[] = new PHPExcel_Calculation_FormulaToken(substr($this->_formula, $index, 2), PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); + $tokens1[] = new PHPExcel_Calculation_FormulaToken(substr($this->formula, $index, 2), PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); $index += 2; continue; } } // standard infix operators - if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->_formula{$index}) !== false) { + if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->formula{$index}) !== false) { if (strlen($value) > 0) { $tokens1[] =new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; } - $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX); + $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX); ++$index; continue; } // standard postfix operators (only one) - if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->_formula{$index}) !== false) { + if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->formula{$index}) !== false) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; } - $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->_formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX); + $tokens1[] = new PHPExcel_Calculation_FormulaToken($this->formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX); ++$index; continue; } // start subexpression or function - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) { if (strlen($value) > 0) { $tmp = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START); $tokens1[] = $tmp; @@ -417,7 +423,7 @@ class PHPExcel_Calculation_FormulaParser { } // function, subexpression, or array parameters, or operand unions - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; @@ -438,7 +444,7 @@ class PHPExcel_Calculation_FormulaParser { } // stop subexpression - if ($this->_formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) { + if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) { if (strlen($value) > 0) { $tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND); $value = ""; @@ -454,7 +460,7 @@ class PHPExcel_Calculation_FormulaParser { } // token accumulation - $value .= $this->_formula{$index}; + $value .= $this->formula{$index}; ++$index; } @@ -516,7 +522,7 @@ class PHPExcel_Calculation_FormulaParser { // move tokens to final list, switching infix "-" operators to prefix when appropriate, switching infix "+" operators // to noop when appropriate, identifying operand and infix-operator subtypes, and pulling "@" from function names - $this->_tokens = array(); + $this->tokens = array(); $tokenCount = count($tokens2); for ($i = 0; $i < $tokenCount; ++$i) { @@ -539,53 +545,55 @@ class PHPExcel_Calculation_FormulaParser { if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "-") { if ($i == 0) { $token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); - } else if ( - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) - ) { + } elseif ((($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && + ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && + ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)) { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); } else { $token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX); } - $this->_tokens[] = $token; + $this->tokens[] = $token; continue; } if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "+") { if ($i == 0) { continue; - } else if ( - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || - (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || - ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND) - ) { + } elseif ((($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && + ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || + (($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && + ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) || + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) || + ($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)) { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); } else { continue; } - $this->_tokens[] = $token; + $this->tokens[] = $token; continue; } - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && + $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { if (strpos("<>=", substr($token->getValue(), 0, 1)) !== false) { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); - } else if ($token->getValue() == "&") { + } elseif ($token->getValue() == "&") { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_CONCATENATION); } else { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH); } - $this->_tokens[] = $token; + $this->tokens[] = $token; continue; } - if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND && $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { + if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND && + $token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { if (!is_numeric($token->getValue())) { if (strtoupper($token->getValue()) == "TRUE" || strtoupper($token->getValue() == "FALSE")) { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL); @@ -596,7 +604,7 @@ class PHPExcel_Calculation_FormulaParser { $token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NUMBER); } - $this->_tokens[] = $token; + $this->tokens[] = $token; continue; } @@ -608,7 +616,7 @@ class PHPExcel_Calculation_FormulaParser { } } - $this->_tokens[] = $token; + $this->tokens[] = $token; } } } diff --git a/Classes/PHPExcel/Calculation/FormulaToken.php b/Classes/PHPExcel/Calculation/FormulaToken.php index f5255617..41c6e3d5 100644 --- a/Classes/PHPExcel/Calculation/FormulaToken.php +++ b/Classes/PHPExcel/Calculation/FormulaToken.php @@ -1,6 +1,30 @@ _value = $pValue; - $this->_tokenType = $pTokenType; - $this->_tokenSubType = $pTokenSubType; + $this->value = $pValue; + $this->tokenType = $pTokenType; + $this->tokenSubType = $pTokenSubType; } /** @@ -125,8 +119,9 @@ class PHPExcel_Calculation_FormulaToken { * * @return string */ - public function getValue() { - return $this->_value; + public function getValue() + { + return $this->value; } /** @@ -134,8 +129,9 @@ class PHPExcel_Calculation_FormulaToken { * * @param string $value */ - public function setValue($value) { - $this->_value = $value; + public function setValue($value) + { + $this->value = $value; } /** @@ -143,8 +139,9 @@ class PHPExcel_Calculation_FormulaToken { * * @return string */ - public function getTokenType() { - return $this->_tokenType; + public function getTokenType() + { + return $this->tokenType; } /** @@ -152,8 +149,9 @@ class PHPExcel_Calculation_FormulaToken { * * @param string $value */ - public function setTokenType($value = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN) { - $this->_tokenType = $value; + public function setTokenType($value = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN) + { + $this->tokenType = $value; } /** @@ -161,8 +159,9 @@ class PHPExcel_Calculation_FormulaToken { * * @return string */ - public function getTokenSubType() { - return $this->_tokenSubType; + public function getTokenSubType() + { + return $this->tokenSubType; } /** @@ -170,7 +169,8 @@ class PHPExcel_Calculation_FormulaToken { * * @param string $value */ - public function setTokenSubType($value = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) { - $this->_tokenSubType = $value; + public function setTokenSubType($value = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) + { + $this->tokenSubType = $value; } } diff --git a/Classes/PHPExcel/Calculation/Function.php b/Classes/PHPExcel/Calculation/Function.php index 5cda0f12..d58cef25 100644 --- a/Classes/PHPExcel/Calculation/Function.php +++ b/Classes/PHPExcel/Calculation/Function.php @@ -1,6 +1,7 @@ _category = $pCategory; - $this->_excelName = $pExcelName; - $this->_phpExcelName = $pPHPExcelName; + $this->category = $pCategory; + $this->excelName = $pExcelName; + $this->phpExcelName = $pPHPExcelName; } else { throw new PHPExcel_Calculation_Exception("Invalid parameters passed."); } @@ -93,8 +86,9 @@ class PHPExcel_Calculation_Function { * * @return string */ - public function getCategory() { - return $this->_category; + public function getCategory() + { + return $this->category; } /** @@ -103,9 +97,10 @@ class PHPExcel_Calculation_Function { * @param string $value * @throws PHPExcel_Calculation_Exception */ - public function setCategory($value = null) { + public function setCategory($value = null) + { if (!is_null($value)) { - $this->_category = $value; + $this->category = $value; } else { throw new PHPExcel_Calculation_Exception("Invalid parameter passed."); } @@ -116,8 +111,9 @@ class PHPExcel_Calculation_Function { * * @return string */ - public function getExcelName() { - return $this->_excelName; + public function getExcelName() + { + return $this->excelName; } /** @@ -125,8 +121,9 @@ class PHPExcel_Calculation_Function { * * @param string $value */ - public function setExcelName($value) { - $this->_excelName = $value; + public function setExcelName($value) + { + $this->excelName = $value; } /** @@ -134,8 +131,9 @@ class PHPExcel_Calculation_Function { * * @return string */ - public function getPHPExcelName() { - return $this->_phpExcelName; + public function getPHPExcelName() + { + return $this->phpExcelName; } /** @@ -143,7 +141,8 @@ class PHPExcel_Calculation_Function { * * @param string $value */ - public function setPHPExcelName($value) { - $this->_phpExcelName = $value; + public function setPHPExcelName($value) + { + $this->phpExcelName = $value; } } diff --git a/Classes/PHPExcel/Calculation/Functions.php b/Classes/PHPExcel/Calculation/Functions.php index 8b9da311..b10f242c 100644 --- a/Classes/PHPExcel/Calculation/Functions.php +++ b/Classes/PHPExcel/Calculation/Functions.php @@ -1,30 +1,4 @@ '#NULL!', - 'divisionbyzero' => '#DIV/0!', - 'value' => '#VALUE!', - 'reference' => '#REF!', - 'name' => '#NAME?', - 'num' => '#NUM!', - 'na' => '#N/A', - 'gettingdata' => '#GETTING_DATA' - ); + protected static $_errorCodes = array( + 'null' => '#NULL!', + 'divisionbyzero' => '#DIV/0!', + 'value' => '#VALUE!', + 'reference' => '#REF!', + 'name' => '#NAME?', + 'num' => '#NUM!', + 'na' => '#N/A', + 'gettingdata' => '#GETTING_DATA' + ); /** @@ -113,15 +107,16 @@ class PHPExcel_Calculation_Functions { * PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' * @return boolean (Success or Failure) */ - public static function setCompatibilityMode($compatibilityMode) { + public static function setCompatibilityMode($compatibilityMode) + { if (($compatibilityMode == self::COMPATIBILITY_EXCEL) || ($compatibilityMode == self::COMPATIBILITY_GNUMERIC) || ($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) { self::$compatibilityMode = $compatibilityMode; - return True; + return true; } - return False; - } // function setCompatibilityMode() + return false; + } /** @@ -135,9 +130,10 @@ class PHPExcel_Calculation_Functions { * PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC 'Gnumeric' * PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE 'OpenOfficeCalc' */ - public static function getCompatibilityMode() { + public static function getCompatibilityMode() + { return self::$compatibilityMode; - } // function getCompatibilityMode() + } /** @@ -152,15 +148,16 @@ class PHPExcel_Calculation_Functions { * PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' * @return boolean Success or failure */ - public static function setReturnDateType($returnDateType) { + public static function setReturnDateType($returnDateType) + { if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) || ($returnDateType == self::RETURNDATE_PHP_OBJECT) || ($returnDateType == self::RETURNDATE_EXCEL)) { self::$ReturnDateType = $returnDateType; - return True; + return true; } - return False; - } // function setReturnDateType() + return false; + } /** @@ -174,9 +171,10 @@ class PHPExcel_Calculation_Functions { * PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT 'O' * PHPExcel_Calculation_Functions::RETURNDATE_EXCEL 'E' */ - public static function getReturnDateType() { + public static function getReturnDateType() + { return self::$ReturnDateType; - } // function getReturnDateType() + } /** @@ -186,9 +184,10 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #Not Yet Implemented */ - public static function DUMMY() { + public static function DUMMY() + { return '#Not Yet Implemented'; - } // function DUMMY() + } /** @@ -198,9 +197,10 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #Not Yet Implemented */ - public static function DIV0() { + public static function DIV0() + { return self::$_errorCodes['divisionbyzero']; - } // function DIV0() + } /** @@ -216,9 +216,10 @@ class PHPExcel_Calculation_Functions { * @category Logical Functions * @return string #N/A! */ - public static function NA() { + public static function NA() + { return self::$_errorCodes['na']; - } // function NA() + } /** @@ -230,9 +231,10 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #NUM! */ - public static function NaN() { + public static function NaN() + { return self::$_errorCodes['num']; - } // function NaN() + } /** @@ -244,9 +246,10 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #NAME? */ - public static function NAME() { + public static function NAME() + { return self::$_errorCodes['name']; - } // function NAME() + } /** @@ -258,9 +261,10 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #REF! */ - public static function REF() { + public static function REF() + { return self::$_errorCodes['reference']; - } // function REF() + } /** @@ -272,9 +276,10 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #NULL! */ - public static function NULL() { + public static function NULL() + { return self::$_errorCodes['null']; - } // function NULL() + } /** @@ -286,36 +291,44 @@ class PHPExcel_Calculation_Functions { * @category Error Returns * @return string #VALUE! */ - public static function VALUE() { + public static function VALUE() + { return self::$_errorCodes['value']; - } // function VALUE() - - - public static function isMatrixValue($idx) { - return ((substr_count($idx,'.') <= 1) || (preg_match('/\.[A-Z]/',$idx) > 0)); } - public static function isValue($idx) { - return (substr_count($idx,'.') == 0); + public static function isMatrixValue($idx) + { + return ((substr_count($idx, '.') <= 1) || (preg_match('/\.[A-Z]/', $idx) > 0)); } - public static function isCellValue($idx) { - return (substr_count($idx,'.') > 1); + public static function isValue($idx) + { + return (substr_count($idx, '.') == 0); } - public static function _ifCondition($condition) { + public static function isCellValue($idx) + { + return (substr_count($idx, '.') > 1); + } + + + public static function _ifCondition($condition) + { $condition = PHPExcel_Calculation_Functions::flattenSingleValue($condition); - if (!isset($condition{0})) + if (!isset($condition{0})) { $condition = '=""'; - if (!in_array($condition{0},array('>', '<', '='))) { - if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); } - return '='.$condition; + } + if (!in_array($condition{0}, array('>', '<', '='))) { + if (!is_numeric($condition)) { + $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); + } + return '=' . $condition; } else { - preg_match('/([<>=]+)(.*)/',$condition,$matches); - list(,$operator,$operand) = $matches; + preg_match('/([<>=]+)(.*)/', $condition, $matches); + list(, $operator, $operand) = $matches; if (!is_numeric($operand)) { $operand = str_replace('"', '""', $operand); @@ -324,8 +337,7 @@ class PHPExcel_Calculation_Functions { return $operator.$operand; } - } // function _ifCondition() - + } /** * ERROR_TYPE @@ -333,18 +345,19 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function ERROR_TYPE($value = '') { - $value = self::flattenSingleValue($value); + public static function ERROR_TYPE($value = '') + { + $value = self::flattenSingleValue($value); $i = 1; - foreach(self::$_errorCodes as $errorCode) { + foreach (self::$_errorCodes as $errorCode) { if ($value === $errorCode) { return $i; } ++$i; } return self::NA(); - } // function ERROR_TYPE() + } /** @@ -353,13 +366,14 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_BLANK($value = NULL) { + public static function IS_BLANK($value = null) + { if (!is_null($value)) { $value = self::flattenSingleValue($value); } return is_null($value); - } // function IS_BLANK() + } /** @@ -368,11 +382,12 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_ERR($value = '') { - $value = self::flattenSingleValue($value); + public static function IS_ERR($value = '') + { + $value = self::flattenSingleValue($value); return self::IS_ERROR($value) && (!self::IS_NA($value)); - } // function IS_ERR() + } /** @@ -381,13 +396,15 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_ERROR($value = '') { - $value = self::flattenSingleValue($value); + public static function IS_ERROR($value = '') + { + $value = self::flattenSingleValue($value); - if (!is_string($value)) + if (!is_string($value)) { return false; + } return in_array($value, array_values(self::$_errorCodes)); - } // function IS_ERROR() + } /** @@ -396,11 +413,12 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_NA($value = '') { - $value = self::flattenSingleValue($value); + public static function IS_NA($value = '') + { + $value = self::flattenSingleValue($value); return ($value === self::NA()); - } // function IS_NA() + } /** @@ -409,15 +427,18 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_EVEN($value = NULL) { + public static function IS_EVEN($value = null) + { $value = self::flattenSingleValue($value); - if ($value === NULL) + if ($value === null) { return self::NAME(); - if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) + } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) { return self::VALUE(); + } + return ($value % 2 == 0); - } // function IS_EVEN() + } /** @@ -426,15 +447,18 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_ODD($value = NULL) { + public static function IS_ODD($value = null) + { $value = self::flattenSingleValue($value); - if ($value === NULL) + if ($value === null) { return self::NAME(); - if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) + } elseif ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value)))) { return self::VALUE(); + } + return (abs($value) % 2 == 1); - } // function IS_ODD() + } /** @@ -443,14 +467,15 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_NUMBER($value = NULL) { - $value = self::flattenSingleValue($value); + public static function IS_NUMBER($value = null) + { + $value = self::flattenSingleValue($value); if (is_string($value)) { - return False; + return false; } return is_numeric($value); - } // function IS_NUMBER() + } /** @@ -459,11 +484,12 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_LOGICAL($value = NULL) { - $value = self::flattenSingleValue($value); + public static function IS_LOGICAL($value = null) + { + $value = self::flattenSingleValue($value); return is_bool($value); - } // function IS_LOGICAL() + } /** @@ -472,11 +498,12 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_TEXT($value = NULL) { - $value = self::flattenSingleValue($value); + public static function IS_TEXT($value = null) + { + $value = self::flattenSingleValue($value); return (is_string($value) && !self::IS_ERROR($value)); - } // function IS_TEXT() + } /** @@ -485,9 +512,10 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Value to check * @return boolean */ - public static function IS_NONTEXT($value = NULL) { + public static function IS_NONTEXT($value = null) + { return !self::IS_TEXT($value); - } // function IS_NONTEXT() + } /** @@ -495,9 +523,10 @@ class PHPExcel_Calculation_Functions { * * @return string Version information */ - public static function VERSION() { + public static function VERSION() + { return 'PHPExcel ##VERSION##, ##DATE##'; - } // function VERSION() + } /** @@ -515,21 +544,22 @@ class PHPExcel_Calculation_Functions { * An error value The error value * Anything else 0 */ - public static function N($value = NULL) { + public static function N($value = null) + { while (is_array($value)) { $value = array_shift($value); } switch (gettype($value)) { - case 'double' : - case 'float' : - case 'integer' : + case 'double': + case 'float': + case 'integer': return $value; break; - case 'boolean' : + case 'boolean': return (integer) $value; break; - case 'string' : + case 'string': // Errors if ((strlen($value) > 0) && ($value{0} == '#')) { return $value; @@ -537,7 +567,7 @@ class PHPExcel_Calculation_Functions { break; } return 0; - } // function N() + } /** @@ -554,11 +584,12 @@ class PHPExcel_Calculation_Functions { * An error value 16 * Array or Matrix 64 */ - public static function TYPE($value = NULL) { - $value = self::flattenArrayIndexed($value); + public static function TYPE($value = null) + { + $value = self::flattenArrayIndexed($value); if (is_array($value) && (count($value) > 1)) { - $a = array_keys($value); - $a = array_pop($a); + end($value); + $a = key($value); // Range of cells is an error if (self::isCellValue($a)) { return 16; @@ -566,19 +597,19 @@ class PHPExcel_Calculation_Functions { } elseif (self::isMatrixValue($a)) { return 64; } - } elseif(empty($value)) { + } elseif (empty($value)) { // Empty Cell return 1; } - $value = self::flattenSingleValue($value); + $value = self::flattenSingleValue($value); - if (($value === NULL) || (is_float($value)) || (is_int($value))) { + if (($value === null) || (is_float($value)) || (is_int($value))) { return 1; - } elseif(is_bool($value)) { + } elseif (is_bool($value)) { return 4; - } elseif(is_array($value)) { + } elseif (is_array($value)) { return 64; - } elseif(is_string($value)) { + } elseif (is_string($value)) { // Errors if ((strlen($value) > 0) && ($value{0} == '#')) { return 16; @@ -586,7 +617,7 @@ class PHPExcel_Calculation_Functions { return 2; } return 0; - } // function TYPE() + } /** @@ -595,7 +626,8 @@ class PHPExcel_Calculation_Functions { * @param array $array Array to be flattened * @return array Flattened array */ - public static function flattenArray($array) { + public static function flattenArray($array) + { if (!is_array($array)) { return (array) $array; } @@ -618,7 +650,7 @@ class PHPExcel_Calculation_Functions { } return $arrayValues; - } // function flattenArray() + } /** @@ -627,7 +659,8 @@ class PHPExcel_Calculation_Functions { * @param array $array Array to be flattened * @return array Flattened array */ - public static function flattenArrayIndexed($array) { + public static function flattenArrayIndexed($array) + { if (!is_array($array)) { return (array) $array; } @@ -650,7 +683,7 @@ class PHPExcel_Calculation_Functions { } return $arrayValues; - } // function flattenArrayIndexed() + } /** @@ -659,15 +692,15 @@ class PHPExcel_Calculation_Functions { * @param mixed $value Array or scalar value * @return mixed */ - public static function flattenSingleValue($value = '') { + public static function flattenSingleValue($value = '') + { while (is_array($value)) { $value = array_pop($value); } return $value; - } // function flattenSingleValue() - -} // class PHPExcel_Calculation_Functions + } +} // @@ -676,19 +709,22 @@ class PHPExcel_Calculation_Functions { // So we test if they do exist for this version of PHP/operating platform; and if not we create them // if (!function_exists('acosh')) { - function acosh($x) { + function acosh($x) + { return 2 * log(sqrt(($x + 1) / 2) + sqrt(($x - 1) / 2)); } // function acosh() } if (!function_exists('asinh')) { - function asinh($x) { + function asinh($x) + { return log($x + sqrt(1 + $x * $x)); } // function asinh() } if (!function_exists('atanh')) { - function atanh($x) { + function atanh($x) + { return (log(1 + $x) - log(1 - $x)) / 2; } // function atanh() } @@ -700,22 +736,23 @@ if (!function_exists('atanh')) { // if ((!function_exists('mb_str_replace')) && (function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) { - function mb_str_replace($search, $replace, $subject) { - if(is_array($subject)) { + function mb_str_replace($search, $replace, $subject) + { + if (is_array($subject)) { $ret = array(); - foreach($subject as $key => $val) { + foreach ($subject as $key => $val) { $ret[$key] = mb_str_replace($search, $replace, $val); } return $ret; } - foreach((array) $search as $key => $s) { - if($s == '' && $s !== 0) { + foreach ((array) $search as $key => $s) { + if ($s == '' && $s !== 0) { continue; } $r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] : ''); $pos = mb_strpos($subject, $s, 0, 'UTF-8'); - while($pos !== false) { + while ($pos !== false) { $subject = mb_substr($subject, 0, $pos, 'UTF-8') . $r . mb_substr($subject, $pos + mb_strlen($s, 'UTF-8'), 65535, 'UTF-8'); $pos = mb_strpos($subject, $s, $pos + mb_strlen($r, 'UTF-8'), 'UTF-8'); } diff --git a/Classes/PHPExcel/Calculation/Logical.php b/Classes/PHPExcel/Calculation/Logical.php index ca5575cf..dd65f010 100644 --- a/Classes/PHPExcel/Calculation/Logical.php +++ b/Classes/PHPExcel/Calculation/Logical.php @@ -1,6 +1,16 @@