Skip to content

Commit

Permalink
Property type hints and psalm checks
Browse files Browse the repository at this point in the history
* Moved js_nonce and css_nonce to AbstractRenderer
  • Loading branch information
jnvsor committed Aug 16, 2024
1 parent 1ac18b0 commit cbfde1f
Show file tree
Hide file tree
Showing 60 changed files with 328 additions and 416 deletions.
4 changes: 0 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
<file name="init_helpers.php" />
<file name="init_phar.php" />
</projectFiles>

<issueHandlers>
<MissingPropertyType errorLevel="info" />
</issueHandlers>
</psalm>
10 changes: 5 additions & 5 deletions src/CallFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class CallFinder
{
private static $ignore = [
private static array $ignore = [
T_CLOSE_TAG => true,
T_COMMENT => true,
T_DOC_COMMENT => true,
Expand All @@ -49,7 +49,7 @@ class CallFinder
* - Wrap the access path in parentheses if there
* are any of these in the final short parameter.
*/
private static $operator = [
private static array $operator = [
T_AND_EQUAL => true,
T_BOOLEAN_AND => true,
T_BOOLEAN_OR => true,
Expand Down Expand Up @@ -116,7 +116,7 @@ class CallFinder
'~' => true,
];

private static $strip = [
private static array $strip = [
'(' => true,
')' => true,
'[' => true,
Expand All @@ -128,12 +128,12 @@ class CallFinder
T_NS_SEPARATOR => true,
];

private static $classcalls = [
private static array $classcalls = [
T_DOUBLE_COLON => true,
T_OBJECT_OPERATOR => true,
];

private static $namespace = [
private static array $namespace = [
T_STRING => true,
];

Expand Down
34 changes: 19 additions & 15 deletions src/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

/**
* @psalm-consistent-constructor
*
* @psalm-type KintMode = string|bool
*/
class Kint implements FacadeInterface
{
Expand All @@ -51,27 +53,29 @@ class Kint implements FacadeInterface
* false: Disabled
* true: Enabled, default mode selection
* other: Manual mode selection
*
* @psalm-var KintMode
*/
public static $enabled_mode = true;

/**
* Default mode.
*
* @var string
* @psalm-var KintMode
*/
public static $mode_default = self::MODE_RICH;

/**
* Default mode in CLI with cli_detection on.
*
* @var string
* @psalm-var KintMode
*/
public static $mode_default_cli = self::MODE_CLI;

/**
* @var bool Return output instead of echoing
*/
public static $return;
public static bool $return = false;

/**
* @var string format of the link to the source file in trace entries.
Expand All @@ -82,12 +86,12 @@ class Kint implements FacadeInterface
*
* Kint::$file_link_format = 'http://localhost:8091/?message=%f:%l';
*/
public static $file_link_format = '';
public static string $file_link_format = '';

/**
* @var bool whether to display where kint was called from
*/
public static $display_called_from = true;
public static bool $display_called_from = true;

/**
* @var array base directories of your application that will be displayed instead of the full path.
Expand All @@ -108,29 +112,29 @@ class Kint implements FacadeInterface
*
* Defaults to [$_SERVER['DOCUMENT_ROOT'] => '<ROOT>']
*/
public static $app_root_dirs = [];
public static array $app_root_dirs = [];

/**
* @var int depth limit for array/object traversal. 0 for no limit
*/
public static $depth_limit = 7;
public static int $depth_limit = 7;

/**
* @var bool expand all trees by default for rich view
*/
public static $expanded = false;
public static bool $expanded = false;

/**
* @var bool enable detection when Kint is command line.
*
* Formats output with whitespace only; does not HTML-escape it
*/
public static $cli_detection = true;
public static bool $cli_detection = true;

/**
* @var array Kint aliases. Add debug functions in Kint wrappers here to fix modifiers and backtraces
*/
public static $aliases = [
public static array $aliases = [
['Kint\\Kint', 'dump'],
['Kint\\Kint', 'trace'],
['Kint\\Kint', 'dumpAll'],
Expand All @@ -139,7 +143,7 @@ class Kint implements FacadeInterface
/**
* @psalm-var class-string[] Array of modes to renderer class names
*/
public static $renderers = [
public static array $renderers = [
self::MODE_RICH => Renderer\RichRenderer::class,
self::MODE_PLAIN => Renderer\PlainRenderer::class,
self::MODE_TEXT => TextRenderer::class,
Expand All @@ -149,7 +153,7 @@ class Kint implements FacadeInterface
/**
* @psalm-var class-string[]
*/
public static $plugins = [
public static array $plugins = [
\Kint\Parser\ArrayLimitPlugin::class,
\Kint\Parser\ArrayObjectPlugin::class,
\Kint\Parser\Base64Plugin::class,
Expand All @@ -175,10 +179,10 @@ class Kint implements FacadeInterface
\Kint\Parser\XmlPlugin::class,
];

protected static $plugin_pool = [];
protected static array $plugin_pool = [];

protected $parser;
protected $renderer;
protected Parser $parser;
protected RendererInterface $renderer;

public function __construct(Parser $p, RendererInterface $r)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
abstract class AbstractPlugin implements ConstructablePluginInterface
{
protected $parser;
protected Parser $parser;

Check failure on line 35 in src/Parser/AbstractPlugin.php

View workflow job for this annotation

GitHub Actions / Static analysis check

PropertyNotSetInConstructor

src/Parser/AbstractPlugin.php:35:22: PropertyNotSetInConstructor: Property Kint\Parser\AbstractPlugin::$parser is not defined in constructor of Kint\Parser\AbstractPlugin or in any methods called in the constructor (see https://psalm.dev/074)

public function __construct()
{
Expand Down
12 changes: 3 additions & 9 deletions src/Parser/ArrayLimitPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,18 @@ class ArrayLimitPlugin extends AbstractPlugin
{
/**
* Maximum size of arrays before limiting.
*
* @var int
*/
public static $trigger = 1000;
public static int $trigger = 1000;

/**
* Maximum amount of items to show in a limited array.
*
* @var int
*/
public static $limit = 50;
public static int $limit = 50;

/**
* Don't limit arrays with string keys.
*
* @var bool
*/
public static $numeric_only = true;
public static bool $numeric_only = true;

public function getTypes(): array
{
Expand Down
8 changes: 2 additions & 6 deletions src/Parser/Base64Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ class Base64Plugin extends AbstractPlugin
{
/**
* The minimum length before a string will be considered for base64 decoding.
*
* @var int
*/
public static $min_length_hard = 16;
public static int $min_length_hard = 16;

/**
* The minimum length before the base64 decoding will take precedence.
*
* @var int
*/
public static $min_length_soft = 50;
public static int $min_length_soft = 50;

public function getTypes(): array
{
Expand Down
8 changes: 4 additions & 4 deletions src/Parser/BlacklistPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ class BlacklistPlugin extends AbstractPlugin
/**
* List of classes and interfaces to blacklist.
*
* @var array
* @var class-string[]
*/
public static $blacklist = [];
public static array $blacklist = [];

/**
* List of classes and interfaces to blacklist except when dumped directly.
*
* @var array
* @var class-string[]
*/
public static $shallow_blacklist = [ContainerInterface::class];
public static array $shallow_blacklist = [ContainerInterface::class];

public function getTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ClassMethodsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class ClassMethodsPlugin extends AbstractPlugin
{
private static $cache = [];
private static array $cache = [];

public function getTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ClassStaticsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

class ClassStaticsPlugin extends AbstractPlugin
{
private static $cache = [];
private static array $cache = [];

public function getTypes(): array
{
Expand Down
8 changes: 3 additions & 5 deletions src/Parser/DOMDocumentPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class DOMDocumentPlugin extends AbstractPlugin
*
* In retrospect - this is probably why print_r does the same
*
* @var array
* @psalm-var array<string, class-string>
*/
public static $blacklist = [
public static array $blacklist = [
'parentNode' => 'DOMNode',
'firstChild' => 'DOMNode',
'lastChild' => 'DOMNode',
Expand All @@ -78,10 +78,8 @@ class DOMDocumentPlugin extends AbstractPlugin

/**
* Show all properties and methods.
*
* @var bool
*/
public static $verbose = false;
public static bool $verbose = false;

public function getTypes(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Parser/DateTimePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace Kint\Parser;

use DateTime;
use DateTimeInterface;
use Kint\Zval\DateTimeValue;
use Kint\Zval\Value;

Expand All @@ -45,7 +45,7 @@ public function getTriggers(): int

public function parse(&$var, Value &$o, int $trigger): void
{
if (!$var instanceof DateTime) {
if (!$var instanceof DateTimeInterface) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/EnumPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class EnumPlugin extends AbstractPlugin
{
private static $cache = [];
private static array $cache = [];

public function getTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/FsPathPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class FsPathPlugin extends AbstractPlugin
{
public static $blacklist = ['/', '.'];
public static array $blacklist = ['/', '.'];

public function getTypes(): array
{
Expand Down
4 changes: 1 addition & 3 deletions src/Parser/IteratorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ class IteratorPlugin extends AbstractPlugin
* Certain classes (Such as PDOStatement) irreversibly lose information
* when traversed. Others are just huge. Either way, put them in here
* and you won't have to worry about them being parsed.
*
* @var array
*/
public static $blacklist = [
public static array $blacklist = [
'DOMNamedNodeMap',
'DOMNodeList',
'mysqli_result',
Expand Down
8 changes: 4 additions & 4 deletions src/Parser/MicrotimePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

class MicrotimePlugin extends AbstractPlugin
{
private static $last = null;
private static $start = null;
private static $times = 0;
private static $group = 0;
private static ?array $last = null;
private static ?float $start = null;
private static int $times = 0;
private static int $group = 0;

public function getTypes(): array
{
Expand Down
Loading

0 comments on commit cbfde1f

Please sign in to comment.