@@ -71,12 +71,8 @@ class Linter
7171 * @return boolean : true if the string is a valid css string, false else
7272 * @throws \InvalidArgumentException
7373 */
74- public function lintString ($ sString )
74+ public function lintString (string $ sString ): bool
7575 {
76- if (!is_string ($ sString )) {
77- throw new \InvalidArgumentException ('Argument "$sString" expects a string, " ' . (is_object ($ sString ) ? get_class ($ sString ) : gettype ($ sString )) . '" given ' );
78- }
79-
8076 $ this ->initLint ();
8177 $ iIterator = 0 ;
8278 while (isset ($ sString [$ iIterator ])) {
@@ -100,12 +96,8 @@ public function lintString($sString)
10096 * @throws \InvalidArgumentException
10197 * @throws \RuntimeException
10298 */
103- public function lintFile ($ sFilePath )
99+ public function lintFile (string $ sFilePath ): bool
104100 {
105- if (!is_string ($ sFilePath )) {
106- throw new \InvalidArgumentException ('Argument "$sFilePath" expects a string, " ' . (is_object ($ sFilePath ) ? get_class ($ sFilePath ) : gettype ($ sFilePath )) . '" given ' );
107- }
108-
109101 if (!file_exists ($ sFilePath )) {
110102 throw new \InvalidArgumentException ('Argument "$sFilePath" " ' . $ sFilePath . '" is not an existing file path ' );
111103 }
@@ -161,7 +153,7 @@ protected function initLint()
161153 * @param string $sChar
162154 * @return boolean : true if the process should continue, else false
163155 */
164- protected function lintChar ($ sChar )
156+ protected function lintChar (string $ sChar ): ? bool
165157 {
166158 $ this ->incrementCharNumber ();
167159 if ($ this ->isEndOfLine ($ sChar )) {
@@ -212,7 +204,7 @@ protected function lintChar($sChar)
212204 * @param string $sChar
213205 * @return boolean|null : true if the process should continue, else false, null if this char is not about comment
214206 */
215- protected function lintCommentChar ($ sChar )
207+ protected function lintCommentChar (string $ sChar ): ? bool
216208 {
217209 // Manage comment context
218210 if ($ this ->isComment ()) {
@@ -231,14 +223,16 @@ protected function lintCommentChar($sChar)
231223 $ this ->setComment (true );
232224 return true ;
233225 }
226+
227+ return null ;
234228 }
235229
236230 /**
237231 * Performs lint for a given char, check selector part
238232 * @param string $sChar
239233 * @return boolean|null : true if the process should continue, else false, null if this char is not about selector
240234 */
241- protected function lintSelectorChar ($ sChar )
235+ protected function lintSelectorChar (string $ sChar ): ? bool
242236 {
243237 // Selector must start by #.a-zA-Z
244238 if ($ this ->assertContext (null )) {
@@ -250,7 +244,7 @@ protected function lintSelectorChar($sChar)
250244 $ this ->addContextContent ($ sChar );
251245 return true ;
252246 }
253- return ;
247+ return null ;
254248 }
255249 // Selector must contains
256250 if ($ this ->assertContext (self ::CONTEXT_SELECTOR )) {
@@ -321,17 +315,19 @@ protected function lintSelectorChar($sChar)
321315 $ this ->addError ('Unexpected selector token " ' . $ sChar . '" ' );
322316 return true ;
323317 }
318+
319+ return null ;
324320 }
325321
326322 /**
327323 * Performs lint for a given char, check selector content part
328324 * @param string $sChar
329325 * @return boolean|null : true if the process should continue, else false, null if this char is not about selector content
330326 */
331- protected function lintSelectorContentChar ($ sChar )
327+ protected function lintSelectorContentChar (string $ sChar ): ? bool
332328 {
333329 if (!$ this ->assertContext (self ::CONTEXT_SELECTOR_CONTENT )) {
334- return ;
330+ return null ;
335331 }
336332 if ($ sChar === ' ' ) {
337333 return true ;
@@ -350,17 +346,19 @@ protected function lintSelectorContentChar($sChar)
350346 $ this ->addContextContent ($ sChar );
351347 return true ;
352348 }
349+
350+ return null ;
353351 }
354352
355353 /**
356354 * Performs lint for a given char, check property name part
357355 * @param string $sChar
358356 * @return boolean|null : true if the process should continue, else false, null if this char is not about property name
359357 */
360- protected function lintPropertyNameChar ($ sChar )
358+ protected function lintPropertyNameChar (string $ sChar ): ? bool
361359 {
362360 if (!$ this ->assertContext (self ::CONTEXT_PROPERTY_NAME )) {
363- return ;
361+ return null ;
364362 }
365363
366364 if ($ sChar === ': ' ) {
@@ -391,10 +389,10 @@ protected function lintPropertyNameChar($sChar)
391389 * @param string $sChar
392390 * @return boolean|null : true if the process should continue, else false, null if this char is not about property content
393391 */
394- protected function lintPropertyContentChar ($ sChar )
392+ protected function lintPropertyContentChar (string $ sChar ): ? bool
395393 {
396394 if (!$ this ->assertContext (self ::CONTEXT_PROPERTY_CONTENT )) {
397- return ;
395+ return null ;
398396 }
399397
400398 $ this ->addContextContent ($ sChar );
@@ -421,21 +419,23 @@ protected function lintPropertyContentChar($sChar)
421419 * @param string $sChar
422420 * @return boolean|null : true if the process should continue, else false, null if this char is not about nested selector
423421 */
424- protected function lintNestedSelectorChar ($ sChar )
422+ protected function lintNestedSelectorChar (string $ sChar ): ? bool
425423 {
426424 // End of nested selector
427425 if ($ this ->isNestedSelector () && $ this ->assertContext (null ) && $ sChar === '} ' ) {
428426 $ this ->setNestedSelector (false );
429427 return true ;
430428 }
429+
430+ return null ;
431431 }
432432
433433 /**
434434 * Check if a given char is an end of line token
435435 * @param string $sChar
436436 * @return boolean : true if the char is an end of line token, else false
437437 */
438- protected function isEndOfLine ($ sChar )
438+ protected function isEndOfLine (string $ sChar ): bool
439439 {
440440 return $ sChar === "\r" || $ sChar === "\n" ;
441441 }
@@ -444,7 +444,7 @@ protected function isEndOfLine($sChar)
444444 * Return the current char number
445445 * @return int
446446 */
447- protected function getCharNumber ()
447+ protected function getCharNumber (): int
448448 {
449449 return $ this ->charNumber ;
450450 }
@@ -454,7 +454,7 @@ protected function getCharNumber()
454454 * @param string $sChar
455455 * @return boolean
456456 */
457- protected function assertPreviousChar ($ sChar )
457+ protected function assertPreviousChar (string $ sChar ): bool
458458 {
459459 return $ this ->previousChar === $ sChar ;
460460 }
@@ -463,7 +463,7 @@ protected function assertPreviousChar($sChar)
463463 * Reset previous char property
464464 * @return \CssLint\Linter
465465 */
466- protected function resetPreviousChar ()
466+ protected function resetPreviousChar (): Linter
467467 {
468468 $ this ->previousChar = null ;
469469 return $ this ;
@@ -474,7 +474,7 @@ protected function resetPreviousChar()
474474 * @param string $sChar
475475 * @return \CssLint\Linter
476476 */
477- protected function setPreviousChar ($ sChar )
477+ protected function setPreviousChar (string $ sChar ): Linter
478478 {
479479 $ this ->previousChar = $ sChar ;
480480 return $ this ;
@@ -484,7 +484,7 @@ protected function setPreviousChar($sChar)
484484 * Return the current line number
485485 * @return int
486486 */
487- protected function getLineNumber ()
487+ protected function getLineNumber (): int
488488 {
489489 return $ this ->lineNumber ;
490490 }
@@ -493,7 +493,7 @@ protected function getLineNumber()
493493 * Add 1 to the current line number
494494 * @return \CssLint\Linter
495495 */
496- protected function incrementLineNumber ()
496+ protected function incrementLineNumber (): Linter
497497 {
498498 $ this ->lineNumber ++;
499499 return $ this ;
@@ -503,7 +503,7 @@ protected function incrementLineNumber()
503503 * Reset current line number property
504504 * @return \CssLint\Linter
505505 */
506- protected function resetLineNumber ()
506+ protected function resetLineNumber (): Linter
507507 {
508508 $ this ->lineNumber = 0 ;
509509 return $ this ;
@@ -513,7 +513,7 @@ protected function resetLineNumber()
513513 * Reset current char number property
514514 * @return \CssLint\Linter
515515 */
516- protected function resetCharNumber ()
516+ protected function resetCharNumber (): Linter
517517 {
518518 $ this ->charNumber = 0 ;
519519 return $ this ;
@@ -523,7 +523,7 @@ protected function resetCharNumber()
523523 * Add 1 to the current char number
524524 * @return \CssLint\Linter
525525 */
526- protected function incrementCharNumber ()
526+ protected function incrementCharNumber (): Linter
527527 {
528528 $ this ->charNumber ++;
529529 return $ this ;
@@ -534,7 +534,7 @@ protected function incrementCharNumber()
534534 * @param string|array $sContext
535535 * @return boolean
536536 */
537- protected function assertContext ($ sContext )
537+ protected function assertContext ($ sContext ): bool
538538 {
539539 if (is_array ($ sContext )) {
540540 foreach ($ sContext as $ sTmpContext ) {
@@ -551,7 +551,7 @@ protected function assertContext($sContext)
551551 * Reset context property
552552 * @return \CssLint\Linter
553553 */
554- protected function resetContext ()
554+ protected function resetContext (): Linter
555555 {
556556 return $ this ->setContext (null );
557557 }
@@ -561,7 +561,7 @@ protected function resetContext()
561561 * @param string $sContext
562562 * @return \CssLint\Linter
563563 */
564- protected function setContext ($ sContext )
564+ protected function setContext ($ sContext ): Linter
565565 {
566566 $ this ->context = $ sContext ;
567567 return $ this ->resetContextContent ();
@@ -571,7 +571,7 @@ protected function setContext($sContext)
571571 * Return context content
572572 * @return string
573573 */
574- protected function getContextContent ()
574+ protected function getContextContent (): string
575575 {
576576 return $ this ->contextContent ;
577577 }
@@ -580,7 +580,7 @@ protected function getContextContent()
580580 * Reset context content property
581581 * @return \CssLint\Linter
582582 */
583- protected function resetContextContent ()
583+ protected function resetContextContent (): Linter
584584 {
585585 $ this ->contextContent = '' ;
586586 return $ this ;
@@ -591,7 +591,7 @@ protected function resetContextContent()
591591 * @param string $sContextContent
592592 * @return \CssLint\Linter
593593 */
594- protected function addContextContent ($ sContextContent )
594+ protected function addContextContent ($ sContextContent ): Linter
595595 {
596596 $ this ->contextContent .= $ sContextContent ;
597597 return $ this ;
@@ -602,7 +602,7 @@ protected function addContextContent($sContextContent)
602602 * @param string $sError
603603 * @return \CssLint\Linter
604604 */
605- protected function addError ($ sError )
605+ protected function addError ($ sError ): Linter
606606 {
607607 $ this ->errors [] = $ sError . ' (line: ' . $ this ->getLineNumber () . ', char: ' . $ this ->getCharNumber () . ') ' ;
608608 return $ this ;
@@ -612,7 +612,7 @@ protected function addError($sError)
612612 * Return the errors occured during the lint process
613613 * @return array
614614 */
615- public function getErrors ()
615+ public function getErrors (): ? array
616616 {
617617 return $ this ->errors ;
618618 }
@@ -621,7 +621,7 @@ public function getErrors()
621621 * Reset the errors property
622622 * @return \CssLint\Linter
623623 */
624- protected function resetErrors ()
624+ protected function resetErrors (): Linter
625625 {
626626 $ this ->errors = null ;
627627 return $ this ;
@@ -631,7 +631,7 @@ protected function resetErrors()
631631 * Tells if the linter is parsing a nested selector
632632 * @return boolean
633633 */
634- protected function isNestedSelector ()
634+ protected function isNestedSelector (): bool
635635 {
636636 return $ this ->nestedSelector ;
637637 }
@@ -640,7 +640,7 @@ protected function isNestedSelector()
640640 * Set the nested selector flag
641641 * @param boolean $bNestedSelector
642642 */
643- protected function setNestedSelector ($ bNestedSelector )
643+ protected function setNestedSelector (bool $ bNestedSelector ): void
644644 {
645645 $ this ->nestedSelector = $ bNestedSelector ;
646646 }
@@ -649,7 +649,7 @@ protected function setNestedSelector($bNestedSelector)
649649 * Tells if the linter is parsing a comment
650650 * @return boolean
651651 */
652- protected function isComment ()
652+ protected function isComment (): bool
653653 {
654654 return $ this ->comment ;
655655 }
@@ -658,7 +658,7 @@ protected function isComment()
658658 * Set the comment flag
659659 * @param boolean $bComment
660660 */
661- protected function setComment ($ bComment )
661+ protected function setComment (bool $ bComment ): void
662662 {
663663 $ this ->comment = $ bComment ;
664664 }
@@ -667,7 +667,7 @@ protected function setComment($bComment)
667667 * Return an instance of the "\CssLint\Properties" helper, initialize a new one if not define already
668668 * @return \CssLint\Properties
669669 */
670- public function getCssLintProperties ()
670+ public function getCssLintProperties (): Properties
671671 {
672672 if (!$ this ->cssLintProperties ) {
673673 $ this ->cssLintProperties = new \CssLint \Properties ();
0 commit comments