Skip to content

Commit

Permalink
Remove default values for function that should not have any default
Browse files Browse the repository at this point in the history
Having default values made it harder for end-user to figure out whether
it the arguement had to be supplied or not. Ommitting the argument may
lead to hard to debug issues, and is overall not a good idea.

Closes #110
  • Loading branch information
PowerKiKi committed Apr 16, 2017
1 parent 67581a0 commit 033a4bd
Show file tree
Hide file tree
Showing 93 changed files with 1,048 additions and 1,121 deletions.
21 changes: 21 additions & 0 deletions docs/topics/migration-from-PHPExcel.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,24 @@ to `\PhpOffice\PhpSpreadsheet::getCoordinates()` and
`\PhpOffice\PhpSpreadsheet::getCellCollection()` for clarity.

Refer to [the new documentation](./memory_saving.md) to see how to migrate.

## Dropped conditionally returned cell

For all the following methods, it is no more possible to change the type of
returned value. It always return the Worksheet and never the Cell or Rule:

- Worksheet::setCellValue()
- Worksheet::setCellValueByColumnAndRow()
- Worksheet::setCellValueExplicit()
- Worksheet::setCellValueExplicitByColumnAndRow()
- Worksheet::addRule()

Migration would be similar to:

``` php
// Before
$cell = $worksheet->setCellValue('A1', 'value', true);

// After
$cell = $worksheet->getCell('A1')->setValue('value');
```
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/CalcEngine/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct(CyclicReferenceStack $stack)
*
* @param bool $pValue
*/
public function setWriteDebugLog($pValue = false)
public function setWriteDebugLog($pValue)
{
$this->writeDebugLog = $pValue;
}
Expand All @@ -94,7 +94,7 @@ public function getWriteDebugLog()
*
* @param bool $pValue
*/
public function setEchoDebugLog($pValue = false)
public function setEchoDebugLog($pValue)
{
$this->echoDebugLog = $pValue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/PhpSpreadsheet/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ public function getCalculationCacheEnabled()
*
* @param bool $pValue
*/
public function setCalculationCacheEnabled($pValue = true)
public function setCalculationCacheEnabled($pValue)
{
$this->calculationCacheEnabled = $pValue;
$this->clearCalculationCache();
Expand Down Expand Up @@ -2245,11 +2245,11 @@ public function getLocale()
/**
* Set the locale code.
*
* @param string $locale The locale to use for formula translation
* @param string $locale The locale to use for formula translation, eg: 'en_us'
*
* @return bool
*/
public function setLocale($locale = 'en_us')
public function setLocale($locale)
{
// Identify our locale and language
$language = $locale = strtolower($locale);
Expand Down
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Calculation/FormulaToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ public function getTokenType()
}

/**
* Set Token Type.
* Set Token Type (represented by TOKEN_TYPE_*).
*
* @param string $value
*/
public function setTokenType($value = self::TOKEN_TYPE_UNKNOWN)
public function setTokenType($value)
{
$this->tokenType = $value;
}
Expand All @@ -162,11 +162,11 @@ public function getTokenSubType()
}

/**
* Set Token SubType.
* Set Token SubType (represented by TOKEN_SUBTYPE_*).
*
* @param string $value
*/
public function setTokenSubType($value = self::TOKEN_SUBTYPE_NOTHING)
public function setTokenSubType($value)
{
$this->tokenSubType = $value;
}
Expand Down
42 changes: 21 additions & 21 deletions src/PhpSpreadsheet/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function getFormattedValue()
*
* @return Cell
*/
public function setValue($pValue = null)
public function setValue($pValue)
{
if (!self::getValueBinder()->bindValue($this, $pValue)) {
throw new Exception('Value could not be bound to cell.');
Expand All @@ -215,13 +215,13 @@ public function setValue($pValue = null)
* Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder).
*
* @param mixed $pValue Value
* @param string $pDataType Explicit data type
* @param string $pDataType Explicit data type, see Cell\DataType::TYPE_*
*
* @throws Exception
*
* @return Cell
*/
public function setValueExplicit($pValue = null, $pDataType = Cell\DataType::TYPE_STRING)
public function setValueExplicit($pValue, $pDataType)
{
// set the value according to data type
switch ($pDataType) {
Expand Down Expand Up @@ -311,7 +311,7 @@ public function getCalculatedValue($resetLog = true)
*
* @return Cell
*/
public function setCalculatedValue($pValue = null)
public function setCalculatedValue($pValue)
{
if ($pValue !== null) {
$this->calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue;
Expand Down Expand Up @@ -348,11 +348,11 @@ public function getDataType()
/**
* Set cell data type.
*
* @param string $pDataType
* @param string $pDataType see Cell\DataType::TYPE_*
*
* @return Cell
*/
public function setDataType($pDataType = Cell\DataType::TYPE_STRING)
public function setDataType($pDataType)
{
if ($pDataType == Cell\DataType::TYPE_STRING2) {
$pDataType = Cell\DataType::TYPE_STRING;
Expand Down Expand Up @@ -571,7 +571,7 @@ public function rebindParent(Worksheet $parent)
*
* @return bool
*/
public function isInRange($pRange = 'A1:A1')
public function isInRange($pRange)
{
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);

Expand All @@ -587,13 +587,13 @@ public function isInRange($pRange = 'A1:A1')
/**
* Coordinate from string.
*
* @param string $pCoordinateString
* @param string $pCoordinateString eg: 'A1'
*
* @throws Exception
*
* @return string[] Array containing column and row (indexes 0 and 1)
*/
public static function coordinateFromString($pCoordinateString = 'A1')
public static function coordinateFromString($pCoordinateString)
{
if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
return [$matches[1], $matches[2]];
Expand All @@ -616,7 +616,7 @@ public static function coordinateFromString($pCoordinateString = 'A1')
*
* @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
*/
public static function absoluteReference($pCoordinateString = 'A1')
public static function absoluteReference($pCoordinateString)
{
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
// Split out any worksheet name from the reference
Expand Down Expand Up @@ -651,7 +651,7 @@ public static function absoluteReference($pCoordinateString = 'A1')
*
* @return string Absolute coordinate e.g. '$A$1'
*/
public static function absoluteCoordinate($pCoordinateString = 'A1')
public static function absoluteCoordinate($pCoordinateString)
{
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
// Split out any worksheet name from the coordinate
Expand Down Expand Up @@ -684,7 +684,7 @@ public static function absoluteCoordinate($pCoordinateString = 'A1')
* e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11'))
* or array('B4')
*/
public static function splitRange($pRange = 'A1:A1')
public static function splitRange($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
Expand Down Expand Up @@ -735,7 +735,7 @@ public static function buildRange($pRange)
* @return array Range coordinates array(Start Cell, End Cell)
* where Start Cell and End Cell are arrays (Column Number, Row Number)
*/
public static function rangeBoundaries($pRange = 'A1:A1')
public static function rangeBoundaries($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
Expand Down Expand Up @@ -770,7 +770,7 @@ public static function rangeBoundaries($pRange = 'A1:A1')
*
* @return array Range dimension (width, height)
*/
public static function rangeDimension($pRange = 'A1:A1')
public static function rangeDimension($pRange)
{
// Calculate range outer borders
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
Expand All @@ -786,7 +786,7 @@ public static function rangeDimension($pRange = 'A1:A1')
* @return array Range coordinates array(Start Cell, End Cell)
* where Start Cell and End Cell are arrays (Column ID, Row Number)
*/
public static function getRangeBoundaries($pRange = 'A1:A1')
public static function getRangeBoundaries($pRange)
{
// Ensure $pRange is a valid range
if (empty($pRange)) {
Expand All @@ -809,11 +809,11 @@ public static function getRangeBoundaries($pRange = 'A1:A1')
/**
* Column index from string.
*
* @param string $pString
* @param string $pString eg 'A'
*
* @return int Column index (base 1 !!!)
*/
public static function columnIndexFromString($pString = 'A')
public static function columnIndexFromString($pString)
{
// Using a lookup cache adds a slight memory overhead, but boosts speed
// caching using a static within the method is faster than a class static,
Expand Down Expand Up @@ -856,11 +856,11 @@ public static function columnIndexFromString($pString = 'A')
/**
* String from columnindex.
*
* @param int $pColumnIndex Column index (base 0 !!!)
* @param int $pColumnIndex Column index (A = 0)
*
* @return string
*/
public static function stringFromColumnIndex($pColumnIndex = 0)
public static function stringFromColumnIndex($pColumnIndex)
{
// Using a lookup cache adds a slight memory overhead, but boosts speed
// caching using a static within the method is faster than a class static,
Expand Down Expand Up @@ -891,7 +891,7 @@ public static function stringFromColumnIndex($pColumnIndex = 0)
*
* @return array Array containing single cell references
*/
public static function extractAllCellReferencesInRange($pRange = 'A1')
public static function extractAllCellReferencesInRange($pRange)
{
// Returnvalue
$returnValue = [];
Expand Down Expand Up @@ -1031,7 +1031,7 @@ public function getXfIndex()
*
* @return Cell
*/
public function setXfIndex($pValue = 0)
public function setXfIndex($pValue)
{
$this->xfIndex = $pValue;

Expand Down
4 changes: 2 additions & 2 deletions src/PhpSpreadsheet/Cell/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function getErrorCodes()
*
* @return mixed Sanitized value
*/
public static function checkString($pValue = null)
public static function checkString($pValue)
{
if ($pValue instanceof \PhpOffice\PhpSpreadsheet\RichText) {
// TODO: Sanitize Rich-Text string (max. character count is 32,767)
Expand All @@ -93,7 +93,7 @@ public static function checkString($pValue = null)
*
* @return string Sanitized value
*/
public static function checkErrorCode($pValue = null)
public static function checkErrorCode($pValue)
{
$pValue = (string) $pValue;

Expand Down
Loading

0 comments on commit 033a4bd

Please sign in to comment.