Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muqsit/preprocessor
A PHP compiler written in PHP using PHPStan for code analysis.
https://github.com/muqsit/preprocessor
compiler php php-parser phpstan
Last synced: 2 months ago
JSON representation
A PHP compiler written in PHP using PHPStan for code analysis.
- Host: GitHub
- URL: https://github.com/muqsit/preprocessor
- Owner: Muqsit
- Created: 2020-07-08T21:19:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-15T02:48:21.000Z (7 months ago)
- Last Synced: 2024-10-04T12:56:10.194Z (3 months ago)
- Topics: compiler, php, php-parser, phpstan
- Language: PHP
- Homepage:
- Size: 101 KB
- Stars: 25
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PreProcessor
Comment out debug code before pushing it to production.## Quick Start
### Installing
Install the library using composer:
```
composer require muqsit/preprocessor:dev-master
```### Preprocessing a list of PHP files
```php
require_once "src/proxy/Client.php";
require_once "src/proxy/Server.php";
require_once "src/proxy/Logger.php";use muqsit\preprocessor\PreProcessor;
use proxy\Logger;PreProcessor::fromPaths(["src/proxy/Client.php", "src/proxy/Server.php", "src/proxy/Logger.php"]) // files to preprocess
->commentOut(Logger::class, "debug")
->export("./preprocessed-src"); // preprocessed files written to ./preprocessed-src folder
```
Result:
```diff
final class Client{/** @var Logger */
private $logger;public function onLogin(){
- $this->logger->debug("Client logged in");
+ /* $this->logger->debug("Client logged in ") */;
}
}
```### Preprocessing a directory of PHP files
```php
require "vendor/autoload.php";use muqsit\preprocessor\PreProcessor;
use pocketmine\entity\Entity;
use pocketmine\Player;
use pocketmine\utils\Utils;PreProcessor::fromDirectory("./src") // searches for .php files recursively
->commentOut(Logger::class, "debug")
->commentOut(Utils::class, "testValidInstance")
->commentOut(Utils::class, "validateCallableSignature")
->commentOut(Client::class, "debugClientStatus")
->export("./preprocessed-src");
```
Result:
```diff
final class Player extends Client implements LoggerHolder{public function onJoin() : void{
- $this->getLogger()->debug("Player {$this->getUUID()} joined");
+ /* $this->getLogger()->debug("Player {$this->getUUID()} joined") */;- $this->sendMessage("You joined the server"); $this->debugClientStatus();
+ $this->sendMessage("You joined the server"); /* $this->debugClientStatus() */;
}public function registerQuitListener(Closure $listener) : void{
- Utils::validateCallableSignature(function(Player $player) : void{}, $listener);
+ /* Utils::validateCallableSignature(function(Player $player) : void{}, $listener) */;
}
}
```## Libraries Used
- [nikic/PHP-Parser](https://github.com/nikic/PHP-Parser/) - Reading and writing nodes using the formatting-preservation functionality
- [phpstan/phpstan](https://github.com/phpstan/phpstan) - Determinig type of variables, properties, methods etc within the scope