Skip to content

Commit

Permalink
[Scoper] Remove PHPStanStubLoader: move to dedicated file to define n…
Browse files Browse the repository at this point in the history
…ative classes (#2249)

* [Scoper] Remove PHPStanStubLoader: move to dedicated file to define native classes

* clean up

* load internal early, just in case

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed May 7, 2022
1 parent c2ade05 commit 81ba0c9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if (! interface_exists('UnitEnum')) {
if (PHP_VERSION_ID < 80100 && ! interface_exists('UnitEnum', false)) {
/**
* @since 8.1
*/
Expand All @@ -13,7 +13,7 @@ public static function cases(): array;
}
}

if (! interface_exists('BackedEnum')) {
if (PHP_VERSION_ID < 80100 && ! interface_exists('BackedEnum', false)) {
/**
* @since 8.1
*/
Expand Down
80 changes: 80 additions & 0 deletions build/target-repository/stubs-rector/Internal/NativeClasses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

if (PHP_VERSION_ID < 80000 && ! class_exists('ReflectionUnionType', false)) {
class ReflectionUnionType extends ReflectionType
{
/** @return ReflectionType[] */
public function getTypes()
{
return [];
}
}
}

if (\PHP_VERSION_ID < 80000 && ! class_exists('Attribute', false)) {
#[Attribute(Attribute::TARGET_CLASS)]
class Attribute
{

/** @var int */
public $flags;

/**
* Marks that attribute declaration is allowed only in classes.
*/
const TARGET_CLASS = 1;

/**
* Marks that attribute declaration is allowed only in functions.
*/
const TARGET_FUNCTION = 1 << 1;

/**
* Marks that attribute declaration is allowed only in class methods.
*/
const TARGET_METHOD = 1 << 2;

/**
* Marks that attribute declaration is allowed only in class properties.
*/
const TARGET_PROPERTY = 1 << 3;

/**
* Marks that attribute declaration is allowed only in class constants.
*/
const TARGET_CLASS_CONSTANT = 1 << 4;

/**
* Marks that attribute declaration is allowed only in function or method parameters.
*/
const TARGET_PARAMETER = 1 << 5;

/**
* Marks that attribute declaration is allowed anywhere.
*/
const TARGET_ALL = (1 << 6) - 1;

/**
* Notes that an attribute declaration in the same place is
* allowed multiple times.
*/
const IS_REPEATABLE = 1 << 6;

/**
* @param int $flags A value in the form of a bitmask indicating the places
* where attributes can be defined.
*/
public function __construct($flags = self::TARGET_ALL)
{
$this->flags = $flags;
}

}
}

if (\PHP_VERSION_ID < 80100 && ! class_exists('ReturnTypeWillChange', false)) {
#[Attribute(Attribute::TARGET_METHOD)]
final class ReturnTypeWillChange
{
}
}
9 changes: 5 additions & 4 deletions src/Autoloading/BootstrapFilesIncluder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ final class BootstrapFilesIncluder
* @var string[]
*/
private const STUBS = [
'/../../stubs-rector/PHPUnit/Framework/TestCase.php',
'/../../stubs-rector/Internal/EnumInterfaces.php',
'Internal/EnumInterfaces.php',
'Internal/NativeClasses.php',
'PHPUnit/Framework/TestCase.php',
];

public function __construct(
Expand Down Expand Up @@ -58,8 +59,8 @@ public function includeBootstrapFiles(): void
}

foreach (self::STUBS as $stub) {
if (is_file(__DIR__ . $stub)) {
require_once __DIR__ . $stub;
if (is_file(__DIR__ . '/../../stubs-rector/' . $stub)) {
require_once __DIR__ . '/../../stubs-rector/' . $stub;
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/DependencyInjection/RectorContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Psr\Container\ContainerInterface;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Core\Kernel\RectorKernel;
use Rector\Core\Stubs\PHPStanStubLoader;
use Rector\Core\ValueObject\Bootstrap\BootstrapConfigs;
use Symfony\Component\Console\Style\SymfonyStyle;

Expand Down Expand Up @@ -52,9 +51,6 @@ public function createFromBootstrapConfigs(BootstrapConfigs $bootstrapConfigs):
*/
private function createFromConfigs(array $configFiles): ContainerInterface
{
$phpStanStubLoader = new PHPStanStubLoader();
$phpStanStubLoader->loadStubs();

$rectorKernel = new RectorKernel();
return $rectorKernel->createFromConfigs($configFiles);
}
Expand Down
73 changes: 0 additions & 73 deletions src/Stubs/PHPStanStubLoader.php

This file was deleted.

0 comments on commit 81ba0c9

Please sign in to comment.