Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7799c7e
Started Reorganizing folders
rcalicdan Sep 5, 2026
87f77ba
Progress on Reorganizing files and folders
rcalicdan Sep 5, 2026
1b9e614
Organizing folders
rcalicdan Sep 5, 2026
13fadce
Organizing folders
rcalicdan Sep 5, 2026
cce4a21
fix code styling
rcalicdan Sep 5, 2026
9ebd31a
fix phpstan errors
rcalicdan Sep 5, 2026
ed875c4
Refactor internal directory patterns and update path normalization logic
rcalicdan Sep 5, 2026
0f85bf4
fix failing test
rcalicdan Sep 5, 2026
b18b344
Fix class trait use documentation initialization in SpecialTypeResolver
rcalicdan Sep 5, 2026
b3ad6b5
Reorganize Test files
rcalicdan Sep 5, 2026
4973b02
Add unit tests for CommandRunner functionality
rcalicdan Sep 5, 2026
247baad
Enhance StreamWrapper functionality and add tests for string literal …
rcalicdan Sep 5, 2026
880bc1f
Major performance optimization
rcalicdan Sep 5, 2026
5caa02f
Enhance DocblockNormalizer and SpecialTypeResolver with additional ch…
rcalicdan Sep 5, 2026
2cb2830
Rename ContractParser to DocblockParser
rcalicdan Sep 5, 2026
13e0073
bump php doc parser version
rcalicdan Sep 5, 2026
716fad5
Update phpstan/phpdoc-parser version to ^2.3.5 in composer.json
rcalicdan Sep 5, 2026
7285d2b
trace failing 8.2 ci test
rcalicdan Sep 5, 2026
744bd28
Remove redundant --verbose flag from Pest runtime type checking command
rcalicdan Sep 5, 2026
651eb35
Refactor Node name usage to use FullyQualified for consistency
rcalicdan Sep 5, 2026
a9b0f5f
Enhance debugging output in ClassConstKeyShapeTest and StreamWrapper …
rcalicdan Sep 5, 2026
da5274b
Refactor ParamChecker to return validation error immediately instead …
rcalicdan Sep 5, 2026
cb6e8d3
Remove manual debug checks from TypeError test in ClassConstKeyShapeTest
rcalicdan Sep 5, 2026
fa717b7
Fix formatting and remove redundant debug statements across multiple …
rcalicdan Sep 5, 2026
c62b88c
Update CI workflow to run full test suite with coverage and adjust PH…
rcalicdan Sep 5, 2026
811f14b
Update phpdoc-parser version and fix namespace usage in NodeBuilder
rcalicdan Sep 5, 2026
86a0f93
Update nikic/php-parser version to ^5.8 in composer.json
rcalicdan Sep 5, 2026
6dc3cd7
Reorganize CI workflow steps and update nikic/php-parser version to ^5.3
rcalicdan Sep 5, 2026
94002ce
Enhance CI workflow to run full test suite with coverage and streamli…
rcalicdan Sep 5, 2026
3e4198a
fix code styling
rcalicdan Sep 5, 2026
b4b478a
Update phpstan/phpdoc-parser version to ^2.3 in composer.json
rcalicdan Sep 5, 2026
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
2 changes: 1 addition & 1 deletion bin/typephp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ foreach ($autoloadFiles as $file) {
}
}

use TypePHP\Command\CommandRunner;
use TypePHP\Internal\Cli\CommandRunner;

