forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHAR compiler inside phpstan/phpstan-src
- Loading branch information
1 parent
37927e0
commit 3398198
Showing
36 changed files
with
721 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,20 +31,24 @@ script: | |
|
||
jobs: | ||
include: | ||
- stage: test | ||
name: Compiler tests | ||
script: | ||
- | | ||
cd compiler && \ | ||
composer install --no-interaction && \ | ||
vendor/bin/phpunit -c tests/phpunit.xml tests && \ | ||
../bin/phpstan analyse -l 8 src && \ | ||
./run-e2e-tests.sh $TRAVIS_COMMIT | ||
- stage: phar | ||
name: PHAR | ||
script: | ||
- | | ||
git clone https://github.com/phpstan/phpstan-compiler && \ | ||
cd phpstan-compiler && \ | ||
./run-e2e-tests.sh $TRAVIS_COMMIT && \ | ||
cd .. && \ | ||
composer install --working-dir=phpstan-compiler && \ | ||
php phpstan-compiler/bin/compile $TRAVIS_COMMIT && \ | ||
git clone https://${GITHUB_TOKEN}@github.com/phpstan/phpstan.git > /dev/null 2>&1 && \ | ||
cp phpstan-compiler/tmp/phpstan.phar phpstan/phpstan.phar && \ | ||
cp phpstan-compiler/tmp/phpstan.phar phpstan/phpstan && \ | ||
cd phpstan && \ | ||
composer install --working-dir=compiler && \ | ||
php compiler/bin/compile $TRAVIS_COMMIT && \ | ||
git clone https://${GITHUB_TOKEN}@github.com/phpstan/phpstan.git phpstan-dist > /dev/null 2>&1 && \ | ||
cp compiler/tmp/phpstan.phar phpstan-dist/phpstan.phar && \ | ||
cp compiler/tmp/phpstan.phar phpstan-dist/phpstan && \ | ||
cd phpstan-dist && \ | ||
git config user.email "[email protected]" && \ | ||
git config user.name "Travis CI" && \ | ||
git add phpstan phpstan.phar && \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# PHAR Compiler for PHPStan | ||
|
||
## Compile the PHAR | ||
|
||
```bash | ||
composer install | ||
php bin/compile [version] [repository] | ||
``` | ||
|
||
Default `version` is `master`, and default `repository` is `https://github.com/phpstan/phpstan.git`. | ||
|
||
The compiled PHAR will be in `tmp/phpstan.phar`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env php | ||
<?php declare(strict_types = 1); | ||
|
||
use PHPStan\Compiler\Console\CompileCommand; | ||
use PHPStan\Compiler\Filesystem\SymfonyFilesystem; | ||
use PHPStan\Compiler\Process\DefaultProcessFactory; | ||
use Symfony\Component\Console\Application; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$compileCommand = new CompileCommand( | ||
new SymfonyFilesystem(new \Symfony\Component\Filesystem\Filesystem()), | ||
new DefaultProcessFactory(), | ||
__DIR__ . '/../build', | ||
__DIR__ . '/../tmp/build' | ||
); | ||
|
||
$application = new Application(); | ||
$application->add($compileCommand); | ||
$application->setDefaultCommand($compileCommand->getName(), true); | ||
$application->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"alias": "phpstan.phar", | ||
"banner": false, | ||
"base-path": "../tmp/build", | ||
"check-requirements": false, | ||
"compactors": [ | ||
"KevinGH\\Box\\Compactor\\PhpScoper" | ||
], | ||
"directories": [ | ||
"conf", | ||
"src", | ||
"stubs", | ||
"vendor" | ||
], | ||
"output": "../phpstan.phar", | ||
"php-scoper": "../../build/scoper.inc.php" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
includes: | ||
- ../vendor/phpstan/phpstan-strict-rules/rules.neon | ||
- ../vendor/phpstan/phpstan-phpunit/extension.neon | ||
- ../vendor/phpstan/phpstan-phpunit/rules.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php declare(strict_types=1); | ||
|
||
$stubs = []; | ||
$stubFinder = \Isolated\Symfony\Component\Finder\Finder::create(); | ||
foreach ($stubFinder->files()->name('*.php')->in('../tmp/build/stubs') as $file) { | ||
$stubs[] = $file->getPathName(); | ||
} | ||
|
||
return [ | ||
'prefix' => null, | ||
'finders' => [], | ||
'files-whitelist' => $stubs, | ||
'patchers' => [ | ||
function (string $filePath, string $prefix, string $content): string { | ||
if ($filePath !== 'bin/phpstan') { | ||
return $content; | ||
} | ||
return str_replace('__DIR__ . \'/..', '\'phar://phpstan.phar', $content); | ||
}, | ||
function (string $filePath, string $prefix, string $content): string { | ||
if ($filePath !== 'vendor/nette/di/src/DI/Compiler.php') { | ||
return $content; | ||
} | ||
return str_replace('|Nette\\\\DI\\\\Statement', sprintf('|\\\\%s\\\\Nette\\\\DI\\\\Statement', $prefix), $content); | ||
}, | ||
function (string $filePath, string $prefix, string $content): string { | ||
if ($filePath !== 'vendor/nette/di/src/DI/Config/DefinitionSchema.php') { | ||
return $content; | ||
} | ||
$content = str_replace( | ||
sprintf('\'%s\\\\callable', $prefix), | ||
'\'callable', | ||
$content | ||
); | ||
$content = str_replace( | ||
'|Nette\\\\DI\\\\Definitions\\\\Statement', | ||
sprintf('|%s\\\\Nette\\\\DI\\\\Definitions\\\\Statement', $prefix), | ||
$content | ||
); | ||
|
||
return $content; | ||
}, | ||
function (string $filePath, string $prefix, string $content): string { | ||
if ($filePath !== 'vendor/nette/di/src/DI/Extensions/ExtensionsExtension.php') { | ||
return $content; | ||
} | ||
$content = str_replace( | ||
sprintf('\'%s\\\\string', $prefix), | ||
'\'string', | ||
$content | ||
); | ||
$content = str_replace( | ||
'|Nette\\\\DI\\\\Definitions\\\\Statement', | ||
sprintf('|%s\\\\Nette\\\\DI\\\\Definitions\\\\Statement', $prefix), | ||
$content | ||
); | ||
|
||
return $content; | ||
}, | ||
function (string $filePath, string $prefix, string $content): string { | ||
if ($filePath !== 'src/Testing/TestCase.php') { | ||
return $content; | ||
} | ||
return str_replace(sprintf('\\%s\\PHPUnit\\Framework\\TestCase', $prefix), '\\PHPUnit\\Framework\\TestCase', $content); | ||
}, | ||
function (string $filePath, string $prefix, string $content): string { | ||
if ($filePath !== 'src/Testing/LevelsTestCase.php') { | ||
return $content; | ||
} | ||
return str_replace( | ||
[sprintf('\\%s\\PHPUnit\\Framework\\AssertionFailedError', $prefix), sprintf('\\%s\\PHPUnit\\Framework\\TestCase', $prefix)], | ||
['\\PHPUnit\\Framework\\AssertionFailedError', '\\PHPUnit\\Framework\\TestCase'], | ||
$content | ||
); | ||
}, | ||
], | ||
'whitelist' => [ | ||
'PHPStan\*', | ||
'PhpParser\*', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "phpstan/phpstan-compiler", | ||
"type": "project", | ||
"description": "PHAR Compiler for PHPStan", | ||
"license": ["MIT"], | ||
"require": { | ||
"php": "^7.1", | ||
"symfony/console": "^4.1", | ||
"symfony/process": "^4.1", | ||
"symfony/filesystem": "^4.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"PHPStan\\Compiler\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"PHPStan\\Compiler\\": "tests/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^7.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor | ||
/composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
class PharTest extends \PHPStan\Testing\LevelsTestCase | ||
{ | ||
|
||
public function dataTopics(): array | ||
{ | ||
return [ | ||
['strictRulesExtension'], | ||
]; | ||
} | ||
|
||
public function getDataPath(): string | ||
{ | ||
return __DIR__ . '/data'; | ||
} | ||
|
||
public function getPhpStanExecutablePath(): string | ||
{ | ||
return __DIR__ . '/vendor/phpstan/phpstan/phpstan.phar'; | ||
} | ||
|
||
public function getPhpStanConfigPath(): ?string | ||
{ | ||
return __DIR__ . '/phpstan.neon'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"require": { | ||
"php": "^7.1" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "dev-master", | ||
"phpstan/phpstan-strict-rules": "dev-master", | ||
"nikic/php-parser": "^4.0", | ||
"phpunit/phpunit": "^7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"PHPStan\\E2E\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"message": "Dynamic call to static method PHPStan\\E2E\\DynamicCallToStaticMethod::bar().", | ||
"line": 10, | ||
"ignorable": true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\E2E; | ||
|
||
class DynamicCallToStaticMethod | ||
{ | ||
|
||
public function foo(): void | ||
{ | ||
$this->bar(); | ||
} | ||
|
||
public static function bar(): void | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-strict-rules/rules.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\E2E; | ||
|
||
use PhpParser\Node\Scalar\String_; | ||
|
||
class PharAutoloaderWorks | ||
{ | ||
|
||
public function __construct(String_ $string) | ||
{ | ||
unset($string); | ||
} | ||
|
||
} | ||
|
||
new PharAutoloaderWorks(new String_('')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
require_once __DIR__ . '/src/PharAutoloaderWorks.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
set -ev | ||
|
||
# compile phar | ||
if [ ! -f tmp/phpstan.phar ]; then | ||
php bin/compile $1 | ||
fi | ||
|
||
# setup | ||
cd e2e | ||
rm -rf vendor | ||
rm -f composer.lock | ||
composer install --no-interaction | ||
cp -f ../tmp/phpstan.phar vendor/phpstan/phpstan/phpstan.phar | ||
cp -f ../tmp/phpstan.phar vendor/phpstan/phpstan/phpstan | ||
|
||
# test that the phar autoloader works | ||
php testPharAutoloader.php | ||
|
||
# test levels | ||
vendor/bin/phpunit PharTest.php |
Oops, something went wrong.