Skip to content

Commit 033a4bd

Browse files
committed
Remove default values for function that should not have any default
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
1 parent 67581a0 commit 033a4bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1048
-1121
lines changed

docs/topics/migration-from-PHPExcel.md

+21
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,24 @@ to `\PhpOffice\PhpSpreadsheet::getCoordinates()` and
171171
`\PhpOffice\PhpSpreadsheet::getCellCollection()` for clarity.
172172

173173
Refer to [the new documentation](./memory_saving.md) to see how to migrate.
174+
175+
## Dropped conditionally returned cell
176+
177+
For all the following methods, it is no more possible to change the type of
178+
returned value. It always return the Worksheet and never the Cell or Rule:
179+
180+
- Worksheet::setCellValue()
181+
- Worksheet::setCellValueByColumnAndRow()
182+
- Worksheet::setCellValueExplicit()
183+
- Worksheet::setCellValueExplicitByColumnAndRow()
184+
- Worksheet::addRule()
185+
186+
Migration would be similar to:
187+
188+
``` php
189+
// Before
190+
$cell = $worksheet->setCellValue('A1', 'value', true);
191+
192+
// After
193+
$cell = $worksheet->getCell('A1')->setValue('value');
194+
```

src/PhpSpreadsheet/CalcEngine/Logger.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(CyclicReferenceStack $stack)
7474
*
7575
* @param bool $pValue
7676
*/
77-
public function setWriteDebugLog($pValue = false)
77+
public function setWriteDebugLog($pValue)
7878
{
7979
$this->writeDebugLog = $pValue;
8080
}
@@ -94,7 +94,7 @@ public function getWriteDebugLog()
9494
*
9595
* @param bool $pValue
9696
*/
97-
public function setEchoDebugLog($pValue = false)
97+
public function setEchoDebugLog($pValue)
9898
{
9999
$this->echoDebugLog = $pValue;
100100
}

src/PhpSpreadsheet/Calculation.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ public function getCalculationCacheEnabled()
21762176
*
21772177
* @param bool $pValue
21782178
*/
2179-
public function setCalculationCacheEnabled($pValue = true)
2179+
public function setCalculationCacheEnabled($pValue)
21802180
{
21812181
$this->calculationCacheEnabled = $pValue;
21822182
$this->clearCalculationCache();
@@ -2245,11 +2245,11 @@ public function getLocale()
22452245
/**
22462246
* Set the locale code.
22472247
*
2248-
* @param string $locale The locale to use for formula translation
2248+
* @param string $locale The locale to use for formula translation, eg: 'en_us'
22492249
*
22502250
* @return bool
22512251
*/
2252-
public function setLocale($locale = 'en_us')
2252+
public function setLocale($locale)
22532253
{
22542254
// Identify our locale and language
22552255
$language = $locale = strtolower($locale);

src/PhpSpreadsheet/Calculation/FormulaToken.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ public function getTokenType()
142142
}
143143

144144
/**
145-
* Set Token Type.
145+
* Set Token Type (represented by TOKEN_TYPE_*).
146146
*
147147
* @param string $value
148148
*/
149-
public function setTokenType($value = self::TOKEN_TYPE_UNKNOWN)
149+
public function setTokenType($value)
150150
{
151151
$this->tokenType = $value;
152152
}
@@ -162,11 +162,11 @@ public function getTokenSubType()
162162
}
163163

164164
/**
165-
* Set Token SubType.
165+
* Set Token SubType (represented by TOKEN_SUBTYPE_*).
166166
*
167167
* @param string $value
168168
*/
169-
public function setTokenSubType($value = self::TOKEN_SUBTYPE_NOTHING)
169+
public function setTokenSubType($value)
170170
{
171171
$this->tokenSubType = $value;
172172
}

