@@ -50,14 +50,14 @@ class Cell
50
50
private $ dataType ;
51
51
52
52
/**
53
- * Collection of cells.
53
+ * The collection of cells that this cell belongs to (i.e. The Cell Collection for the parent Worksheet) .
54
54
*
55
55
* @var Cells
56
56
*/
57
57
private $ parent ;
58
58
59
59
/**
60
- * Index to cellXf.
60
+ * Index to the cellXf reference for the styling of this cell .
61
61
*
62
62
* @var int
63
63
*/
@@ -95,9 +95,8 @@ public function attach(Cells $parent): void
95
95
* Create a new Cell.
96
96
*
97
97
* @param mixed $value
98
- * @param string $dataType
99
98
*/
100
- public function __construct ($ value , $ dataType , Worksheet $ worksheet )
99
+ public function __construct ($ value , ? string $ dataType , Worksheet $ worksheet )
101
100
{
102
101
// Initialise cell value
103
102
$ this ->value = $ value ;
@@ -111,7 +110,7 @@ public function __construct($value, $dataType, Worksheet $worksheet)
111
110
$ dataType = DataType::TYPE_STRING ;
112
111
}
113
112
$ this ->dataType = $ dataType ;
114
- } elseif (! self ::getValueBinder ()->bindValue ($ this , $ value )) {
113
+ } elseif (self ::getValueBinder ()->bindValue ($ this , $ value ) === false ) {
115
114
throw new Exception ('Value could not be bound to cell. ' );
116
115
}
117
116
}
@@ -167,10 +166,8 @@ public function getValue()
167
166
168
167
/**
169
168
* Get cell value with formatting.
170
- *
171
- * @return string
172
169
*/
173
- public function getFormattedValue ()
170
+ public function getFormattedValue (): string
174
171
{
175
172
return (string ) NumberFormat::toFormattedString (
176
173
$ this ->getCalculatedValue (),
@@ -188,7 +185,7 @@ public function getFormattedValue()
188
185
*
189
186
* @return $this
190
187
*/
191
- public function setValue ($ value )
188
+ public function setValue ($ value ): self
192
189
{
193
190
if (!self ::getValueBinder ()->bindValue ($ this , $ value )) {
194
191
throw new Exception ('Value could not be bound to cell. ' );
@@ -205,7 +202,7 @@ public function setValue($value)
205
202
* Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
206
203
* method, then it is your responsibility as an end-user developer to validate that the value and
207
204
* the datatype match.
208
- * If you do mismatch value and datatpe , then the value you enter may be changed to match the datatype
205
+ * If you do mismatch value and datatype , then the value you enter may be changed to match the datatype
209
206
* that you specify.
210
207
*
211
208
* @return Cell
@@ -271,7 +268,7 @@ public function setValueExplicit($value, $dataType)
271
268
*
272
269
* @return mixed
273
270
*/
274
- public function getCalculatedValue ($ resetLog = true )
271
+ public function getCalculatedValue (bool $ resetLog = true )
275
272
{
276
273
if ($ this ->dataType === DataType::TYPE_FORMULA ) {
277
274
try {
@@ -319,7 +316,7 @@ public function getCalculatedValue($resetLog = true)
319
316
*
320
317
* @return Cell
321
318
*/
322
- public function setCalculatedValue ($ originalValue )
319
+ public function setCalculatedValue ($ originalValue ): self
323
320
{
324
321
if ($ originalValue !== null ) {
325
322
$ this ->calculatedValue = (is_numeric ($ originalValue )) ? (float ) $ originalValue : $ originalValue ;
@@ -345,10 +342,8 @@ public function getOldCalculatedValue()
345
342
346
343
/**
347
344
* Get cell data type.
348
- *
349
- * @return string
350
345
*/
351
- public function getDataType ()
346
+ public function getDataType (): string
352
347
{
353
348
return $ this ->dataType ;
354
349
}
@@ -360,7 +355,7 @@ public function getDataType()
360
355
*
361
356
* @return Cell
362
357
*/
363
- public function setDataType ($ dataType )
358
+ public function setDataType ($ dataType ): self
364
359
{
365
360
if ($ dataType == DataType::TYPE_STRING2 ) {
366
361
$ dataType = DataType::TYPE_STRING ;
@@ -392,10 +387,8 @@ public function hasDataValidation(): bool
392
387
393
388
/**
394
389
* Get Data validation rules.
395
- *
396
- * @return DataValidation
397
390
*/
398
- public function getDataValidation ()
391
+ public function getDataValidation (): DataValidation
399
392
{
400
393
if (!isset ($ this ->parent )) {
401
394
throw new Exception ('Cannot get data validation for cell that is not bound to a worksheet ' );
@@ -420,10 +413,8 @@ public function setDataValidation(?DataValidation $dataValidation = null): self
420
413
421
414
/**
422
415
* Does this cell contain valid value?
423
- *
424
- * @return bool
425
416
*/
426
- public function hasValidValue ()
417
+ public function hasValidValue (): bool
427
418
{
428
419
$ validator = new DataValidator ();
429
420
@@ -432,10 +423,8 @@ public function hasValidValue()
432
423
433
424
/**
434
425
* Does this cell contain a Hyperlink?
435
- *
436
- * @return bool
437
426
*/
438
- public function hasHyperlink ()
427
+ public function hasHyperlink (): bool
439
428
{
440
429
if (!isset ($ this ->parent )) {
441
430
throw new Exception ('Cannot check for hyperlink when cell is not bound to a worksheet ' );
@@ -446,10 +435,8 @@ public function hasHyperlink()
446
435
447
436
/**
448
437
* Get Hyperlink.
449
- *
450
- * @return Hyperlink
451
438
*/
452
- public function getHyperlink ()
439
+ public function getHyperlink (): Hyperlink
453
440
{
454
441
if (!isset ($ this ->parent )) {
455
442
throw new Exception ('Cannot get hyperlink for cell that is not bound to a worksheet ' );
@@ -463,7 +450,7 @@ public function getHyperlink()
463
450
*
464
451
* @return Cell
465
452
*/
466
- public function setHyperlink (?Hyperlink $ hyperlink = null )
453
+ public function setHyperlink (?Hyperlink $ hyperlink = null ): self
467
454
{
468
455
if (!isset ($ this ->parent )) {
469
456
throw new Exception ('Cannot set hyperlink for cell that is not bound to a worksheet ' );
@@ -486,10 +473,8 @@ public function getParent()
486
473
487
474
/**
488
475
* Get parent worksheet.
489
- *
490
- * @return Worksheet
491
476
*/
492
- public function getWorksheet ()
477
+ public function getWorksheet (): Worksheet
493
478
{
494
479
try {
495
480
$ worksheet = $ this ->parent ->getParent ();
@@ -506,27 +491,22 @@ public function getWorksheet()
506
491
507
492
/**
508
493
* Is this cell in a merge range.
509
- *
510
- * @return bool
511
494
*/
512
- public function isInMergeRange ()
495
+ public function isInMergeRange (): bool
513
496
{
514
497
return (bool ) $ this ->getMergeRange ();
515
498
}
516
499
517
500
/**
518
501
* Is this cell the master (top left cell) in a merge range (that holds the actual data value).
519
- *
520
- * @return bool
521
502
*/
522
- public function isMergeRangeValueCell ()
503
+ public function isMergeRangeValueCell (): bool
523
504
{
524
505
if ($ mergeRange = $ this ->getMergeRange ()) {
525
506
$ mergeRange = Coordinate::splitRange ($ mergeRange );
526
507
[$ startCell ] = $ mergeRange [0 ];
527
- if ($ this ->getCoordinate () === $ startCell ) {
528
- return true ;
529
- }
508
+
509
+ return $ this ->getCoordinate () === $ startCell ;
530
510
}
531
511
532
512
return false ;
@@ -579,7 +559,7 @@ public function getAppliedStyle(): Style
579
559
*
580
560
* @return Cell
581
561
*/
582
- public function rebindParent (Worksheet $ parent )
562
+ public function rebindParent (Worksheet $ parent ): self
583
563
{
584
564
$ this ->parent = $ parent ->getCellCollection ();
585
565
@@ -590,10 +570,8 @@ public function rebindParent(Worksheet $parent)
590
570
* Is cell in a specific range?
591
571
*
592
572
* @param string $range Cell range (e.g. A1:A1)
593
- *
594
- * @return bool
595
573
*/
596
- public function isInRange ($ range )
574
+ public function isInRange (string $ range ): bool
597
575
{
598
576
[$ rangeStart , $ rangeEnd ] = Coordinate::rangeBoundaries ($ range );
599
577
@@ -614,7 +592,7 @@ public function isInRange($range)
614
592
*
615
593
* @return int Result of comparison (always -1 or 1, never zero!)
616
594
*/
617
- public static function compareCells (self $ a , self $ b )
595
+ public static function compareCells (self $ a , self $ b ): int
618
596
{
619
597
if ($ a ->getRow () < $ b ->getRow ()) {
620
598
return -1 ;
@@ -629,10 +607,8 @@ public static function compareCells(self $a, self $b)
629
607
630
608
/**
631
609
* Get value binder to use.
632
- *
633
- * @return IValueBinder
634
610
*/
635
- public static function getValueBinder ()
611
+ public static function getValueBinder (): IValueBinder
636
612
{
637
613
if (self ::$ valueBinder === null ) {
638
614
self ::$ valueBinder = new DefaultValueBinder ();
@@ -655,33 +631,29 @@ public static function setValueBinder(IValueBinder $binder): void
655
631
public function __clone ()
656
632
{
657
633
$ vars = get_object_vars ($ this );
658
- foreach ($ vars as $ key => $ value ) {
659
- if ((is_object ($ value )) && ($ key ! = 'parent ' )) {
660
- $ this ->$ key = clone $ value ;
634
+ foreach ($ vars as $ propertyName => $ propertyValue ) {
635
+ if ((is_object ($ propertyValue )) && ($ propertyName != = 'parent ' )) {
636
+ $ this ->$ propertyName = clone $ propertyValue ;
661
637
} else {
662
- $ this ->$ key = $ value ;
638
+ $ this ->$ propertyName = $ propertyValue ;
663
639
}
664
640
}
665
641
}
666
642
667
643
/**
668
644
* Get index to cellXf.
669
- *
670
- * @return int
671
645
*/
672
- public function getXfIndex ()
646
+ public function getXfIndex (): int
673
647
{
674
648
return $ this ->xfIndex ;
675
649
}
676
650
677
651
/**
678
652
* Set index to cellXf.
679
653
*
680
- * @param int $indexValue
681
- *
682
654
* @return Cell
683
655
*/
684
- public function setXfIndex ($ indexValue )
656
+ public function setXfIndex (int $ indexValue ): self
685
657
{
686
658
$ this ->xfIndex = $ indexValue ;
687
659
@@ -695,7 +667,7 @@ public function setXfIndex($indexValue)
695
667
*
696
668
* @return $this
697
669
*/
698
- public function setFormulaAttributes ($ attributes )
670
+ public function setFormulaAttributes ($ attributes ): self
699
671
{
700
672
$ this ->formulaAttributes = $ attributes ;
701
673
0 commit comments