Skip to content

Fix PHP 8.1 deprecations #1016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Util/YamlSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ private function updateContents(string $newContents, array $newData, int $newPos
private function convertToYaml($data)
{
$indent = $this->depth > 0 && isset($this->indentationForDepths[$this->depth])
? $this->indentationForDepths[$this->depth] / $this->depth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 This division might evaluate to a float value. The problem is that $indent is implicitly cast to an integer later and PHP 8.1 will complain if that implicit cast would result in a loss of precision. Since the loss in precision is actually desired here, I'm performing an integer division instead which will always yield an integer.

? intdiv($this->indentationForDepths[$this->depth], $this->depth)
: 4;

$newDataString = Yaml::dump($data, 4, $indent);
Expand Down Expand Up @@ -1132,7 +1132,7 @@ private function removeMetadataKeys(array $data)
unset($data[$key]);
}

if (0 === strpos($val, self::COMMENT_PLACEHOLDER_VALUE)) {
if (null !== $val && 0 === strpos($val, self::COMMENT_PLACEHOLDER_VALUE)) {
Copy link
Member Author

@derrabus derrabus Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Passing null to strpos() will trigger a deprecation on PHP 8.1.

unset($data[$key]);
}
}
Expand Down