Skip to content

Commit

Permalink
[scoper] keep phpstan.phar to avoid conflict in install (#5009)
Browse files Browse the repository at this point in the history
* fix scoping of Symfony autodiscovery namespace

* scoped: add along phpstan run

* wait longer, the old version is used

* keep phpstan.phar
  • Loading branch information
TomasVotruba committed Dec 27, 2020
1 parent 34a2a49 commit 5203352
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_scoped_rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: Build Scoped Rector

on:
push:
branches: master
branches:
- master

jobs:
build_scoped_rector:
Expand Down
9 changes: 0 additions & 9 deletions bin/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

$autoloadIncluder->autoloadProjectAutoloaderFile();
$autoloadIncluder->autoloadFromCommandLine();
$autoloadIncluder->autoloadPhpStanExtracted();

$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller());
$symfonyStyle = $symfonyStyleFactory->create();
Expand Down Expand Up @@ -105,14 +104,6 @@ public function autoloadProjectAutoloaderFile(): void
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../../autoload.php');
}

/**
* This autoloads extracted PHPStan autoload
*/
public function autoloadPhpStanExtracted(): void
{
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/phpstan/phpstan-extracted/vendor/autoload.php');
}

public function autoloadFromCommandLine(): void
{
$cliArgs = $_SERVER['argv'];
Expand Down
11 changes: 0 additions & 11 deletions build-rector-scoped.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ rsync -av * "$NESTED_DIRECTORY" --quiet
note "Running composer update without dev"
composer update --no-dev --no-progress --ansi --working-dir "$NESTED_DIRECTORY"

# Unpacking PHPStan
note "Unpacking PHPStan"
wget https://github.com/box-project/box/releases/download/3.11.0/box.phar -N --no-verbose
php box.phar extract "$NESTED_DIRECTORY/vendor/phpstan/phpstan/phpstan.phar" "$NESTED_DIRECTORY/vendor/phpstan/phpstan-extracted"

# this will remove dependency on dev packages that are imported in phpstan.neon
rm -f "$NESTED_DIRECTORY/phpstan-for-rector.neon"

Expand All @@ -50,14 +45,9 @@ wget https://github.com/humbug/php-scoper/releases/download/0.14.0/php-scoper.ph

php php-scoper.phar add-prefix bin config packages rules src templates vendor composer.json --output-dir "../$SCOPED_DIRECTORY" --config scoper.php.inc --force --ansi --working-dir "$NESTED_DIRECTORY"

# keep only one PHPStan version
note "Remove package phpstan version"
rm -rf "$SCOPED_DIRECTORY/vendor/phpstan/phpstan"

note "Dumping Composer Autoload"
composer dump-autoload --working-dir "$SCOPED_DIRECTORY" --ansi --optimize --classmap-authoritative --no-dev


# clean up
rm -rf "$NESTED_DIRECTORY"

Expand All @@ -66,7 +56,6 @@ note "Copy metafiles like composer.json, .github etc to repository"
rm -f "$SCOPED_DIRECTORY/composer.json"
cp -R scoped/. "$SCOPED_DIRECTORY"


# make bin/rector runnable without "php"
chmod 777 "$SCOPED_DIRECTORY/bin/rector"
chmod 777 "$SCOPED_DIRECTORY/bin/rector.php"
Expand Down
2 changes: 2 additions & 0 deletions scoped/.github/workflows/along_phpstan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ jobs:
cd standalone
# wait for deploy to packagist
sleep 60
- run: |
cd standalone
# run
composer require rector/rector-prefixed:dev-master --dev --ansi
composer require phpstan/phpstan --dev --ansi
-
run: |
cd standalone
Expand Down
2 changes: 1 addition & 1 deletion scoped/.github/workflows/composer_dependency.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
mkdir standalone
cd standalone
# wait for deploy to packagist
sleep 45
sleep 60
- run: |
cd standalone
Expand Down
2 changes: 1 addition & 1 deletion scoped/.github/workflows/finalize_classes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
mkdir standalone
cd standalone
# wait for deploy to packagist
sleep 45
sleep 60
- run: |
cd standalone
Expand Down
3 changes: 2 additions & 1 deletion scoped/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"bin/rector"
],
"require": {
"php": "^7.3|^8.0"
"php": "^7.3|^8.0",
"phpstan/phpstan": "^0.12.64"
}
}
16 changes: 3 additions & 13 deletions scoper.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use Nette\Utils\DateTime;
use Nette\Utils\Strings;
use Rector\Compiler\PhpScoper\StaticEasyPrefixer;
use Rector\Compiler\ValueObject\ScoperOption;
use Symfony\Component\Finder\Finder;

require_once __DIR__ . '/vendor/autoload.php';

Expand All @@ -17,16 +16,6 @@ $filePathsToSkip = [
];

// remove phpstan, because it is already prefixed in its own scope
$finder = new Finder();
$phpstanPhpFileInfos = $finder->files()
->name('*.php')
// the working dir is already "rector-nested"
->in(__DIR__ . '/vendor/phpstan/phpstan-extracted')
->getIterator();

foreach ($phpstanPhpFileInfos as $phpstanPhpFileInfo) {
$filePathsToSkip[] = $phpstanPhpFileInfo->getRealPath();
}

$dateTime = DateTime::from('now');
$timestamp = $dateTime->format('Ymd');
Expand All @@ -41,7 +30,8 @@ return [

// scoper missed PSR-4 autodiscovery in Symfony
function (string $filePath, string $prefix, string $content): string {
if (!Strings::endsWith($filePath, 'config.php') && !Strings::endsWith($filePath, 'services.php')) {
// scoper missed PSR-4 autodiscovery in Symfony
if (! Strings::endsWith($filePath, 'config.php') && ! Strings::endsWith($filePath, 'services.php')) {
return $content;
}

Expand All @@ -51,6 +41,6 @@ return [
}

return Strings::replace($content, '#services\->load\(\'#', 'services->load(\'' . $prefix . '\\');
}
},
],
];
4 changes: 3 additions & 1 deletion utils/compiler/src/PhpScoper/StaticEasyPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ final class StaticEasyPrefixer
'Rector\*',
// we use this API a lot
'PhpParser\*',

// phpstan needs to be here, as phpstan-extracted/vendor autoload is statically generated and namespaces cannot be changed
'PHPStan\*',
// 'Symplify\*',

// doctrine annotations to autocomplete
'Doctrine\ORM\Mapping\*',
];
Expand Down

0 comments on commit 5203352

Please sign in to comment.