Skip to content
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
90 changes: 45 additions & 45 deletions src/CssLint/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@ class Linter
* @return boolean : true if the string is a valid css string, false else
* @throws \InvalidArgumentException
*/
public function lintString($sString)
public function lintString(string $sString): bool
{
if (!is_string($sString)) {
throw new \InvalidArgumentException('Argument "$sString" expects a string, "' . (is_object($sString) ? get_class($sString) : gettype($sString)) . '" given');
}

$this->initLint();
$iIterator = 0;
while (isset($sString[$iIterator])) {
Expand All @@ -100,12 +96,8 @@ public function lintString($sString)
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function lintFile($sFilePath)
public function lintFile(string $sFilePath): bool
{
if (!is_string($sFilePath)) {
throw new \InvalidArgumentException('Argument "$sFilePath" expects a string, "' . (is_object($sFilePath) ? get_class($sFilePath) : gettype($sFilePath)) . '" given');
}

if (!file_exists($sFilePath)) {
throw new \InvalidArgumentException('Argument "$sFilePath" "' . $sFilePath . '" is not an existing file path');
}
Expand Down Expand Up @@ -161,7 +153,7 @@ protected function initLint()
* @param string $sChar
* @return boolean : true if the process should continue, else false
*/
protected function lintChar($sChar)
protected function lintChar(string $sChar): ?bool
{
$this->incrementCharNumber();
if ($this->isEndOfLine($sChar)) {
Expand Down Expand Up @@ -212,7 +204,7 @@ protected function lintChar($sChar)
* @param string $sChar
* @return boolean|null : true if the process should continue, else false, null if this char is not about comment
*/
protected function lintCommentChar($sChar)
protected function lintCommentChar(string $sChar): ?bool
{
// Manage comment context
if ($this->isComment()) {
Expand All @@ -231,14 +223,16 @@ protected function lintCommentChar($sChar)
$this->setComment(true);
return true;
}

return null;
}

/**
* Performs lint for a given char, check selector part
* @param string $sChar
* @return boolean|null : true if the process should continue, else false, null if this char is not about selector
*/
protected function lintSelectorChar($sChar)
protected function lintSelectorChar(string $sChar): ?bool
{
// Selector must start by #.a-zA-Z
if ($this->assertContext(null)) {
Expand All @@ -250,7 +244,7 @@ protected function lintSelectorChar($sChar)
$this->addContextContent($sChar);
return true;
}
return;
return null;
}
// Selector must contains
if ($this->assertContext(self::CONTEXT_SELECTOR)) {
Expand Down Expand Up @@ -321,17 +315,19 @@ protected function lintSelectorChar($sChar)
$this->addError('Unexpected selector token "' . $sChar . '"');
return true;
}

return null;
}

/**
* Performs lint for a given char, check selector content part
* @param string $sChar
* @return boolean|null : true if the process should continue, else false, null if this char is not about selector content
*/
protected function lintSelectorContentChar($sChar)
protected function lintSelectorContentChar(string $sChar): ?bool
{
if (!$this->assertContext(self::CONTEXT_SELECTOR_CONTENT)) {
return;
return null;
}
if ($sChar === ' ') {
return true;
Expand All @@ -350,17 +346,19 @@ protected function lintSelectorContentChar($sChar)
$this->addContextContent($sChar);
return true;
}

return null;
}

/**
* Performs lint for a given char, check property name part
* @param string $sChar
* @return boolean|null : true if the process should continue, else false, null if this char is not about property name
*/
protected function lintPropertyNameChar($sChar)
protected function lintPropertyNameChar(string $sChar): ?bool
{
if (!$this->assertContext(self::CONTEXT_PROPERTY_NAME)) {
return;
return null;
}

if ($sChar === ':') {
Expand Down Expand Up @@ -391,10 +389,10 @@ protected function lintPropertyNameChar($sChar)
* @param string $sChar
* @return boolean|null : true if the process should continue, else false, null if this char is not about property content
*/
protected function lintPropertyContentChar($sChar)
protected function lintPropertyContentChar(string $sChar): ?bool
{
if (!$this->assertContext(self::CONTEXT_PROPERTY_CONTENT)) {
return;
return null;
}

$this->addContextContent($sChar);
Expand All @@ -421,21 +419,23 @@ protected function lintPropertyContentChar($sChar)
* @param string $sChar
* @return boolean|null : true if the process should continue, else false, null if this char is not about nested selector
*/
protected function lintNestedSelectorChar($sChar)
protected function lintNestedSelectorChar(string $sChar): ?bool
{
// End of nested selector
if ($this->isNestedSelector() && $this->assertContext(null) && $sChar === '}') {
$this->setNestedSelector(false);
return true;
}

return null;
}

/**
* Check if a given char is an end of line token
* @param string $sChar
* @return boolean : true if the char is an end of line token, else false
*/
protected function isEndOfLine($sChar)
protected function isEndOfLine(string $sChar): bool
{
return $sChar === "\r" || $sChar === "\n";
}
Expand All @@ -444,7 +444,7 @@ protected function isEndOfLine($sChar)
* Return the current char number
* @return int
*/
protected function getCharNumber()
protected function getCharNumber(): int
{
return $this->charNumber;
}
Expand All @@ -454,7 +454,7 @@ protected function getCharNumber()
* @param string $sChar
* @return boolean
*/
protected function assertPreviousChar($sChar)
protected function assertPreviousChar(string $sChar): bool
{
return $this->previousChar === $sChar;
}
Expand All @@ -463,7 +463,7 @@ protected function assertPreviousChar($sChar)
* Reset previous char property
* @return \CssLint\Linter
*/
protected function resetPreviousChar()
protected function resetPreviousChar(): Linter
{
$this->previousChar = null;
return $this;
Expand All @@ -474,7 +474,7 @@ protected function resetPreviousChar()
* @param string $sChar
* @return \CssLint\Linter
*/
protected function setPreviousChar($sChar)
protected function setPreviousChar(string $sChar): Linter
{
$this->previousChar = $sChar;
return $this;
Expand All @@ -484,7 +484,7 @@ protected function setPreviousChar($sChar)
* Return the current line number
* @return int
*/
protected function getLineNumber()
protected function getLineNumber(): int
{
return $this->lineNumber;
}
Expand All @@ -493,7 +493,7 @@ protected function getLineNumber()
* Add 1 to the current line number
* @return \CssLint\Linter
*/
protected function incrementLineNumber()
protected function incrementLineNumber(): Linter
{
$this->lineNumber++;
return $this;
Expand All @@ -503,7 +503,7 @@ protected function incrementLineNumber()
* Reset current line number property
* @return \CssLint\Linter
*/
protected function resetLineNumber()
protected function resetLineNumber(): Linter
{
$this->lineNumber = 0;
return $this;
Expand All @@ -513,7 +513,7 @@ protected function resetLineNumber()
* Reset current char number property
* @return \CssLint\Linter
*/
protected function resetCharNumber()
protected function resetCharNumber(): Linter
{
$this->charNumber = 0;
return $this;
Expand All @@ -523,7 +523,7 @@ protected function resetCharNumber()
* Add 1 to the current char number
* @return \CssLint\Linter
*/
protected function incrementCharNumber()
protected function incrementCharNumber(): Linter
{
$this->charNumber++;
return $this;
Expand All @@ -534,7 +534,7 @@ protected function incrementCharNumber()
* @param string|array $sContext
* @return boolean
*/
protected function assertContext($sContext)
protected function assertContext($sContext): bool
{
if (is_array($sContext)) {
foreach ($sContext as $sTmpContext) {
Expand All @@ -551,7 +551,7 @@ protected function assertContext($sContext)
* Reset context property
* @return \CssLint\Linter
*/
protected function resetContext()
protected function resetContext(): Linter
{
return $this->setContext(null);
}
Expand All @@ -561,7 +561,7 @@ protected function resetContext()
* @param string $sContext
* @return \CssLint\Linter
*/
protected function setContext($sContext)
protected function setContext($sContext): Linter
{
$this->context = $sContext;
return $this->resetContextContent();
Expand All @@ -571,7 +571,7 @@ protected function setContext($sContext)
* Return context content
* @return string
*/
protected function getContextContent()
protected function getContextContent(): string
{
return $this->contextContent;
}
Expand All @@ -580,7 +580,7 @@ protected function getContextContent()
* Reset context content property
* @return \CssLint\Linter
*/
protected function resetContextContent()
protected function resetContextContent(): Linter
{
$this->contextContent = '';
return $this;
Expand All @@ -591,7 +591,7 @@ protected function resetContextContent()
* @param string $sContextContent
* @return \CssLint\Linter
*/
protected function addContextContent($sContextContent)
protected function addContextContent($sContextContent): Linter
{
$this->contextContent .= $sContextContent;
return $this;
Expand All @@ -602,7 +602,7 @@ protected function addContextContent($sContextContent)
* @param string $sError
* @return \CssLint\Linter
*/
protected function addError($sError)
protected function addError($sError): Linter
{
$this->errors[] = $sError . ' (line: ' . $this->getLineNumber() . ', char: ' . $this->getCharNumber() . ')';
return $this;
Expand All @@ -612,7 +612,7 @@ protected function addError($sError)
* Return the errors occurred during the lint process
* @return array
*/
public function getErrors()
public function getErrors(): ?array
{
return $this->errors;
}
Expand All @@ -621,7 +621,7 @@ public function getErrors()
* Reset the errors property
* @return \CssLint\Linter
*/
protected function resetErrors()
protected function resetErrors(): Linter
{
$this->errors = null;
return $this;
Expand All @@ -631,7 +631,7 @@ protected function resetErrors()
* Tells if the linter is parsing a nested selector
* @return boolean
*/
protected function isNestedSelector()
protected function isNestedSelector(): bool
{
return $this->nestedSelector;
}
Expand All @@ -640,7 +640,7 @@ protected function isNestedSelector()
* Set the nested selector flag
* @param boolean $bNestedSelector
*/
protected function setNestedSelector($bNestedSelector)
protected function setNestedSelector(bool $bNestedSelector): void
{
$this->nestedSelector = $bNestedSelector;
}
Expand All @@ -649,7 +649,7 @@ protected function setNestedSelector($bNestedSelector)
* Tells if the linter is parsing a comment
* @return boolean
*/
protected function isComment()
protected function isComment(): bool
{
return $this->comment;
}
Expand All @@ -658,7 +658,7 @@ protected function isComment()
* Set the comment flag
* @param boolean $bComment
*/
protected function setComment($bComment)
protected function setComment(bool $bComment): void
{
$this->comment = $bComment;
}
Expand All @@ -667,7 +667,7 @@ protected function setComment($bComment)
* Return an instance of the "\CssLint\Properties" helper, initialize a new one if not define already
* @return \CssLint\Properties
*/
public function getCssLintProperties()
public function getCssLintProperties(): Properties
{
if (!$this->cssLintProperties) {
$this->cssLintProperties = new \CssLint\Properties();
Expand Down
2 changes: 1 addition & 1 deletion src/CssLint/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class Properties
* @param string $sProperty
* @return boolean
*/
public static function propertyExists($sProperty)
public static function propertyExists(string $sProperty): bool
{
if (isset(static::$standards[$sProperty])) {
return true;
Expand Down