Skip to content

Commit 5beda06

Browse files
committed
Improve project structure + tooling
1 parent 4c76c47 commit 5beda06

25 files changed

Lines changed: 230 additions & 132 deletions

‎.editorconfig‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,4 @@ insert_final_newline = false
1111

1212
[*.php]
1313

14-
end_of_line = lf
15-
charset = utf-8
16-
indent_style = space
17-
indent_size = 4
18-
insert_final_newline = true
19-
trim_trailing_whitespace = true
14+
insert_final_newline = true

‎.gitattributes‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1+
/bin export-ignore
2+
/build export-ignore
13
/tests export-ignore
4+
/tools export-ignore
25
/examples export-ignore
3-
/.gitattributes export-ignore
4-
/.gitignore export-ignore
5-
/phpunit.xml.dist export-ignore
6-
/phpcs.xml.dist export-ignore
7-
/captainhook.json export-ignore
8-
/.travis.yml export-ignore
9-
/ruleset.xml export-ignore
6+
/docker export-ignore
7+
/vendor-bin export-ignore
108
/.editorconfig export-ignore
11-
/phpstan.neon export-ignore
12-
/phpstan-baseline.neon export-ignore
13-
/psalm.xml export-ignore
14-
/psalm-baseline.xml export-ignore
15-
/vendor-bin export-ignore
9+
/.gitattributes export-ignore
10+
/.gitignore export-ignore

‎.gitignore‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
/vendor
44
/vendor-bin/**/vendor
55
/vendor-bin/**/composer.lock
6-
/.phpunit*
76
/tests/_output
87
/tests/_reports
9-
/build
8+
/build
9+
/tools/cache/*
10+
!/tools/cache/.gitkeep

‎.travis.yml‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎bin/vendorbin‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env php
2+
<?php
3+
error_reporting(E_ALL); // Report everything, even notices
4+
set_time_limit(0); // No time limit for console commands
5+
6+
$projectDir = dirname(__DIR__);
7+
8+
$composerRunType = $_SERVER['argv'][1] ?? 'outdated';
9+
10+
require $projectDir.'/vendor/autoload.php';
11+
12+
$sourceFinder = new \Symfony\Component\Finder\Finder();
13+
$sourceFinder->in($projectDir . '/vendor-bin')->directories()->depth(0)->sortByName();
14+
15+
/** @var array<string, \Symfony\Component\Process\Process> $tools */
16+
$tools = [];
17+
18+
foreach ($sourceFinder as $directory) {
19+
$toolName = $directory->getFilename();
20+
21+
$options = [
22+
'--ansi',
23+
];
24+
25+
if ($composerRunType === 'update') {
26+
$options[] = '--no-progress';
27+
}
28+
29+
$process = new \Symfony\Component\Process\Process(['composer', $composerRunType, ...$options]);
30+
if (isset($_SERVER['COMPOSER_CACHE_DIR'])) {
31+
$process->setEnv(['COMPOSER_CACHE_DIR' => $_SERVER['COMPOSER_CACHE_DIR']]);
32+
}
33+
$process->setWorkingDirectory($projectDir . '/vendor-bin/' . $toolName);
34+
$process->start();
35+
$process->wait();
36+
37+
echo 'Running composer ' . $composerRunType . ' for ' . $toolName . ' ...' . "\n";
38+
39+
$processOutput = \trim($process->getOutput());
40+
41+
if ($composerRunType === 'update') {
42+
$processOutput = \trim($processOutput . "\n" . $process->getErrorOutput());
43+
}
44+
45+
if (\strlen($processOutput) > 0) {
46+
echo $processOutput . "\n";
47+
}
48+
}