src/PhpSpreadsheet/Cell.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function getFormattedValue()
202202
*
203203
* @return Cell
204204
*/
205-
public function setValue($pValue = null)
205+
public function setValue($pValue)
206206
{
207207
if (!self::getValueBinder()->bindValue($this, $pValue)) {
208208
throw new Exception('Value could not be bound to cell.');
@@ -215,13 +215,13 @@ public function setValue($pValue = null)
215215
* Set the value for a cell, with the explicit data type passed to the method (bypassing any use of the value binder).
216216
*
217217
* @param mixed $pValue Value
218-
* @param string $pDataType Explicit data type
218+
* @param string $pDataType Explicit data type, see Cell\DataType::TYPE_*
219219
*
220220
* @throws Exception
221221
*
222222
* @return Cell
223223
*/
224-
public function setValueExplicit($pValue = null, $pDataType = Cell\DataType::TYPE_STRING)
224+
public function setValueExplicit($pValue, $pDataType)
225225
{
226226
// set the value according to data type
227227
switch ($pDataType) {
@@ -311,7 +311,7 @@ public function getCalculatedValue($resetLog = true)
311311
*
312312
* @return Cell
313313
*/
314-
public function setCalculatedValue($pValue = null)
314+
public function setCalculatedValue($pValue)
315315
{
316316
if ($pValue !== null) {
317317
$this->calculatedValue = (is_numeric($pValue)) ? (float) $pValue : $pValue;
@@ -348,11 +348,11 @@ public function getDataType()
348348
/**
349349
* Set cell data type.
350350
*
351-
* @param string $pDataType
351+
* @param string $pDataType see Cell\DataType::TYPE_*
352352
*
353353
* @return Cell
354354
*/
355-
public function setDataType($pDataType = Cell\DataType::TYPE_STRING)
355+
public function setDataType($pDataType)
356356
{
357357
if ($pDataType == Cell\DataType::TYPE_STRING2) {
358358
$pDataType = Cell\DataType::TYPE_STRING;
@@ -571,7 +571,7 @@ public function rebindParent(Worksheet $parent)
571571
*
572572
* @return bool
573573
*/
574-
public function isInRange($pRange = 'A1:A1')
574+
public function isInRange($pRange)
575575
{
576576
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
577577

@@ -587,13 +587,13 @@ public function isInRange($pRange = 'A1:A1')
587587
/**
588588
* Coordinate from string.
589589
*
590-
* @param string $pCoordinateString
590+
* @param string $pCoordinateString eg: 'A1'
591591
*
592592
* @throws Exception
593593
*
594594
* @return string[] Array containing column and row (indexes 0 and 1)
595595
*/
596-
public static function coordinateFromString($pCoordinateString = 'A1')
596+
public static function coordinateFromString($pCoordinateString)
597597
{
598598
if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
599599
return [$matches[1], $matches[2]];
@@ -616,7 +616,7 @@ public static function coordinateFromString($pCoordinateString = 'A1')
616616
*
617617
* @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
618618
*/
619-
public static function absoluteReference($pCoordinateString = 'A1')
619+
public static function absoluteReference($pCoordinateString)
620620
{
621621
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
622622
// Split out any worksheet name from the reference
@@ -651,7 +651,7 @@ public static function absoluteReference($pCoordinateString = 'A1')
651651
*
652652
* @return string Absolute coordinate e.g. '$A$1'
653653
*/
654-
public static function absoluteCoordinate($pCoordinateString = 'A1')
654+
public static function absoluteCoordinate($pCoordinateString)
655655
{
656656
if (strpos($pCoordinateString, ':') === false && strpos($pCoordinateString, ',') === false) {
657657
// Split out any worksheet name from the coordinate
@@ -684,7 +684,7 @@ public static function absoluteCoordinate($pCoordinateString = 'A1')
684684
* e.g. array('B4','D9') or array(array('B4','D9'),array('H2','O11'))
685685
* or array('B4')
686686
*/
687-
public static function splitRange($pRange = 'A1:A1')
687+
public static function splitRange($pRange)
688688
{
689689
// Ensure $pRange is a valid range
690690
if (empty($pRange)) {
@@ -735,7 +735,7 @@ public static function buildRange($pRange)
735735
* @return array Range coordinates array(Start Cell, End Cell)
736736
* where Start Cell and End Cell are arrays (Column Number, Row Number)
737737
*/
738-
public static function rangeBoundaries($pRange = 'A1:A1')
738+
public static function rangeBoundaries($pRange)
739739
{
740740
// Ensure $pRange is a valid range
741741
if (empty($pRange)) {
@@ -770,7 +770,7 @@ public static function rangeBoundaries($pRange = 'A1:A1')
770770
*
771771
* @return array Range dimension (width, height)
772772
*/
773-
public static function rangeDimension($pRange = 'A1:A1')
773+
public static function rangeDimension($pRange)
774774
{
775775
// Calculate range outer borders
776776
list($rangeStart, $rangeEnd) = self::rangeBoundaries($pRange);
@@ -786,7 +786,7 @@ public static function rangeDimension($pRange = 'A1:A1')
786786
* @return array Range coordinates array(Start Cell, End Cell)
787787
* where Start Cell and End Cell are arrays (Column ID, Row Number)
788788
*/
789-
public static function getRangeBoundaries($pRange = 'A1:A1')
789+
public static function getRangeBoundaries($pRange)
790790
{
791791
// Ensure $pRange is a valid range
792792
if (empty($pRange)) {
@@ -809,11 +809,11 @@ public static function getRangeBoundaries($pRange = 'A1:A1')
809809
/**
810810
* Column index from string.
811811
*
812-
* @param string $pString
812+
* @param string $pString eg 'A'
813813
*
814814
* @return int Column index (base 1 !!!)
815815
*/
816-
public static function columnIndexFromString($pString = 'A')
816+
public static function columnIndexFromString($pString)
817817
{
818818
// Using a lookup cache adds a slight memory overhead, but boosts speed
819819
// caching using a static within the method is faster than a class static,
@@ -856,11 +856,11 @@ public static function columnIndexFromString($pString = 'A')
856856
/**
857857
* String from columnindex.
858858
*
859-
* @param int $pColumnIndex Column index (base 0 !!!)
859+
* @param int $pColumnIndex Column index (A = 0)
860860
*
861861
* @return string
862862
*/
863-
public static function stringFromColumnIndex($pColumnIndex = 0)
863+
public static function stringFromColumnIndex($pColumnIndex)
864864
{
865865
// Using a lookup cache adds a slight memory overhead, but boosts speed
866866
// caching using a static within the method is faster than a class static,
@@ -891,7 +891,7 @@ public static function stringFromColumnIndex($pColumnIndex = 0)
891891
*
892892
* @return array Array containing single cell references
893893
*/
894-
public static function extractAllCellReferencesInRange($pRange = 'A1')
894+
public static function extractAllCellReferencesInRange($pRange)
895895
{
896896
// Returnvalue
897897
$returnValue = [];
@@ -1031,7 +1031,7 @@ public function getXfIndex()
10311031
*
10321032
* @return Cell
10331033
*/
1034-
public function setXfIndex($pValue = 0)
1034+
public function setXfIndex($pValue)
10351035
{
10361036
$this->xfIndex = $pValue;
10371037

src/PhpSpreadsheet/Cell/DataType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static function getErrorCodes()
6969
*
7070
* @return mixed Sanitized value
7171
*/
72-
public static function checkString($pValue = null)
72+
public static function checkString($pValue)
7373
{
7474
if ($pValue instanceof \PhpOffice\PhpSpreadsheet\RichText) {
7575
// TODO: Sanitize Rich-Text string (max. character count is 32,767)
@@ -93,7 +93,7 @@ public static function checkString($pValue = null)
9393
*
9494
* @return string Sanitized value
9595
*/
96-
public static function checkErrorCode($pValue = null)
96+
public static function checkErrorCode($pValue)
9797
{
9898
$pValue = (string) $pValue;
9999

0 commit comments

Comments
 (0)