Skip to content

Commit

Permalink
[TASK] Use native types for all constructor parameters
Browse files Browse the repository at this point in the history
Part of #811
  • Loading branch information
oliverklee committed Jan 27, 2025
1 parent 98e4204 commit 0eba641
Show file tree
Hide file tree
Showing 32 changed files with 32 additions and 136 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please also have a look at our
### Changed

- Use more native type declarations and strict mode
(#641, #772, #774, #778, #804)
(#641, #772, #774, #778, #804, #818)
- 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
7 changes: 1 addition & 6 deletions src/CSSList/AtRuleBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ class AtRuleBlockList extends CSSBlockList implements AtRule
*/
private $sArgs;

/**
* @param string $type
* @param string $arguments
* @param int $lineNumber
*/
public function __construct($type, $arguments = '', $lineNumber = 0)
public function __construct(string $type, string $arguments = '', int $lineNumber = 0)
{
parent::__construct($lineNumber);
$this->type = $type;
Expand Down
5 changes: 1 addition & 4 deletions src/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
abstract class CSSBlockList extends CSSList
{
/**
* @param int $lineNumber
*/
public function __construct($lineNumber = 0)
public function __construct(int $lineNumber = 0)
{
parent::__construct($lineNumber);
}
Expand Down
5 changes: 1 addition & 4 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ abstract class CSSList implements Renderable, Commentable
*/
protected $iLineNo;

/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
$this->comments = [];
$this->aContents = [];
Expand Down
5 changes: 1 addition & 4 deletions src/CSSList/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
*/
class Document extends CSSBlockList
{
/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
parent::__construct($iLineNo);
}
Expand Down
5 changes: 1 addition & 4 deletions src/CSSList/KeyFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class KeyFrame extends CSSList implements AtRule
*/
private $animationName;

/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
parent::__construct($iLineNo);
$this->vendorKeyFrame = null;
Expand Down
6 changes: 1 addition & 5 deletions src/Comment/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ class Comment implements Renderable
*/
protected $commentText;

/**
* @param string $commentText
* @param int $lineNumber
*/
public function __construct($commentText = '', $lineNumber = 0)
public function __construct(string $commentText = '', int $lineNumber = 0)
{
$this->commentText = $commentText;
$this->lineNumber = $lineNumber;
Expand Down
3 changes: 1 addition & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class Parser

/**
* @param string $sText the complete CSS as text (i.e., usually the contents of a CSS file)
* @param Settings|null $oParserSettings
* @param int $iLineNo the line number (starting from 1, not from 0)
*/
public function __construct($sText, ?Settings $oParserSettings = null, $iLineNo = 1)
public function __construct(string $sText, ?Settings $oParserSettings = null, int $iLineNo = 1)
{
if ($oParserSettings === null) {
$oParserSettings = Settings::create();
Expand Down
5 changes: 1 addition & 4 deletions src/Parsing/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class Anchor
*/
private $oParserState;

/**
* @param int $iPosition
*/
public function __construct($iPosition, ParserState $oParserState)
public function __construct(int $iPosition, ParserState $oParserState)
{
$this->iPosition = $iPosition;
$this->oParserState = $oParserState;
Expand Down
6 changes: 1 addition & 5 deletions src/Parsing/OutputException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
*/
final class OutputException extends SourceException
{
/**
* @param string $sMessage
* @param int $iLineNo
*/
public function __construct($sMessage, $iLineNo = 0)
public function __construct(string $sMessage, int $iLineNo = 0)
{
parent::__construct($sMessage, $iLineNo);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ class ParserState

/**
* @param string $sText the complete CSS as text (i.e., usually the contents of a CSS file)
* @param int $iLineNo
*/
public function __construct($sText, Settings $oParserSettings, $iLineNo = 1)
public function __construct(string $sText, Settings $oParserSettings, int $iLineNo = 1)
{
$this->oParserSettings = $oParserSettings;
$this->sText = $sText;
Expand Down
6 changes: 1 addition & 5 deletions src/Parsing/SourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ class SourceException extends \Exception
*/
private $iLineNo;

/**
* @param string $sMessage
* @param int $iLineNo
*/
public function __construct($sMessage, $iLineNo = 0)
public function __construct(string $sMessage, int $iLineNo = 0)
{
$this->iLineNo = $iLineNo;
if ($iLineNo !== 0) {
Expand Down
8 changes: 1 addition & 7 deletions src/Parsing/UnexpectedTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ class UnexpectedTokenException extends SourceException
*/
private $sMatchType;

/**
* @param string $sExpected
* @param string $sFound
* @param string $sMatchType
* @param int $iLineNo
*/
public function __construct($sExpected, $sFound, $sMatchType = 'literal', $iLineNo = 0)
public function __construct(string $sExpected, string $sFound, string $sMatchType = 'literal', int $iLineNo = 0)
{
$this->sExpected = $sExpected;
$this->sFound = $sFound;
Expand Down
7 changes: 1 addition & 6 deletions src/Property/CSSNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ class CSSNamespace implements AtRule
*/
protected $comments;

/**
* @param string $mUrl
* @param string|null $sPrefix
* @param int $iLineNo
*/
public function __construct($mUrl, $sPrefix = null, $iLineNo = 0)
public function __construct(string $mUrl, ?string $sPrefix = null, int $iLineNo = 0)
{
$this->mUrl = $mUrl;
$this->sPrefix = $sPrefix;
Expand Down
6 changes: 1 addition & 5 deletions src/Property/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ class Charset implements AtRule
*/
protected $comments;

/**
* @param CSSString $oCharset
* @param int $iLineNo
*/
public function __construct(CSSString $oCharset, $iLineNo = 0)
public function __construct(CSSString $oCharset, int $iLineNo = 0)
{
$this->oCharset = $oCharset;
$this->iLineNo = $iLineNo;
Expand Down
7 changes: 1 addition & 6 deletions src/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ class Import implements AtRule
*/
protected $comments;

/**
* @param URL $oLocation
* @param string $sMediaQuery
* @param int $iLineNo
*/
public function __construct(URL $oLocation, $sMediaQuery, $iLineNo = 0)
public function __construct(URL $oLocation, string $sMediaQuery, int $iLineNo = 0)
{
$this->oLocation = $oLocation;
$this->sMediaQuery = $sMediaQuery;
Expand Down
6 changes: 1 addition & 5 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ public static function isValid($sSelector)
return \preg_match(static::SELECTOR_VALIDATION_RX, $sSelector);
}

/**
* @param string $sSelector
* @param bool $bCalculateSpecificity
*/
public function __construct($sSelector, $bCalculateSpecificity = false)
public function __construct(string $sSelector, bool $bCalculateSpecificity = false)
{
$this->setSelector($sSelector);
if ($bCalculateSpecificity) {
Expand Down
7 changes: 1 addition & 6 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ class Rule implements Renderable, Commentable
*/
protected $comments;

/**
* @param string $sRule
* @param int $iLineNo
* @param int $iColNo
*/
public function __construct($sRule, $iLineNo = 0, $iColNo = 0)
public function __construct(string $sRule, int $iLineNo = 0, int $iColNo = 0)
{
$this->sRule = $sRule;
$this->mValue = null;
Expand Down
7 changes: 1 addition & 6 deletions src/RuleSet/AtRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ class AtRuleSet extends RuleSet implements AtRule
*/
private $sArgs;

/**
* @param string $sType
* @param string $sArgs
* @param int $iLineNo
*/
public function __construct($sType, $sArgs = '', $iLineNo = 0)
public function __construct(string $sType, string $sArgs = '', int $iLineNo = 0)
{
parent::__construct($iLineNo);
$this->sType = $sType;
Expand Down
5 changes: 1 addition & 4 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class DeclarationBlock extends RuleSet
*/
private $aSelectors;

/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
parent::__construct($iLineNo);
$this->aSelectors = [];
Expand Down
5 changes: 1 addition & 4 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ abstract class RuleSet implements Renderable, Commentable
*/
protected $comments;

/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
$this->aRules = [];
$this->iLineNo = $iLineNo;
Expand Down
5 changes: 1 addition & 4 deletions src/Value/CSSFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ class CSSFunction extends ValueList
protected $sName;

/**
* @param string $sName
* @param RuleValueList|array<array-key, Value|string> $aArguments
* @param string $sSeparator
* @param int $iLineNo
*/
public function __construct($sName, $aArguments, $sSeparator = ',', $iLineNo = 0)
public function __construct(string $sName, $aArguments, string $sSeparator = ',', int $iLineNo = 0)
{
if ($aArguments instanceof RuleValueList) {
$sSeparator = $aArguments->getListSeparator();
Expand Down
6 changes: 1 addition & 5 deletions src/Value/CSSString.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ class CSSString extends PrimitiveValue
*/
private $sString;

/**
* @param string $sString
* @param int $iLineNo
*/
public function __construct($sString, $iLineNo = 0)
public function __construct(string $sString, int $iLineNo = 0)
{
$this->sString = $sString;
parent::__construct($iLineNo);
Expand Down
5 changes: 1 addition & 4 deletions src/Value/CalcRuleValueList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class CalcRuleValueList extends RuleValueList
{
/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
parent::__construct(',', $iLineNo);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Value/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class Color extends CSSFunction
{
/**
* @param array<array-key, Value|string> $colorValues
* @param int $lineNumber
*/
public function __construct(array $colorValues, $lineNumber = 0)
public function __construct(array $colorValues, int $lineNumber = 0)
{
parent::__construct(\implode('', \array_keys($colorValues)), $colorValues, ',', $lineNumber);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Value/LineName.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class LineName extends ValueList
{
/**
* @param array<int, Value|string> $aComponents
* @param int $iLineNo
*/
public function __construct(array $aComponents = [], $iLineNo = 0)
public function __construct(array $aComponents = [], int $iLineNo = 0)
{
parent::__construct($aComponents, ' ', $iLineNo);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Value/PrimitiveValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

abstract class PrimitiveValue extends Value
{
/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
parent::__construct($iLineNo);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Value/RuleValueList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
*/
class RuleValueList extends ValueList
{
/**
* @param string $sSeparator
* @param int $iLineNo
*/
public function __construct($sSeparator = ',', $iLineNo = 0)
public function __construct(string $sSeparator = ',', int $iLineNo = 0)
{
parent::__construct([], $sSeparator, $iLineNo);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ class Size extends PrimitiveValue

/**
* @param float|int|string $fSize
* @param string|null $sUnit
* @param bool $bIsColorComponent
* @param int $iLineNo
*/
public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0)
public function __construct($fSize, ?string $sUnit = null, bool $bIsColorComponent = false, int $iLineNo = 0)
{
parent::__construct($iLineNo);
$this->fSize = (float) $fSize;
Expand Down
5 changes: 1 addition & 4 deletions src/Value/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ class URL extends PrimitiveValue
*/
private $oURL;

/**
* @param int $iLineNo
*/
public function __construct(CSSString $oURL, $iLineNo = 0)
public function __construct(CSSString $oURL, int $iLineNo = 0)
{
parent::__construct($iLineNo);
$this->oURL = $oURL;
Expand Down
5 changes: 1 addition & 4 deletions src/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ abstract class Value implements Renderable
*/
protected $iLineNo;

/**
* @param int $iLineNo
*/
public function __construct($iLineNo = 0)
public function __construct(int $iLineNo = 0)
{
$this->iLineNo = $iLineNo;
}
Expand Down
Loading

0 comments on commit 0eba641

Please sign in to comment.