‎composer.json‎

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=8.0",
19+
"php": ">=8.2",
2020
"ext-mbstring": "*"
2121
},
2222
"require-dev": {
23-
"bamarni/composer-bin-plugin": "^1.3",
24-
"captainhook/plugin-composer": "^5.0",
25-
"phpunit/phpunit": "^9.0"
23+
"captainhook/captainhook-phar": "^5.0",
24+
"captainhook/hook-installer": "^1.0",
25+
"phpunit/phpunit": "^11.4",
26+
"symfony/finder": "^7.0",
27+
"symfony/process": "^7.0"
2628
},
2729
"config": {
28-
"sort-packages": false
30+
"sort-packages": false,
31+
"allow-plugins": {
32+
"captainhook/captainhook-phar": true,
33+
"captainhook/hook-installer": true
34+
}
35+
},
36+
"extra": {
37+
"captainhook": {
38+
"config": "tools/captainhook.json"
39+
}
2940
},
3041
"autoload": {
3142
"psr-4": {
@@ -38,18 +49,20 @@
3849
}
3950
},
4051
"scripts": {
41-
"phpstan": "vendor/bin/phpstan analyse",
42-
"phpstan_full": "vendor/bin/phpstan clear-result-cache && vendor/bin/phpstan analyse",
43-
"phpstan_base": "vendor/bin/phpstan analyse --configuration=phpstan.neon --generate-baseline=phpstan-baseline.neon",
44-
"psalm": "vendor/bin/psalm --show-info=false",
45-
"psalm_full": "vendor/bin/psalm --clear-cache && vendor/bin/psalm --show-info=false",
46-
"psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml",
47-
"phpunit": "vendor/bin/phpunit --colors=always",
48-
"phpunit_clover": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml",
49-
"phpcs": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache src tests",
50-
"phpcsfix": "vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --cache src tests",
51-
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html tests/_reports",
52-
"binupdate": "@composer bin all update --ansi",
53-
"bininstall": "@composer bin all install --ansi"
52+
"captainhook_install": "vendor/bin/captainhook install --configuration=tools/captainhook.json --ansi --no-interaction",
53+
"phpstan": "vendor-bin/phpstan/vendor/bin/phpstan analyse --configuration=tools/phpstan.neon",
54+
"phpstan_full": "rm -Rf tools/cache/phpstan && vendor-bin/phpstan/vendor/bin/phpstan analyse --configuration=tools/phpstan.neon",
55+
"phpstan_base": "vendor-bin/phpstan/vendor/bin/phpstan analyse --configuration=tools/phpstan.neon --generate-baseline=tools/phpstan-baseline.php",
56+
"psalm": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --show-info=false",
57+
"psalm_full": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --clear-cache && vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --show-info=false",
58+
"psalm_base": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --set-baseline=tools/psalm-baseline.xml",
59+
"phpunit": "vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --colors=always",
60+
"phpunit_clover": "vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --coverage-text --coverage-clover build/logs/clover.xml",
61+
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --coverage-html=tests/_reports",
62+
"phpcs": "vendor-bin/phpcs/vendor/bin/phpcs --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
63+
"phpcs_diff": "vendor-bin/phpcs/vendor/bin/phpcs -s --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
64+
"phpcs_fix": "vendor-bin/phpcs/vendor/bin/phpcbf --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
65+
"binupdate": "bin/vendorbin update",
66+
"binoutdated": "bin/vendorbin outdated"
5467
}
5568
}

‎docker/compose/composer.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
services:
2+
composer:
3+
image: thecodingmachine/php:8.2-v5-cli
4+
container_name: squirrel_composer
5+
working_dir: /usr/src/app
6+
command: [ "composer", "${COMPOSER_COMMAND}", "--ansi" ]
7+
logging:
8+
driver: "none"
9+
volumes:
10+
- .:/usr/src/app
11+
- "$HOME/.cache/composer:/tmp/composer_cache"
12+
environment:
13+
COMPOSER_CACHE_DIR: "/tmp/composer_cache"
14+
COMPOSER_ROOT_VERSION: 'dev-master'
15+
# Basic config for CLI commands
16+
PHP_INI_ERROR_REPORTING: "E_ALL"
17+
PHP_INI_MEMORY_LIMIT: "1g"
18+
PHP_INI_MAX_EXECUTION_TIME: 3600
19+
# Enable Opcache + JIT
20+
PHP_INI_OPCACHE__ENABLE_CLI: 1
21+
PHP_INI_OPCACHE__MEMORY_CONSUMPTION: 256
22+
PHP_INI_OPCACHE__VALIDATE_TIMESTAMPS: 0
23+
PHP_INI_JIT_BUFFER_SIZE: "256m"
24+
# For code coverage
25+
PHP_EXTENSION_XDEBUG: 1
26+
XDEBUG_MODE: coverage

‎docker/composer‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# Get directory of this script
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
COMPOSER_COMMAND="$@" docker compose -f "$DIR/compose/composer.yml" --project-directory "$DIR/.." --project-name=squirrel_composer up --abort-on-container-exit --exit-code-from=composer --no-log-prefix composer 2>&1

‎phpstan.neon‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎phpunit.xml.dist‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)