Skip to content

Commit fe79f7b

Browse files
authored
Fix Unintential Deprecated Calls in Tests - INFORMATION (#3177)
* Fix Unintential Deprecated Calls in Tests - INFORMATION I think it's best to install these before PR #3166. There are no changes to source code, only to doc-blocks and to test members which continue to inadvertently use calls to deprecated functions. * Missed Some Deprecated Calls Fix them now.
1 parent c2bf9cd commit fe79f7b

File tree

20 files changed

+129
-120
lines changed

20 files changed

+129
-120
lines changed

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4833,7 +4833,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
48334833
}
48344834
if (count(Functions::flattenArray($cellIntersect)) === 0) {
48354835
$this->debugLog->writeDebugLog('Evaluation Result is %s', $this->showTypeDetails($cellIntersect));
4836-
$stack->push('Error', Functions::null(), null);
4836+
$stack->push('Error', Information\ExcelError::null(), null);
48374837
} else {
48384838
$cellRef = Coordinate::stringFromColumnIndex(min($oCol) + 1) . min($oRow) . ':' .
48394839
Coordinate::stringFromColumnIndex(max($oCol) + 1) . max($oRow);

src/PhpSpreadsheet/Calculation/Functions.php

Lines changed: 32 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,10 @@ private static function operandSpecialHandling($operand)
206206
*
207207
* Returns the error value #NULL!
208208
*
209-
* @Deprecated 1.23.0
209+
* @deprecated 1.23.0 Use the null() method in the Information\ExcelError class instead
210+
* @see Information\ExcelError::null()
210211
*
211212
* @return string #NULL!
212-
*
213-
*@see Information\ExcelError::null()
214-
* Use the null() method in the Information\Error class instead
215213
*/
216214
public static function null()
217215
{
@@ -223,12 +221,10 @@ public static function null()
223221
*
224222
* Returns the error value #NUM!
225223
*
226-
* @Deprecated 1.23.0
224+
* @deprecated 1.23.0 Use the NAN() method in the Information\Error class instead
225+
* @see Information\ExcelError::NAN()
227226
*
228227
* @return string #NUM!
229-
*
230-
* @see Information\ExcelError::NAN()
231-
* Use the NAN() method in the Information\Error class instead
232228
*/
233229
public static function NAN()
234230
{
@@ -240,12 +236,10 @@ public static function NAN()
240236
*
241237
* Returns the error value #REF!
242238
*
243-
* @Deprecated 1.23.0
239+
* @deprecated 1.23.0 Use the REF() method in the Information\ExcelError class instead
240+
* @see Information\ExcelError::REF()
244241
*
245242
* @return string #REF!
246-
*
247-
* @see Information\ExcelError::REF()
248-
* Use the REF() method in the Information\Error class instead
249243
*/
250244
public static function REF()
251245
{
@@ -261,12 +255,10 @@ public static function REF()
261255
* Returns the error value #N/A
262256
* #N/A is the error value that means "no value is available."
263257
*
264-
* @Deprecated 1.23.0
258+
* @deprecated 1.23.0 Use the NA() method in the Information\ExcelError class instead
259+
* @see Information\ExcelError::NA()
265260
*
266261
* @return string #N/A!
267-
*
268-
* @see Information\ExcelError::NA()
269-
* Use the NA() method in the Information\Error class instead
270262
*/
271263
public static function NA()
272264
{
@@ -278,12 +270,10 @@ public static function NA()
278270
*
279271
* Returns the error value #VALUE!
280272
*
281-
* @Deprecated 1.23.0
273+
* @deprecated 1.23.0 Use the VALUE() method in the Information\ExcelError class instead
274+
* @see Information\ExcelError::VALUE()
282275
*
283276
* @return string #VALUE!
284-
*
285-
* @see Information\ExcelError::VALUE()
286-
* Use the VALUE() method in the Information\Error class instead
287277
*/
288278
public static function VALUE()
289279
{
@@ -295,12 +285,10 @@ public static function VALUE()
295285
*
296286
* Returns the error value #NAME?
297287
*
298-
* @Deprecated 1.23.0
288+
* @deprecated 1.23.0 Use the NAME() method in the Information\ExcelError class instead
289+
* @see Information\ExcelError::NAME()
299290
*
300291
* @return string #NAME?
301-
*
302-
* @see Information\ExcelError::NAME()
303-
* Use the NAME() method in the Information\Error class instead
304292
*/
305293
public static function NAME()
306294
{
@@ -310,12 +298,10 @@ public static function NAME()
310298
/**
311299
* DIV0.
312300
*
313-
* @Deprecated 1.23.0
301+
* @deprecated 1.23.0 Use the DIV0() method in the Information\ExcelError class instead
302+
* @see Information\ExcelError::DIV0()
314303
*
315304
* @return string #Not Yet Implemented
316-
*
317-
*@see Information\ExcelError::DIV0()
318-
* Use the DIV0() method in the Information\Error class instead
319305
*/
320306
public static function DIV0()
321307
{
@@ -327,12 +313,10 @@ public static function DIV0()
327313
*
328314
* @param mixed $value Value to check
329315
*
330-
* @Deprecated 1.23.0
316+
* @deprecated 1.23.0 Use the type() method in the Information\ExcelError class instead
317+
* @see Information\ExcelError::type()
331318
*
332319
* @return array|int|string
333-
*
334-
* @see Information\ExcelError::type()
335-
* Use the type() method in the Information\Error class instead
336320
*/
337321
public static function errorType($value = '')
338322
{
@@ -344,10 +328,8 @@ public static function errorType($value = '')
344328
*
345329
* @param mixed $value Value to check
346330
*
347-
* @Deprecated 1.23.0
348-
*
331+
* @deprecated 1.23.0 Use the isBlank() method in the Information\Value class instead
349332
* @see Information\Value::isBlank()
350-
* Use the isBlank() method in the Information\Value class instead
351333
*
352334
* @return array|bool
353335
*/
@@ -361,10 +343,8 @@ public static function isBlank($value = null)
361343
*
362344
* @param mixed $value Value to check
363345
*
364-
* @Deprecated 1.23.0
365-
*
366-
* @see Information\Value::isErr()
367-
* Use the isErr() method in the Information\Value class instead
346+
* @deprecated 1.23.0 Use the isErr() method in the Information\ErrorValue class instead
347+
* @see Information\ErrorValue::isErr()
368348
*
369349
* @return array|bool
370350
*/
@@ -378,10 +358,8 @@ public static function isErr($value = '')
378358
*
379359
* @param mixed $value Value to check
380360
*
381-
* @Deprecated 1.23.0
382-
*
383-
* @see Information\Value::isError()
384-
* Use the isError() method in the Information\Value class instead
361+
* @deprecated 1.23.0 Use the isError() method in the Information\ErrorValue class instead
362+
* @see Information\ErrorValue::isError()
385363
*
386364
* @return array|bool
387365
*/
@@ -395,10 +373,8 @@ public static function isError($value = '')
395373
*
396374
* @param mixed $value Value to check
397375
*
398-
* @Deprecated 1.23.0
399-
*
400-
* @see Information\Value::isNa()
401-
* Use the isNa() method in the Information\Value class instead
376+
* @deprecated 1.23.0 Use the isNa() method in the Information\ErrorValue class instead
377+
* @see Information\ErrorValue::isNa()
402378
*
403379
* @return array|bool
404380
*/
@@ -412,10 +388,8 @@ public static function isNa($value = '')
412388
*
413389
* @param mixed $value Value to check
414390
*
415-
* @Deprecated 1.23.0
416-
*
391+
* @deprecated 1.23.0 Use the isEven() method in the Information\Value class instead
417392
* @see Information\Value::isEven()
418-
* Use the isEven() method in the Information\Value class instead
419393
*
420394
* @return array|bool|string
421395
*/
@@ -429,10 +403,8 @@ public static function isEven($value = null)
429403
*
430404
* @param mixed $value Value to check
431405
*
432-
* @Deprecated 1.23.0
433-
*
406+
* @deprecated 1.23.0 Use the isOdd() method in the Information\Value class instead
434407
* @see Information\Value::isOdd()
435-
* Use the isOdd() method in the Information\Value class instead
436408
*
437409
* @return array|bool|string
438410
*/
@@ -446,10 +418,8 @@ public static function isOdd($value = null)
446418
*
447419
* @param mixed $value Value to check
448420
*
449-
* @Deprecated 1.23.0
450-
*
421+
* @deprecated 1.23.0 Use the isNumber() method in the Information\Value class instead
451422
* @see Information\Value::isNumber()
452-
* Use the isNumber() method in the Information\Value class instead
453423
*
454424
* @return array|bool
455425
*/
@@ -463,10 +433,8 @@ public static function isNumber($value = null)
463433
*
464434
* @param mixed $value Value to check
465435
*
466-
* @Deprecated 1.23.0
467-
*
436+
* @deprecated 1.23.0 Use the isLogical() method in the Information\Value class instead
468437
* @see Information\Value::isLogical()
469-
* Use the isLogical() method in the Information\Value class instead
470438
*
471439
* @return array|bool
472440
*/
@@ -480,10 +448,8 @@ public static function isLogical($value = null)
480448
*
481449
* @param mixed $value Value to check
482450
*
483-
* @Deprecated 1.23.0
484-
*
451+
* @deprecated 1.23.0 Use the isText() method in the Information\Value class instead
485452
* @see Information\Value::isText()
486-
* Use the isText() method in the Information\Value class instead
487453
*
488454
* @return array|bool
489455
*/
@@ -497,10 +463,8 @@ public static function isText($value = null)
497463
*
498464
* @param mixed $value Value to check
499465
*
500-
* @Deprecated 1.23.0
501-
*
466+
* @deprecated 1.23.0 Use the isNonText() method in the Information\Value class instead
502467
* @see Information\Value::isNonText()
503-
* Use the isNonText() method in the Information\Value class instead
504468
*
505469
* @return array|bool
506470
*/
@@ -514,10 +478,8 @@ public static function isNonText($value = null)
514478
*
515479
* Returns a value converted to a number
516480
*
517-
* @Deprecated 1.23.0
518-
*
481+
* @deprecated 1.23.0 Use the asNumber() method in the Information\Value class instead
519482
* @see Information\Value::asNumber()
520-
* Use the asNumber() method in the Information\Value class instead
521483
*
522484
* @param null|mixed $value The value you want converted
523485
*
@@ -540,10 +502,8 @@ public static function n($value = null)
540502
*
541503
* Returns a number that identifies the type of a value
542504
*
543-
* @Deprecated 1.23.0
544-
*
505+
* @deprecated 1.23.0 Use the type() method in the Information\Value class instead
545506
* @see Information\Value::type()
546-
* Use the type() method in the Information\Value class instead
547507
*
548508
* @param null|mixed $value The value you want tested
549509
*
@@ -659,10 +619,8 @@ public static function flattenSingleValue($value = '')
659619
/**
660620
* ISFORMULA.
661621
*
662-
* @Deprecated 1.23.0
663-
*
622+
* @deprecated 1.23.0 Use the isFormula() method in the Information\Value class instead
664623
* @see Information\Value::isFormula()
665-
* Use the isFormula() method in the Information\Value class instead
666624
*
667625
* @param mixed $cellReference The cell to check
668626
* @param ?Cell $cell The current cell (containing this formula)

src/PhpSpreadsheet/Calculation/TextData/Text.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
66
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
77
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
8+
use PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue;
89

910
class Text
1011
{
@@ -243,7 +244,7 @@ private static function formatValueMode0($cellValue): string
243244
*/
244245
private static function formatValueMode1($cellValue): string
245246
{
246-
if (is_string($cellValue) && Functions::isError($cellValue) === false) {
247+
if (is_string($cellValue) && ErrorValue::isError($cellValue) === false) {
247248
return Calculation::FORMULA_STRING_QUOTE . $cellValue . Calculation::FORMULA_STRING_QUOTE;
248249
} elseif (is_bool($cellValue)) {
249250
return Calculation::getLocaleBoolean($cellValue ? 'TRUE' : 'FALSE');

tests/PhpSpreadsheetTests/Calculation/Engine/RangeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Engine;
44

5-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
5+
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
66
use PhpOffice\PhpSpreadsheet\NamedRange;
77
use PhpOffice\PhpSpreadsheet\Spreadsheet;
88
use PHPUnit\Framework\TestCase;
@@ -49,7 +49,7 @@ public function providerRangeEvaluation(): array
4949
'Count with INTERSECTION #1' => ['=COUNT(A1:B3 A1:C2)', 4],
5050
'Sum with UNION #2' => ['=SUM(A1:A3,C1:C3)', 48],
5151
'Count with UNION #2' => ['=COUNT(A1:A3,C1:C3)', 6],
52-
'Sum with INTERSECTION #2 - No Intersect' => ['=SUM(A1:A3 C1:C3)', Functions::null()],
52+
'Sum with INTERSECTION #2 - No Intersect' => ['=SUM(A1:A3 C1:C3)', ExcelError::null()],
5353
'Count with INTERSECTION #2 - No Intersect' => ['=COUNT(A1:A3 C1:C3)', 0],
5454
'Sum with UNION #3' => ['=SUM(A1:B2,B2:C3)', 64],
5555
'Count with UNION #3' => ['=COUNT(A1:B2,B2:C3)', 8],
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information;
4+
5+
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
7+
use PHPUnit\Framework\TestCase;
8+
9+
// Sanity tests for functions which have been moved out of Functions
10+
// to their own classes. A deprecated version remains in Functions;
11+
// this class contains cursory tests to ensure that those work properly.
12+
// If Scrutinizer fails the PR because of these deprecations, I will
13+
// remove this class from the PR.
14+
15+
class DeprecatedFunctionsTest extends TestCase
16+
{
17+
public function testDeprecated(): void
18+
{
19+
self::assertSame('#DIV/0!', /** @scrutinizer ignore-deprecated */ Functions::DIV0());
20+
self::assertSame('#N/A', /** @scrutinizer ignore-deprecated */ Functions::errorType());
21+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isBlank());
22+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isErr('#DIV/0!'));
23+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isError('#DIV/0!'));
24+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isEven(2));
25+
// isFormula needs more complicated test - see next method
26+
self::assertFalse(/** @scrutinizer ignore-deprecated */ Functions::isNa());
27+
self::assertFalse(/** @scrutinizer ignore-deprecated */ Functions::isLogical());
28+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isNonText(2));
29+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isNumber(2));
30+
self::assertFalse(/** @scrutinizer ignore-deprecated */ Functions::isOdd(2));
31+
self::assertFalse(/** @scrutinizer ignore-deprecated */ Functions::isText(2));
32+
self::assertSame('#N/A', /** @scrutinizer ignore-deprecated */ Functions::NA());
33+
self::assertSame('#NAME?', /** @scrutinizer ignore-deprecated */ Functions::NAME());
34+
self::assertSame('#NUM!', /** @scrutinizer ignore-deprecated */ Functions::NAN());
35+
self::assertSame(1, /** @scrutinizer ignore-deprecated */ Functions::n(true));
36+
self::assertSame('#NULL!', /** @scrutinizer ignore-deprecated */ Functions::null());
37+
self::assertSame('#REF!', /** @scrutinizer ignore-deprecated */ Functions::REF());
38+
self::assertSame(1, /** @scrutinizer ignore-deprecated */ Functions::type(7));
39+
self::assertSame('#VALUE!', /** @scrutinizer ignore-deprecated */ Functions::VALUE());
40+
}
41+
42+
public function testIsFormula(): void
43+
{
44+
$spreadsheet = new Spreadsheet();
45+
$sheet = $spreadsheet->getActiveSheet();
46+
$cell = $sheet->getCell('A1');
47+
$cell->setValue('=1');
48+
self::assertTrue(/** @scrutinizer ignore-deprecated */ Functions::isFormula('A1', $cell));
49+
$spreadsheet->disconnectWorksheets();
50+
}
51+
}

0 commit comments

Comments
 (0)