Skip to content

Commit

Permalink
Add psalm typehint for trigger mask
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Aug 26, 2024
1 parent 579ac15 commit 0ef70a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Binary file modified build/kint.phar
Binary file not shown.
6 changes: 5 additions & 1 deletion src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
use ReflectionProperty;
use ReflectionReference;

/**
* @psalm-type ParserTrigger int-mask-of<Parser::TRIGGER_*>
*/
class Parser
{
/**
Expand All @@ -54,7 +57,8 @@ class Parser
* DEPTH_LIMIT: After parsing cancelled by depth limit
* COMPLETE: SUCCESS | RECURSION | DEPTH_LIMIT
*
* While a plugin's getTriggers may return any of these
* While a plugin's getTriggers may return any of these only one should
* be given to the plugin when PluginInterface::parse is called
*/
public const TRIGGER_NONE = 0;
public const TRIGGER_BEGIN = 1;
Expand Down
7 changes: 7 additions & 0 deletions src/Parser/PluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@

use Kint\Zval\Value;

/**
* @psalm-import-type ParserTrigger from Parser
*/
interface PluginInterface
{
public function setParser(Parser $p): void;

public function getTypes(): array;

/**
* @psalm-return ParserTrigger
*/
public function getTriggers(): int;

/**
* @psalm-param mixed &$var
* @psalm-param ParserTrigger $trigger
*/
public function parse(&$var, Value &$o, int $trigger): void;
}
9 changes: 8 additions & 1 deletion src/Parser/ProxyPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@

use Kint\Zval\Value;

/**
* @psalm-import-type ParserTrigger from Parser
*/
class ProxyPlugin implements PluginInterface
{
protected array $types;
/** @psalm-var ParserTrigger */
protected int $triggers;
/** @psalm-var callable */
protected $callback;
private ?Parser $parser = null;

/** @psalm-param callable $callback */
/**
* @psalm-param ParserTrigger $triggers
* @psalm-param callable $callback
*/
public function __construct(array $types, int $triggers, $callback)
{
$this->types = $types;
Expand Down

0 comments on commit 0ef70a3

Please sign in to comment.