@@ -50,14 +50,14 @@ class Cell
5050 private $ dataType ;
5151
5252 /**
53- * Collection of cells.
53+ * The collection of cells that this cell belongs to (i.e. The Cell Collection for the parent Worksheet) .
5454 *
5555 * @var Cells
5656 */
5757 private $ parent ;
5858
5959 /**
60- * Index to cellXf.
60+ * Index to the cellXf reference for the styling of this cell .
6161 *
6262 * @var int
6363 */
@@ -95,9 +95,8 @@ public function attach(Cells $parent): void
9595 * Create a new Cell.
9696 *
9797 * @param mixed $value
98- * @param string $dataType
9998 */
100- public function __construct ($ value , $ dataType , Worksheet $ worksheet )
99+ public function __construct ($ value , ? string $ dataType , Worksheet $ worksheet )
101100 {
102101 // Initialise cell value
103102 $ this ->value = $ value ;
@@ -111,7 +110,7 @@ public function __construct($value, $dataType, Worksheet $worksheet)
111110 $ dataType = DataType::TYPE_STRING ;
112111 }
113112 $ this ->dataType = $ dataType ;
114- } elseif (! self ::getValueBinder ()->bindValue ($ this , $ value )) {
113+ } elseif (self ::getValueBinder ()->bindValue ($ this , $ value ) === false ) {
115114 throw new Exception ('Value could not be bound to cell. ' );
116115 }
117116 }
@@ -167,10 +166,8 @@ public function getValue()
167166
168167 /**
169168 * Get cell value with formatting.
170- *
171- * @return string
172169 */
173- public function getFormattedValue ()
170+ public function getFormattedValue (): string
174171 {
175172 return (string ) NumberFormat::toFormattedString (
176173 $ this ->getCalculatedValue (),
@@ -188,7 +185,7 @@ public function getFormattedValue()
188185 *
189186 * @return $this
190187 */
191- public function setValue ($ value )
188+ public function setValue ($ value ): self
192189 {
193190 if (!self ::getValueBinder ()->bindValue ($ this , $ value )) {
194191 throw new Exception ('Value could not be bound to cell. ' );
@@ -205,7 +202,7 @@ public function setValue($value)
205202 * Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
206203 * method, then it is your responsibility as an end-user developer to validate that the value and
207204 * 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
209206 * that you specify.
210207 *
211208 * @return Cell
@@ -271,7 +268,7 @@ public function setValueExplicit($value, $dataType)
271268 *
272269 * @return mixed
273270 */
274- public function getCalculatedValue ($ resetLog = true )
271+ public function getCalculatedValue (bool $ resetLog = true )
275272 {
276273 if ($ this ->dataType === DataType::TYPE_FORMULA ) {
277274 try {
@@ -319,7 +316,7 @@ public function getCalculatedValue($resetLog = true)
319316 *
320317 * @return Cell
321318 */
322- public function setCalculatedValue ($ originalValue )
319+ public function setCalculatedValue ($ originalValue ): self
323320 {
324321 if ($ originalValue !== null ) {
325322 $ this ->calculatedValue = (is_numeric ($ originalValue )) ? (float ) $ originalValue : $ originalValue ;
@@ -345,10 +342,8 @@ public function getOldCalculatedValue()
345342
346343 /**
347344 * Get cell data type.
348- *
349- * @return string
350345 */
351- public function getDataType ()
346+ public function getDataType (): string
352347 {
353348 return $ this ->dataType ;
354349 }
@@ -360,7 +355,7 @@ public function getDataType()
360355 *
361356 * @return Cell
362357 */
363- public function setDataType ($ dataType )
358+ public function setDataType ($ dataType ): self
364359 {
365360 if ($ dataType == DataType::TYPE_STRING2 ) {
366361 $ dataType = DataType::TYPE_STRING ;
@@ -392,10 +387,8 @@ public function hasDataValidation(): bool
392387
393388 /**
394389 * Get Data validation rules.
395- *
396- * @return DataValidation
397390 */
398- public function getDataValidation ()
391+ public function getDataValidation (): DataValidation
399392 {
400393 if (!isset ($ this ->parent )) {
401394 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
420413
421414 /**
422415 * Does this cell contain valid value?
423- *
424- * @return bool
425416 */
426- public function hasValidValue ()
417+ public function hasValidValue (): bool
427418 {
428419 $ validator = new DataValidator ();
429420
@@ -432,10 +423,8 @@ public function hasValidValue()
432423
433424 /**
434425 * Does this cell contain a Hyperlink?
435- *
436- * @return bool
437426 */
438- public function hasHyperlink ()
427+ public function hasHyperlink (): bool
439428 {
440429 if (!isset ($ this ->parent )) {
441430 throw new Exception ('Cannot check for hyperlink when cell is not bound to a worksheet ' );
@@ -446,10 +435,8 @@ public function hasHyperlink()
446435
447436 /**
448437 * Get Hyperlink.
449- *
450- * @return Hyperlink
451438 */
452- public function getHyperlink ()
439+ public function getHyperlink (): Hyperlink
453440 {
454441 if (!isset ($ this ->parent )) {
455442 throw new Exception ('Cannot get hyperlink for cell that is not bound to a worksheet ' );
@@ -463,7 +450,7 @@ public function getHyperlink()
463450 *
464451 * @return Cell
465452 */
466- public function setHyperlink (?Hyperlink $ hyperlink = null )
453+ public function setHyperlink (?Hyperlink $ hyperlink = null ): self
467454 {
468455 if (!isset ($ this ->parent )) {
469456 throw new Exception ('Cannot set hyperlink for cell that is not bound to a worksheet ' );
@@ -486,10 +473,8 @@ public function getParent()
486473
487474 /**
488475 * Get parent worksheet.
489- *
490- * @return Worksheet
491476 */
492- public function getWorksheet ()
477+ public function getWorksheet (): Worksheet
493478 {
494479 try {
495480 $ worksheet = $ this ->parent ->getParent ();
@@ -506,27 +491,22 @@ public function getWorksheet()
506491
507492 /**
508493 * Is this cell in a merge range.
509- *
510- * @return bool
511494 */
512- public function isInMergeRange ()
495+ public function isInMergeRange (): bool
513496 {
514497 return (bool ) $ this ->getMergeRange ();
515498 }
516499
517500 /**
518501 * Is this cell the master (top left cell) in a merge range (that holds the actual data value).
519- *
520- * @return bool
521502 */
522- public function isMergeRangeValueCell ()
503+ public function isMergeRangeValueCell (): bool
523504 {
524505 if ($ mergeRange = $ this ->getMergeRange ()) {
525506 $ mergeRange = Coordinate::splitRange ($ mergeRange );
526507 [$ startCell ] = $ mergeRange [0 ];
527- if ($ this ->getCoordinate () === $ startCell ) {
528- return true ;
529- }
508+
509+ return $ this ->getCoordinate () === $ startCell ;
530510 }
531511
532512 return false ;
@@ -579,7 +559,7 @@ public function getAppliedStyle(): Style
579559 *
580560 * @return Cell
581561 */
582- public function rebindParent (Worksheet $ parent )
562+ public function rebindParent (Worksheet $ parent ): self
583563 {
584564 $ this ->parent = $ parent ->getCellCollection ();
585565
@@ -590,10 +570,8 @@ public function rebindParent(Worksheet $parent)
590570 * Is cell in a specific range?
591571 *
592572 * @param string $range Cell range (e.g. A1:A1)
593- *
594- * @return bool
595573 */
596- public function isInRange ($ range )
574+ public function isInRange (string $ range ): bool
597575 {
598576 [$ rangeStart , $ rangeEnd ] = Coordinate::rangeBoundaries ($ range );
599577
@@ -614,7 +592,7 @@ public function isInRange($range)
614592 *
615593 * @return int Result of comparison (always -1 or 1, never zero!)
616594 */
617- public static function compareCells (self $ a , self $ b )
595+ public static function compareCells (self $ a , self $ b ): int
618596 {
619597 if ($ a ->getRow () < $ b ->getRow ()) {
620598 return -1 ;
@@ -629,10 +607,8 @@ public static function compareCells(self $a, self $b)
629607
630608 /**
631609 * Get value binder to use.
632- *
633- * @return IValueBinder
634610 */
635- public static function getValueBinder ()
611+ public static function getValueBinder (): IValueBinder
636612 {
637613 if (self ::$ valueBinder === null ) {
638614 self ::$ valueBinder = new DefaultValueBinder ();
@@ -655,33 +631,29 @@ public static function setValueBinder(IValueBinder $binder): void
655631 public function __clone ()
656632 {
657633 $ 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 ;
661637 } else {
662- $ this ->$ key = $ value ;
638+ $ this ->$ propertyName = $ propertyValue ;
663639 }
664640 }
665641 }
666642
667643 /**
668644 * Get index to cellXf.
669- *
670- * @return int
671645 */
672- public function getXfIndex ()
646+ public function getXfIndex (): int
673647 {
674648 return $ this ->xfIndex ;
675649 }
676650
677651 /**
678652 * Set index to cellXf.
679653 *
680- * @param int $indexValue
681- *
682654 * @return Cell
683655 */
684- public function setXfIndex ($ indexValue )
656+ public function setXfIndex (int $ indexValue ): self
685657 {
686658 $ this ->xfIndex = $ indexValue ;
687659
@@ -695,7 +667,7 @@ public function setXfIndex($indexValue)
695667 *
696668 * @return $this
697669 */
698- public function setFormulaAttributes ($ attributes )
670+ public function setFormulaAttributes ($ attributes ): self
699671 {
700672 $ this ->formulaAttributes = $ attributes ;
701673
0 commit comments