Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions build/build-preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,28 @@ final class PreloadBuilder

declare(strict_types=1);

use PhpParser\Node;
use PHPStan\Testing\PHPStanTestCase;

if (defined('__PHPSTAN_RUNNING__')) {
return;
}

// edge case during Rector tests case, happens when
// 1. phpstan autoload test case is triggered first,
// 2. all php-parser classes are loaded,
if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) {
return;
}

function isPHPStanTestPreloaded(): bool
{
if (! class_exists(PHPStanTestCase::class, false)) {
return false;
}

return interface_exists(Node::class, false);
}
CODE_SAMPLE;

/**
Expand Down
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
'*/Fixture/*',
'*/Expected/*',

// avoid re-running on build
__DIR__ . '/preload.php',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also preload-split-package.php:

Suggested change
__DIR__ . '/preload.php',
__DIR__ . '/preload.php',
__DIR__ . '/preload-split-package.php',


PhpdocTypesFixer::class => [
// double to Double false positive
__DIR__ . '/rules/Php74/Rector/Double/RealToFloatTypeCastRector.php',
Expand Down
19 changes: 18 additions & 1 deletion preload-split-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

declare(strict_types=1);

use PhpParser\Node;
use PHPStan\Testing\PHPStanTestCase;
Comment on lines +5 to +6
Copy link
Member

@samsonasik samsonasik Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may cause repetitive apply cs after rebuild weekly, if cs is required, the cs fix position needs to be after generate preload on workflow build so it always have same result:

-
name: 'Apply Coding Standard'
run: "composer fix-cs"
branch: 'automated-apply-coding-standards'
-
name: 'Re-Generate preload.php'
run: "composer preload"
branch: 'automated-regenerated-preload'

or on build/build-preload.php script, or add use statement early there.


if (defined('__PHPSTAN_RUNNING__')) {
return;
}

require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node.php';
// edge case during Rector tests case, happens when
// 1. phpstan autoload test case is triggered first,
// 2. all php-parser classes are loaded,
if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) {
return;
}

function isPHPStanTestPreloaded(): bool
{
if (! class_exists(PHPStanTestCase::class, false)) {
return false;
}

return interface_exists(Node::class, false);
}require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line is needed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
Expand Down
19 changes: 18 additions & 1 deletion preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

declare(strict_types=1);

use PhpParser\Node;
use PHPStan\Testing\PHPStanTestCase;

if (defined('__PHPSTAN_RUNNING__')) {
return;
}

require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
// edge case during Rector tests case, happens when
// 1. phpstan autoload test case is triggered first,
// 2. all php-parser classes are loaded,
if (defined('PHPUNIT_COMPOSER_INSTALL') && isPHPStanTestPreloaded()) {
return;
}

function isPHPStanTestPreloaded(): bool
{
if (! class_exists(PHPStanTestCase::class, false)) {
return false;
}

return interface_exists(Node::class, false);
}require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
Expand Down