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
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
/phpunit.xml export-ignore
/pint.json export-ignore
/typephp.php export-ignore
/mago.toml export-ignore
/psalm.xml export-ignore
/.php-cs-fixer.dist.php export-ignore
/codecov.yml export-ignore
/rector.php export-ignore
/typephp.php export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: clover.xml
fail_ci_if_error: true
fail_ci_if_error: false

- name: Run Test Suite (Pest)
run: ./vendor/bin/pest --compact
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/var
/manual-tests
composer.lock
index.php
index.php
.php-cs-fixer.cache
16 changes: 16 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__ . '/src')
->exclude('vendor');

return (new Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
])
->setFinder($finder)
->setRiskyAllowed(true);
39 changes: 30 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
# Contributing to TypePHP

Thank you for showing interest in contributing to this TypePHP library! Contributions are essential for building a robust type-safe ecosystem for the PHP community.
Thank you for showing interest in contributing to TypePHP! Contributions are essential for building a robust, type-safe ecosystem for the PHP community.

This library is designed to be a reliable foundation for high-performance applications. To achieve this, it maintains rigorous standards for code quality and developer experience.
This library is designed to be a reliable foundation for high-performance applications. To achieve this, it maintains rigorous standards for code quality, developer experience, and static analysis compatibility.

---

## Development Workflow

To ensure consistency across the ecosystem, this repository requires the following workflow:
To ensure consistency across the codebase, this repository requires the following workflow:

1. **Fork and Branch**: Fork the repository and create a feature branch from `main`.
2. **Dependencies**: Install development tools using `composer install`.
3. **Coding Standards**: This project follows strict PSR-12 standards. Use Laravel Pint to format code: `./vendor/bin/pint`.
4. **Static Analysis**: Code must be predictable and type-safe. It must pass PHPStan at the maximum level: `./vendor/bin/phpstan analyse`.
5. **Testing**: This project uses Pest. Ensure the test suite passes completely: `./vendor/bin/pest`.
3. **Linting & Code Formatting Authority (Laravel Pint)**: This project follows strict PSR-12 standards. Laravel Pint is the **sole authoritative linter and formatter** for the entire codebase:
```bash
./vendor/bin/pint
```
4. **Static Analysis Authority (PHPStan)**: Code must pass **PHPStan at Level MAX** (`treatPhpDocTypesAsCertain: false`):
```bash
./vendor/bin/phpstan analyse
```
5. **Testing**: This project uses Pest. Ensure all tests pass completely:
```bash
./vendor/bin/pest
```
6. **Strict Typing**: Every PHP file must begin with `declare(strict_types=1);`.

---

## Tooling Authority & Interoperability Policy

* **Laravel Pint is the Authoritative Linter & Formatter**: All code styling and linting rules are defined strictly in `pint.json`. No external style linter overrides Pint.
* **PHPStan is the Authoritative Static Analyzer**: PHPStan configured at Level MAX is the official gatekeeper for type safety and code quality in TypePHP. All contributions must pass PHPStan checks without errors.
* **Tooling Interoperability (Psalm, Mago, Rector, PHP-CS-Fixer, etc.)**: Secondary analyzers and tools (such as Psalm, Mago, Rector, and PHP-CS-Fixer) are integrated into the test environment solely for **interoperability verification** and ensuring that TypePHP's runtime stream wrapper and AST transformations stand down properly and do not deadlock or conflict with external static analysis engines.

---

## Pull Request Process

1. **Start with an Issue**: Before writing code, please open an issue to discuss the bug or the proposed feature.
2. **Tests are Required**: Every Pull Request must include automated tests that cover the new logic or prevent the bug from recurring.
1. **Start with an Issue**: Before writing code, please open an issue to discuss the bug or proposed feature.
2. **Tests are Required**: Every Pull Request must include automated Pest tests that cover the new logic and prevent regressions.
3. **Keep Code Clean**: Run `./vendor/bin/pint`, `./vendor/bin/phpstan analyse`, and `./vendor/bin/pest` before submitting your PR.

