Skip to content

[TASK] Use native void return type declarations #805

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 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Please also have a look at our

### Changed

- Use more native type declarations and strict mode
(#641, #772, #774, #778, #804)
- Mark parsing-internal classes and methods as `@internal` (#674)
- Block installations on unsupported higher PHP versions (#691)
- Improve performance of `Value::parseValue` with many delimiters by refactoring
Expand Down
22 changes: 9 additions & 13 deletions src/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public function __construct($iLineNo = 0)

/**
* @param array<int, DeclarationBlock> $aResult
*
* @return void
*/
protected function allDeclarationBlocks(array &$aResult)
protected function allDeclarationBlocks(array &$aResult): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't help thinking that these all... methods should perhaps be returning the result, rather than having it as a parameter passed by reference - unless the array is supposed to be merged with some original array - but that is beyond the scope of this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looked at the code, and these functions call each other to build up the array, so it does need to be a parameter passed by reference.

{
foreach ($this->aContents as $mContent) {
if ($mContent instanceof DeclarationBlock) {
Expand All @@ -46,10 +44,8 @@ protected function allDeclarationBlocks(array &$aResult)

/**
* @param array<int, RuleSet> $aResult
*
* @return void
*/
protected function allRuleSets(array &$aResult)
protected function allRuleSets(array &$aResult): void
{
foreach ($this->aContents as $mContent) {
if ($mContent instanceof RuleSet) {
Expand All @@ -65,11 +61,13 @@ protected function allRuleSets(array &$aResult)
* @param array<int, Value> $aResult
* @param string|null $sSearchString
* @param bool $bSearchInFunctionArguments
*
* @return void
*/
protected function allValues($oElement, array &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false)
{
protected function allValues(
$oElement,
array &$aResult,
$sSearchString = null,
$bSearchInFunctionArguments = false
): void {
if ($oElement instanceof CSSBlockList) {
foreach ($oElement->getContents() as $oContent) {
$this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments);
Expand All @@ -95,10 +93,8 @@ protected function allValues($oElement, array &$aResult, $sSearchString = null,
/**
* @param array<int, Selector> $aResult
* @param string|null $sSpecificitySearch
*
* @return void
*/
protected function allSelectors(array &$aResult, $sSpecificitySearch = null)
protected function allSelectors(array &$aResult, $sSpecificitySearch = null): void
{
/** @var array<int, DeclarationBlock> $aDeclarationBlocks */
$aDeclarationBlocks = [];
Expand Down
8 changes: 2 additions & 6 deletions src/Comment/Commentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ interface Commentable
{
/**
* @param array<array-key, Comment> $comments
*
* @return void
*/
public function addComments(array $comments);
public function addComments(array $comments): void;

/**
* @return array<array-key, Comment>
Expand All @@ -20,8 +18,6 @@ public function getComments();

/**
* @param array<array-key, Comment> $comments
*
* @return void
*/
public function setComments(array $comments);
public function setComments(array $comments): void;
}
6 changes: 0 additions & 6 deletions src/Property/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public function getLineNo()

/**
* @param string|CSSString $oCharset
*
* @return void
*/
public function setCharset($sCharset): void
{
Expand Down Expand Up @@ -96,8 +94,6 @@ public function atRuleArgs()

/**
* @param array<array-key, Comment> $comments
*
* @return void
*/
public function addComments(array $comments): void
{
Expand All @@ -114,8 +110,6 @@ public function getComments()

/**
* @param array<array-key, Comment> $comments
*
* @return void
*/
public function setComments(array $comments): void
{
Expand Down
2 changes: 0 additions & 2 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ public function getSelector()

/**
* @param string $sSelector
*
* @return void
*/
public function setSelector($sSelector): void
{
Expand Down
2 changes: 0 additions & 2 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ public function addIeHack($iModifier): void

/**
* @param array<int, int> $aModifiers
*
* @return void
*/
public function setIeHack(array $aModifiers): void
{
Expand Down