Skip to content

Commit 3bf372a

Browse files
Merge pull request #16 from laravel/feat/dev-tools
Add package quality tooling
2 parents 0644a5f + 3502182 commit 3bf372a

40 files changed

Lines changed: 668 additions & 211 deletions

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directories:
5+
- "/"
6+
schedule:
7+
interval: "weekly"
8+
cooldown:
9+
default-days: 5
10+
groups:
11+
github-actions:
12+
patterns:
13+
- "*"

.github/workflows/tests.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 1.x
8+
- 2.x
9+
pull_request:
10+
branches:
11+
- main
12+
- 1.x
13+
- 2.x
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
tests:
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
php-version: ['8.3', '8.4', '8.5']
26+
27+
steps:
28+
- name: Checkout Code
29+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
30+
with:
31+
persist-credentials: false
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
35+
with:
36+
php-version: ${{ matrix.php-version }}
37+
tools: composer:v2
38+
coverage: none
39+
40+
- name: Install Dependencies
41+
run: composer install --no-interaction --prefer-dist --optimize-autoloader
42+
43+
- name: Run Static Analysis
44+
run: composer analyse
45+
46+
- name: Run Lint Check
47+
run: composer lint:check
48+
49+
- name: Run Type Coverage
50+
run: composer test:types
51+
52+
- name: Run Unit Tests
53+
run: composer test:unit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
vendor
2+
composer.lock

composer.json

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,51 @@
2828
"src/functions.php"
2929
]
3030
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"Tests\\": "tests/"
34+
}
35+
},
3136
"require": {
32-
"php": "^8.2"
37+
"php": "^8.3"
38+
},
39+
"require-dev": {
40+
"laravel/pao": "^1.1",
41+
"laravel/pint": "^1.29",
42+
"pestphp/pest": "^4.7",
43+
"pestphp/pest-plugin-type-coverage": "^4.0",
44+
"phpstan/phpstan": "^2.2"
3345
},
3446
"bin": [
3547
"cpx"
36-
]
48+
],
49+
"scripts": {
50+
"analyse": [
51+
"phpstan analyse"
52+
],
53+
"lint": [
54+
"pint --parallel"
55+
],
56+
"lint:check": [
57+
"pint --parallel --test"
58+
],
59+
"test:types": [
60+
"pest --type-coverage --min=100"
61+
],
62+
"test:unit": [
63+
"pest --parallel"
64+
],
65+
"test": [
66+
"@analyse",
67+
"@lint:check",
68+
"@test:types",
69+
"@test:unit"
70+
]
71+
},
72+
"config": {
73+
"allow-plugins": {
74+
"pestphp/pest-plugin": true
75+
},
76+
"sort-packages": true
77+
}
3778
}

cpx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ if (isset($GLOBALS['_composer_autoload_path'])) {
3434
unset($file);
3535
}
3636

37-
function printColor(string $message, string $color = "\033[1;32m"): void
38-
{
39-
echo $color . $message . "\033[0m" . PHP_EOL;
40-
}
41-
4237
array_shift($argv);
4338
$console = Console::parse($argv ?? []);
4439

files/psysh-config.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
require_once __DIR__ . '/../vendor/autoload.php';
3+
use Cpx\PhpExecutionHelper;
44

5-
Cpx\PhpExecutionHelper::init(getcwd());
5+
require_once __DIR__.'/../vendor/autoload.php';
6+
7+
PhpExecutionHelper::init(getcwd());
68

79
return [];

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 7
3+
paths:
4+
- src

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Test Suite">
9+
<directory suffix="Test.php">./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory suffix=".php">src</directory>
15+
</include>
16+
</source>
17+
</phpunit>

pint.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"blank_line_before_statement": {
5+
"statements": [
6+
"break",
7+
"continue",
8+
"declare",
9+
"if",
10+
"return",
11+
"throw",
12+
"try"
13+
]
14+
},
15+
"global_namespace_import": {
16+
"import_classes": true
17+
},
18+
"trailing_comma_in_multiline": {
19+
"elements": [
20+
"arguments",
21+
"arrays",
22+
"match",
23+
"parameters"
24+
]
25+
}
26+
}
27+
}

src/ClassAliasAutoloader.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Cpx;
46

5-
use RecursiveIteratorIterator;
67
use RecursiveDirectoryIterator;
8+
use RecursiveIteratorIterator;
79
use SplFileInfo;
810

911
class ClassAliasAutoloader
1012
{
11-
/** All of the discovered classes. */
13+
/** @var array<string, string> */
1214
protected array $classes = [];
1315

1416
public function __construct(
@@ -21,13 +23,13 @@ public function addAliases(string $autoloadRootDirectory): void
2123
$classes = require "{$autoloadRootDirectory}/vendor/composer/autoload_classmap.php";
2224

2325
foreach ($classes as $class => $path) {
24-
if (!str_contains($class, '\\')) {
26+
if (! str_contains($class, '\\')) {
2527
continue;
2628
}
2729

2830
$name = basename(str_replace('\\', '/', $class));
2931

30-
if (!isset($this->classes[$name]) && class_exists($name)) {
32+
if (! isset($this->classes[$name]) && class_exists($name)) {
3133
$this->classes[$name] = $class;
3234
}
3335
}
@@ -38,12 +40,12 @@ public function addAliases(string $autoloadRootDirectory): void
3840

3941
foreach ($psr4 as $namespace => $directories) {
4042
foreach ($directories as $directory) {
41-
if (!file_exists($directory)) {
43+
if (! file_exists($directory)) {
4244
continue;
4345
}
4446
$iterator = new RecursiveIteratorIterator(
4547
new RecursiveDirectoryIterator($directory),
46-
RecursiveIteratorIterator::LEAVES_ONLY
48+
RecursiveIteratorIterator::LEAVES_ONLY,
4749
);
4850

4951
foreach ($iterator as $file) {
@@ -53,13 +55,12 @@ public function addAliases(string $autoloadRootDirectory): void
5355

5456
$relativePath = str_replace($directory, '', $file->getPath());
5557

56-
if (!empty($relativePath)) {
57-
$classNamespace .= strtr($relativePath, DIRECTORY_SEPARATOR, '\\') . '\\';
58+
if (! empty($relativePath)) {
59+
$classNamespace .= strtr($relativePath, DIRECTORY_SEPARATOR, '\\').'\\';
5860
}
5961

6062
$basename = $file->getBasename('.php');
61-
$class = str_replace('\\\\', '\\', $classNamespace . $basename);
62-
63+
$class = str_replace('\\\\', '\\', $classNamespace.$basename);
6364

6465
if (str_ends_with($basename, 'Test')) {
6566
continue;

0 commit comments

Comments
 (0)