---

The Hibla ecosystem thanks you for your time and effort!
The TypePHP ecosystem thanks you for your time and effort!
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coverage:
status:
project:
default:
enabled: false
patch:
default:
enabled: false

comment:
layout: "reach,diff,flags,files,footer"
behavior: default
24 changes: 20 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
"pestphp/pest": "^2.0 || ^3.0 || ^4.0",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/extension-installer": "^1.4"
"phpstan/extension-installer": "^1.4",
"vimeo/psalm": "^6.16",
"carthage-software/mago": "^1.47",
"rector/rector": "^2.6",
"friendsofphp/php-cs-fixer": "^3.95"
},
"bin": [
"bin/typephp"
Expand Down Expand Up @@ -62,8 +66,20 @@
"test": [
"./vendor/bin/pest --colors"
],
"analyse": [
"./vendor/bin/phpstan analyse"
"analyze": [
"./vendor/bin/phpstan analyze"
],
"psalm": [
"./vendor/bin/psalm"
],
"mago": [
"./vendor/bin/mago analyze"
],
"rector": [
"./vendor/bin/rector process"
],
"rector:dry": [
"./vendor/bin/rector process --dry-run"
]
},
"minimum-stability": "dev",
Expand All @@ -74,4 +90,4 @@
"phpstan/extension-installer": true
}
}
}
}
7 changes: 7 additions & 0 deletions mago.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
php-version = "8.1.0"

[source]
paths = ["src"]
includes = []
excludes = ["tests/**", "vendor/**", "storage/**", "var/**", "cache/**"]

17 changes: 17 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm errorLevel="8" resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" findUnusedBaselineEntry="false" findUnusedCode="false">
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<!-- #[Override] is a PHP 8.3+ feature; TypePHP supports PHP 8.1+ -->
<MissingOverrideAttribute errorLevel="suppress" />
<UndefinedVariable errorLevel="suppress" />
</issueHandlers>
</psalm>
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\CallLike\AddNameToBooleanArgumentRector;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
])
->withoutParallel()
->withRules([
AddNameToBooleanArgumentRector::class,
])
;
4 changes: 2 additions & 2 deletions src/Command/CliFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static function initVT100(): void
{
if (! self::$vt100Initialized) {
if (\function_exists('sapi_windows_vt100_support')) {
@sapi_windows_vt100_support(STDOUT, true);
@sapi_windows_vt100_support(STDERR, true);
@sapi_windows_vt100_support(STDOUT, enable: true);
@sapi_windows_vt100_support(STDERR, enable: true);
}
self::$vt100Initialized = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Command/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public static function run(array $args, $outputStream = STDOUT, $errorStream = S
{
$c = [CliFormatter::class, 'color'];

$showHelp = \in_array('help', $args, true)
|| \in_array('typephp:help', $args, true)
|| \in_array('--help', $args, true)
|| \in_array('-h', $args, true)
$showHelp = \in_array('help', $args, strict: true)
|| \in_array('typephp:help', $args, strict: true)
|| \in_array('--help', $args, strict: true)
|| \in_array('-h', $args, strict: true)
|| $args === [];

if ($showHelp) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function execute(array $args, $outputStream = STDOUT, $errorStream = STDE
$givenTargetCandidate = $arg;
$ext = strtolower(pathinfo($arg, PATHINFO_EXTENSION));

if ($ext !== '' && ! \in_array($ext, self::VALID_PHP_EXTENSIONS, true)) {
if ($ext !== '' && ! \in_array($ext, self::VALID_PHP_EXTENSIONS, strict: true)) {
fwrite($errorStream, "\n " . $c(' TYPEPHP ', 'badge_red') . ' ' . $c('Error', 'bold') . "\n\n");
fwrite($errorStream, ' ' . $c('✗', 'red') . ' Target file ' . $c('"' . $arg . '"', 'bold') . " is not a PHP script file. TypePHP can only execute PHP files.\n\n");

Expand Down
Loading
Loading