$exitCode = CommandRunner::run(array_slice($argv, 1));
exit($exitCode);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"require": {
"php": "^8.1",
"phpstan/phpdoc-parser": "^2.0",
"phpstan/phpdoc-parser": "^2.3",
"nikic/php-parser": "^5.3"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

declare(strict_types=1);

namespace TypePHP\Internal;
namespace TypePHP\Internal\Ast;

use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use TypePHP\Contract\DocblockExtractor;
use TypePHP\Internal\Visitor\FunctionContractInjector;
use TypePHP\Internal\Visitor\NodeBuilder;
use TypePHP\Internal\Visitor\PropertyHookInjector;
use TypePHP\Internal\Visitor\ScopeManager;
use TypePHP\Internal\Docblock\DocblockExtractor;

/**
* @internal AST Node Visitor that injects contract checks, scope tracking, property hook validation, and parameter/return wrappers into functions and methods.
Expand All @@ -31,7 +27,8 @@ public function __construct()
*/
public function enterNode(Node $node): ?array
{
if ($node instanceof Node\Stmt\Function_
if (
$node instanceof Node\Stmt\Function_
|| $node instanceof Node\Stmt\ClassMethod
|| $node instanceof Node\Expr\Closure
|| $node instanceof Node\Expr\ArrowFunction
Expand Down Expand Up @@ -165,12 +162,12 @@ public function leaveNode(Node $node): Node|null
$node->setAttribute('typephp_wrapped', value: true);

return new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::cloneInstance'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::cloneInstance'),
[
new Node\Arg(
new Node\Expr\Clone_(
new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::prepareClone'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::prepareClone'),
[new Node\Arg($node->expr)]
)
)
Expand All @@ -180,7 +177,8 @@ public function leaveNode(Node $node): Node|null
);
}

if ($node instanceof Node\Stmt\Function_
if (
$node instanceof Node\Stmt\Function_
|| $node instanceof Node\Stmt\ClassMethod
|| $node instanceof Node\Expr\Closure
|| $node instanceof Node\Expr\ArrowFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TypePHP\Internal\Visitor;
namespace TypePHP\Internal\Ast;

use PhpParser\Node;
use PhpParser\NodeTraverser;
Expand Down Expand Up @@ -204,7 +204,7 @@ private static function buildSetupScopeStmt(array $params, Node\Expr $thisArg):
);

$checkCall = new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::setupScope'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::setupScope'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg($argsExpr),
Expand All @@ -217,7 +217,7 @@ private static function buildSetupScopeStmt(array $params, Node\Expr $thisArg):
$ifStmt = new Node\Stmt\If_(
new Node\Expr\Instanceof_(
new Node\Expr\Assign(new Node\Expr\Variable('__typephpErr'), $checkCall),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
['stmts' => [$throwStmt]]
);
Expand All @@ -242,7 +242,7 @@ private static function buildCallableParamWrappers(array $params, string $docTex
new Node\Expr\Assign(
new Node\Expr\Variable($paramName),
new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::wrapCallable'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::wrapCallable'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg(new Node\Scalar\String_($paramName)),
Expand Down Expand Up @@ -275,7 +275,7 @@ private static function buildIterableParamWrappers(array $params, string $docTex
new Node\Expr\Assign(
new Node\Expr\Variable($paramName),
new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::wrapIterable'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::wrapIterable'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg(new Node\Scalar\String_($paramName)),
Expand Down Expand Up @@ -373,12 +373,12 @@ public static function buildTypeErrorThrowStmt(Node\Expr $errorVar): Node\Stmt\E
return new Node\Stmt\Expression(
new Node\Expr\Throw_(
new Node\Expr\StaticCall(
new Node\Name('\TypePHP\Internal\ErrorFactory'),
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorFactory'),
'prepareException',
[
new Node\Arg(
new Node\Expr\New_(
new Node\Name('\TypePHP\Exception\TypeError'),
new Node\Name\FullyQualified('TypePHP\Exception\TypeError'),
[
new Node\Arg(
new Node\Expr\MethodCall($errorVar, 'getMessage')
Expand All @@ -399,7 +399,7 @@ public static function buildReturnCheckCall(Node\Expr $exprToWrap, Node\Expr $th
: new Node\Expr\Array_();

return new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::checkReturn'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::checkReturn'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg($exprToWrap),
Expand All @@ -417,7 +417,7 @@ public static function buildVoidReturnGuard(Node\Expr\FuncCall $checkCall): arra
$ifStmt = new Node\Stmt\If_(
new Node\Expr\Instanceof_(
new Node\Expr\Assign(new Node\Expr\Variable('__typephpRet'), $checkCall),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
['stmts' => [self::buildTypeErrorThrowStmt(new Node\Expr\Variable('__typephpRet'))]]
);
Expand All @@ -434,16 +434,16 @@ public static function buildTernaryReturnExpr(Node\Expr\FuncCall $checkCall): No
return new Node\Expr\Ternary(
new Node\Expr\Instanceof_(
new Node\Expr\Assign(new Node\Expr\Variable('__typephpRet'), $checkCall),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
new Node\Expr\Throw_(
new Node\Expr\StaticCall(
new Node\Name('\TypePHP\Internal\ErrorFactory'),
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorFactory'),
'prepareException',
[
new Node\Arg(
new Node\Expr\New_(
new Node\Name('\TypePHP\Exception\TypeError'),
new Node\Name\FullyQualified('TypePHP\Exception\TypeError'),
[
new Node\Arg(
new Node\Expr\MethodCall(new Node\Expr\Variable('__typephpRet'), 'getMessage')
Expand All @@ -461,7 +461,7 @@ public static function buildTernaryReturnExpr(Node\Expr\FuncCall $checkCall): No
public static function buildWrappedYieldNode(Node\Expr\Yield_ $n, Node\Expr $thisArg): Node\Expr\Ternary
{
$checkYieldCall = new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::checkYield'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::checkYield'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg($n->key ?? new Node\Expr\ConstFetch(new Node\Name('null'))),
Expand All @@ -473,16 +473,16 @@ public static function buildWrappedYieldNode(Node\Expr\Yield_ $n, Node\Expr $thi
$n->value = new Node\Expr\Ternary(
new Node\Expr\Instanceof_(
new Node\Expr\Assign(new Node\Expr\Variable('__typephpYld'), $checkYieldCall),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
new Node\Expr\Throw_(
new Node\Expr\StaticCall(
new Node\Name('\TypePHP\Internal\ErrorFactory'),
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorFactory'),
'prepareException',
[
new Node\Arg(
new Node\Expr\New_(
new Node\Name('\TypePHP\Exception\TypeError'),
new Node\Name\FullyQualified('TypePHP\Exception\TypeError'),
[
new Node\Arg(
new Node\Expr\MethodCall(new Node\Expr\Variable('__typephpYld'), 'getMessage')
Expand All @@ -498,7 +498,7 @@ public static function buildWrappedYieldNode(Node\Expr\Yield_ $n, Node\Expr $thi
);

$checkSendCall = new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::checkSend'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::checkSend'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg($n),
Expand All @@ -509,16 +509,16 @@ public static function buildWrappedYieldNode(Node\Expr\Yield_ $n, Node\Expr $thi
return new Node\Expr\Ternary(
new Node\Expr\Instanceof_(
new Node\Expr\Assign(new Node\Expr\Variable('__typephpSnd'), $checkSendCall),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
new Node\Expr\Throw_(
new Node\Expr\StaticCall(
new Node\Name('\TypePHP\Internal\ErrorFactory'),
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorFactory'),
'prepareException',
[
new Node\Arg(
new Node\Expr\New_(
new Node\Name('\TypePHP\Exception\TypeError'),
new Node\Name\FullyQualified('TypePHP\Exception\TypeError'),
[
new Node\Arg(
new Node\Expr\MethodCall(new Node\Expr\Variable('__typephpSnd'), 'getMessage')
Expand Down Expand Up @@ -570,7 +570,7 @@ public function enterNode(Node $n): int|Node|null
$n->setAttribute('typephp_wrapped', true);

$n->expr = new Node\Expr\FuncCall(
new Node\Name('\TypePHP\Internal\RuntimeTypeChecker::wrapIterable'),
new Node\Name\FullyQualified('TypePHP\Internal\RuntimeTypeChecker::wrapIterable'),
[
new Node\Arg(new Node\Scalar\MagicConst\Method()),
new Node\Arg(new Node\Scalar\String_('return')),
Expand Down Expand Up @@ -649,4 +649,4 @@ public function enterNode(Node $n): int|array|null

return $newStmts;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TypePHP\Internal\Visitor;
namespace TypePHP\Internal\Ast;

use PhpParser\Node;

Expand Down Expand Up @@ -42,7 +42,7 @@ public static function createTernaryThrowExpr(Node\Expr\FuncCall $checkCall, int
$args = [
new Node\Arg(
new Node\Expr\New_(
new Node\Name('\TypePHP\Exception\TypeError'),
new Node\Name\FullyQualified('TypePHP\Exception\TypeError'),
[
new Node\Arg(
new Node\Expr\MethodCall(
Expand All @@ -65,11 +65,11 @@ public static function createTernaryThrowExpr(Node\Expr\FuncCall $checkCall, int
new Node\Expr\Variable('__typephpVal'),
$checkCall
),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
new Node\Expr\Throw_(
new Node\Expr\StaticCall(
new Node\Name('\TypePHP\Internal\ErrorFactory'),
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorFactory'),
'prepareException',
$args
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace TypePHP\Internal\Visitor;
namespace TypePHP\Internal\Ast;

use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use TypePHP\Internal\Config;
use TypePHP\Internal\Util\Config;

/**
* @internal Injects property contract checks into PHP 8.4 get and set property hooks.
Expand Down Expand Up @@ -90,16 +90,16 @@ private static function buildExpressionSetHookTernary(Node\Expr\FuncCall $checkC
return new Node\Expr\Ternary(
new Node\Expr\Instanceof_(
new Node\Expr\Assign(new Node\Expr\Variable('__typephpVal'), $checkCall),
new Node\Name('\TypePHP\Internal\ErrorMessage')
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorMessage')
),
new Node\Expr\Throw_(
new Node\Expr\StaticCall(
new Node\Name('\TypePHP\Internal\ErrorFactory'),
new Node\Name\FullyQualified('TypePHP\Internal\Diagnostic\ErrorFactory'),
'prepareException',
[
new Node\Arg(
new Node\Expr\New_(
new Node\Name('\TypePHP\Exception\TypeError'),
new Node\Name\FullyQualified('TypePHP\Exception\TypeError'),
[
new Node\Arg(
new Node\Expr\MethodCall(new Node\Expr\Variable('__typephpVal'), 'getMessage')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace TypePHP\Internal;
namespace TypePHP\Internal\Ast;

use TypePHP\Resolver\TemplateManager;
use TypePHP\Internal\Generics\TemplateManager;

/**
* @internal ensures proper scope cleanup for variable tracking.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace TypePHP\Internal\Visitor;
namespace TypePHP\Internal\Ast;

use PhpParser\Node;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use TypePHP\Contract\DocblockExtractor;
use TypePHP\Internal\DocblockNormalizer;
use TypePHP\Internal\Docblock\DocblockExtractor;
use TypePHP\Internal\Docblock\DocblockNormalizer;

/**
* @internal Manages lexical scope stack frames and extracts local @var variable annotations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TypePHP\Internal;
namespace TypePHP\Internal\Ast;

use PhpParser\Node;
use PhpParser\PrettyPrinter\Standard;
Expand Down
12 changes: 6 additions & 6 deletions src/Internal/Checker/GeneratorChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use TypePHP\Contract\ContractParser;
use TypePHP\Resolver\SpecialTypeResolver;
use TypePHP\Resolver\TemplateManager;
use TypePHP\Resolver\TemplateSubstitutor;
use TypePHP\Validator\TypeValidatorRegistry;
use TypePHP\Internal\Docblock\DocblockParser;
use TypePHP\Internal\Generics\TemplateManager;
use TypePHP\Internal\Generics\TemplateSubstitutor;
use TypePHP\Internal\Resolver\SpecialTypeResolver;
use TypePHP\Internal\Validator\TypeValidatorRegistry;

/**
* @internal Evaluates generator yield and send (TSend) type validations.
Expand Down Expand Up @@ -86,7 +86,7 @@ public static function checkYield(
*/
private static function resolveGeneratorReturnType(string $function, object|string|null $thisOrClass): ?TypeNode
{
$contract = ContractParser::parse($function);
$contract = DocblockParser::parse($function);
$returnTypeNode = $contract['return'] ?? null;

if ($returnTypeNode === null) {
Expand Down
Loading
Loading