Skip to content

Commit

Permalink
Merge pull request #184 from phpfui/PHP8.1
Browse files Browse the repository at this point in the history
Adding #[\ReturnTypeWillChange] for PHP8.1 compatibility
  • Loading branch information
zbateson committed Dec 8, 2021
2 parents fc0e05d + 123dc3a commit b969a8a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Message/MessagePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ public function __construct(PartStreamContainer $streamContainer, IMimePart $par
$this->observers = new SplObjectStorage();
}

#[\ReturnTypeWillChange]
public function attach(SplObserver $observer)
{
$this->observers->attach($observer);
}

#[\ReturnTypeWillChange]
public function detach(SplObserver $observer)
{
$this->observers->detach($observer);
}

#[\ReturnTypeWillChange]
public function notify()
{
foreach ($this->observers as $observer) {
Expand Down
14 changes: 13 additions & 1 deletion src/Message/PartChildrenContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public function __construct(array $children = [])
* Returns true if the current element is an IMultiPart and doesn't return
* null for {@see IMultiPart::getChildIterator()}. Note that the iterator
* may still be empty.
*
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function hasChildren()
{
return ($this->current() instanceof IMultiPart
Expand All @@ -52,6 +53,7 @@ public function hasChildren()
*
* @return RecursiveIterator|null the iterator
*/
#[\ReturnTypeWillChange]
public function getChildren()
{
if ($this->current() instanceof IMultiPart) {
Expand All @@ -60,26 +62,31 @@ public function getChildren()
return null;
}

#[\ReturnTypeWillChange]
public function current()
{
return $this->offsetGet($this->position);
}

#[\ReturnTypeWillChange]
public function key()
{
return $this->position;
}

#[\ReturnTypeWillChange]
public function next()
{
++$this->position;
}

#[\ReturnTypeWillChange]
public function rewind()
{
$this->position = 0;
}

#[\ReturnTypeWillChange]
public function valid()
{
return $this->offsetExists($this->position);
Expand Down Expand Up @@ -112,6 +119,7 @@ public function add(IMessagePart $part, $position = null)
* @param IMessagePart $part The part to remove.
* @return int the 0-based position it previously occupied.
*/
#[\ReturnTypeWillChange]
public function remove(IMessagePart $part)
{
foreach ($this->children as $key => $child) {
Expand All @@ -123,16 +131,19 @@ public function remove(IMessagePart $part)
return null;
}

#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->children[$offset]);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->offsetExists($offset) ? $this->children[$offset] : null;
}

#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if (!$value instanceof IMessagePart) {
Expand All @@ -147,6 +158,7 @@ public function offsetSet($offset, $value)
}
}

#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
array_splice($this->children, $offset, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/Message/PartHeaderContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private function getAllWithOriginalHeaderNameIfSet($name)
/**
* Returns the IHeader object for the header with the given $name, or null
* if none exist.
*
*
* An optional offset can be provided, which defaults to the first header in
* the collection when more than one header with the same name exists.
*
Expand Down Expand Up @@ -290,6 +290,7 @@ public function getHeaders()
*
* @return ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->getHeaders());
Expand Down
3 changes: 2 additions & 1 deletion src/Parser/Part/ParserPartStreamContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* stream as the part's stream instead of the PartStreamContainer's
* MessagePartStream (which dynamically creates a stream from an IMessagePart)
* unless the part changed.
*
*
* The ParserPartStreamContainer must also be attached to its underlying part
* with SplSubject::attach() so the ParserPartStreamContainer gets notified of
* any changes.
Expand Down Expand Up @@ -143,6 +143,7 @@ public function getStream()
return parent::getStream();
}

#[\ReturnTypeWillChange]
public function update(SplSubject $subject)
{
$this->partUpdated = true;
Expand Down
7 changes: 4 additions & 3 deletions src/Stream/MessagePartStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MessagePartStream implements StreamInterface, SplObserver

/**
* Constructor
*
*
* @param StreamFactory $sdf
* @param IMessagePart $part
*/
Expand All @@ -59,6 +59,7 @@ public function __destruct()
}
}

#[\ReturnTypeWillChange]
public function update(SplSubject $subject)
{
if ($this->appendStream !== null) {
Expand Down Expand Up @@ -89,7 +90,7 @@ private function getCharsetDecoratorForStream(StreamInterface $stream)
}
return $stream;
}

/**
* Attaches and returns a transfer encoding stream decorator to the passed
* $stream.
Expand Down Expand Up @@ -173,7 +174,7 @@ function ($child) {
$streams[] = $child->getStream();
}
$streams[] = Psr7\Utils::streamFor("\r\n--$boundary--\r\n");

return $streams;
}

Expand Down

0 comments on commit b969a8a

Please sign in to comment.