Skip to content

Commit

Permalink
Fix issues reported by phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
Sobak committed Jan 16, 2024
1 parent 4a145ef commit 18d39a0
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Language/GreedyLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private function _tokens($source, $offset = 0, $additional = [], $embedded = fal
{
$result = new UnprocessedTokens();

/** @var Language $language */
/** @var Rule $rule */
foreach ($this->_rules($embedded) as $rule) {
foreach ($rule->match($source) as $token) {
$result->add($token, $offset);
Expand Down Expand Up @@ -174,7 +174,7 @@ private function _rules($embedded = false)
*
* @param $embedded
*
* @return Rule|Rule[]
* @return Rule|Rule[]|array<string, array<int, Rule>>
*/
public function getEnds($embedded = false)
{
Expand Down
3 changes: 1 addition & 2 deletions Language/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ function (
$match,
TokenFactoryInterface $factory
) use (
$annotationNameRule,
$allowedInAttributes
$annotationNameRule
) {
yield $factory->create(
Token::NAME,
Expand Down
4 changes: 2 additions & 2 deletions Matcher/RegexMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class RegexMatcher implements MatcherInterface
/**
* RegexMatcher constructor.
*
* @param $regex
* @param array|null $groups
* @param $regex
* @param array $groups
*/
public function __construct($regex, array $groups = [1 => null])
{
Expand Down
4 changes: 2 additions & 2 deletions Matcher/WordMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public function __construct(array $words, array $options = [])

public function merge(array $words)
{
return new static(array_merge($this->words, $words), $this->options);
return new self(array_merge($this->words, $words), $this->options);
}

public function subtract(array $words)
{
return new static(array_diff($this->words, $words), $this->options);
return new self(array_diff($this->words, $words), $this->options);
}

public function getWords()
Expand Down
4 changes: 2 additions & 2 deletions Parser/DelegateTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class DelegateTokenFactory implements TokenFactoryInterface
/**
* DelegateTokenFactory constructor.
*
* @param callable (TokenFactoryInterface $factory, array $params) $function
* @param TokenFactoryInterface|null $factory
* @param callable (TokenFactoryInterface, array $params): Token $function
* @param TokenFactoryInterface|null $factory
*/
public function __construct(callable $function, TokenFactoryInterface $factory = null)
{
Expand Down
2 changes: 1 addition & 1 deletion Parser/OpenRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OpenRule extends Rule
/**
* @param $source
*
* @return Token[]
* @return Token[]|iterable<Token>
*/
public function match($source)
{
Expand Down
8 changes: 4 additions & 4 deletions Parser/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @package Kadet\Highlighter\Parser
*
* @property Language $language
* @property Language|false|null $language
* @property Language $inject
* @property integer $priority
* @property string $type
Expand All @@ -40,7 +40,7 @@
class Rule
{
/**
* @var Validator
* @var Validator|false
*/
public $validator = false;
private $_matcher;
Expand Down Expand Up @@ -106,7 +106,7 @@ public function setMatcher(MatcherInterface $matcher)
/**
* @param $source
*
* @return Token[]|\Iterator
* @return iterable<Token>|\Iterator
*/
public function match($source)
{
Expand All @@ -120,7 +120,7 @@ public function __get($option)

public function __set($option, $value)
{
return $this->_options[$option] = $value;
$this->_options[$option] = $value;
}

public function enable()
Expand Down
10 changes: 10 additions & 0 deletions Parser/Token/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
use Kadet\Highlighter\Parser\Validator\Validator;
use Kadet\Highlighter\Utils\Helper;

/**
* Class Token
*
* @package Kadet\Highlighter\Parser\Token
*
* @mixin Rule
*/
class Token
{
public const NAME = null;
Expand All @@ -37,7 +44,10 @@ class Token
public $pos;
public $name;
public $id;

/** @var Rule */
public $rule;

public $options;

# region >>> cache
Expand Down
2 changes: 1 addition & 1 deletion Utils/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class Console
{
/**
* @var ConsoleHelper
* @var ConsoleHelper|null
*/
private static $_instance;

Expand Down

0 comments on commit 18d39a0

Please sign in to comment.