Skip to content

Commit 6b14261

Browse files
authored
V3 Work (#48)
2 parents 6296130 + 2aa69b7 commit 6b14261

605 files changed

Lines changed: 46086 additions & 8738 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
/.gitattributes export-ignore
55
/phpunit.xml export-ignore
66
/README.md export-ignore
7-
/tools export-ignore
8-
/docker export-ignore
7+
/tools export-ignore

.github/copilot-instructions.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Everywhere within this repository:
2+
* **Always** use `null|` in favor of `?` for nullable types (e.g. `?string` instead of `string|null`).
3+
* **Always** use variadic parameters instead of `array` for lists of items (e.g. `string ...$items` instead
4+
of `array $items`).
5+
* **Always** use `self` instead of the class name in method signatures (e.g.
6+
`public function setFoo(string $foo): self` instead of `public function setFoo(string $foo): MyClass`).
7+
* **Always** always match casing of class properties when defining parameters and methods (e.g.
8+
`public function setFooBar(string $FooBar)` if the class property is `$FooBar`).
9+
* **Always** define a phpdoc for `array` types that specifies the item type (e.g.
10+
`/** @param string[] $items */` for `array $items`).
11+
* **Never** edit files using sed, awk, or other shell utilities.
12+
* **Always** limit yourself to POSIX shell syntax when executing shell scripts.
13+
* **Always** run phpstan with 512MB of memory when analyzing generated code
14+
(e.g. `phpstan analyze -c phpstan.neon --memory-limit=512M src/`).
15+
* **Always** specify `: void` for methods that do not return a value (e.g. `public function setFoo(string $foo): void`).
16+
* This includes unit test methods (e.g. `public function testFoo(): void`).
17+
* **Always** use `declare(strict_types=1);` at the top of all PHP files.
18+
* Do not do this in PHPUnit test class files, as PHPUnit does not support strict types.
19+
* **Always** ensure that constructor parameters for enum fields also accept the enum value type
20+
(e.g. `public function __construct(string $foo, string|MyEnum $bar)`).
21+
* Write tests for both cases.
22+
* **Never** leave imports unused in generated code.
23+
* **Always** used named parameters wherever possible.
24+
* **Never** bother with docblocks unless they are necessary to specify types that cannot be expressed in code
25+
(e.g. `/** @param string[] $items */` for `array $items`).
26+
* **Never** call `jsonSerialize` directly in generated code from within others, as this is an implementation detail\
27+
of the `JsonSerializable` interface.
28+
* Instead, simply set the field of the output object to the raw value of the field (e.g.
29+
`$output->foo = $this->foo;` instead of `$output->foo = $this->foo->jsonSerialize();`).
30+
31+
# When generting code for concrete implementations of AbstractType:
32+
* **Always** ensure that class fields have an associated getter and setter method.
33+
* **Always** ensure the constructor has parameters for all class fields, and that the constructor parameters are
34+
assigned to the class fields.
35+
* **Always** write unit tests that use both the constructor and the setter methods to set class fields,
36+
and that use the getter methods and fields directly to verify that the fields were set correctly.

.github/workflows/tests.yaml

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
name: "Tests"
22

3+
permissions:
4+
actions: none
5+
attestations: none
6+
checks: none
7+
contents: read
8+
deployments: none
9+
id-token: none
10+
issues: none
11+
models: none
12+
discussions: none
13+
packages: none
14+
pages: none
15+
pull-requests: none
16+
security-events: none
17+
statuses: none
18+
319
on:
420
pull_request:
521
branches:
@@ -8,6 +24,15 @@ on:
824
- '**.php'
925
- 'composer.json'
1026
- 'composer.lock'
27+
- '.php-cs-fixer.php'
28+
- 'phpstan.neon'
29+
- 'psalm.xml'
30+
- 'tools/php-cs-fixer/composer.json'
31+
- 'tools/php-cs-fixer/composer.lock'
32+
- 'tools/phpstan/composer.json'
33+
- 'tools/phpstan/composer.lock'
34+
- 'tools/psalm/composer.json'
35+
- 'tools/psalm/composer.lock'
1136
- 'phpunit.xml'
1237
- '.github/workflows/tests.yaml'
1338
push:
@@ -17,23 +42,94 @@ on:
1742
- '**.php'
1843
- 'composer.json'
1944
- 'composer.lock'
45+
- '.php-cs-fixer.php'
46+
- 'phpstan.neon'
47+
- 'psalm.xml'
48+
- 'tools/php-cs-fixer/composer.json'
49+
- 'tools/php-cs-fixer/composer.lock'
50+
- 'tools/phpstan/composer.json'
51+
- 'tools/phpstan/composer.lock'
52+
- 'tools/psalm/composer.json'
53+
- 'tools/psalm/composer.lock'
2054
- 'phpunit.xml'
2155
- '.github/workflows/tests.yaml'
2256

2357
env:
2458
CONSUL_HTTP_ADDR: "127.0.0.1:8500"
25-
CONSUL_VERSION: '1.20.5'
59+
CONSUL_VERSION: '2.0.1'
2660

2761
jobs:
62+
checks:
63+
runs-on: ubuntu-22.04
64+
name: Checks - PHP 8.3
65+
steps:
66+
- uses: actions/checkout@v7
67+
68+
- uses: shivammathur/setup-php@v2
69+
with:
70+
php-version: '8.3'
71+
extensions: json,dom,simplexml,tokenizer,mbstring
72+
ini-values: precision=14,serialize_precision=-1
73+
ini-file: 'development'
74+
75+
- name: 'Install root composer deps'
76+
shell: bash -e {0}
77+
# language=sh
78+
run: |
79+
composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
80+
81+
- name: 'Restore tool vendor cache'
82+
id: tool-vendor-cache
83+
uses: actions/cache/restore@v6
84+
with:
85+
path: |
86+
tools/php-cs-fixer/vendor
87+
tools/phpstan/vendor
88+
tools/psalm/vendor
89+
key: "tool-vendor-${{ runner.os }}-8.3-${{ hashFiles('tools/php-cs-fixer/composer.lock', 'tools/phpstan/composer.lock', 'tools/psalm/composer.lock') }}"
90+
91+
- name: 'Install tool composer deps'
92+
shell: bash -e {0}
93+
# language=sh
94+
run: |
95+
composer install --working-dir tools/php-cs-fixer --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
96+
composer install --working-dir tools/phpstan --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
97+
composer install --working-dir tools/psalm --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
98+
99+
- name: 'Save tool vendor cache'
100+
if: steps.tool-vendor-cache.outputs.cache-hit != 'true' && steps.tool-vendor-cache.outputs.cache-hit != true
101+
uses: actions/cache/save@v6
102+
with:
103+
path: |
104+
tools/php-cs-fixer/vendor
105+
tools/phpstan/vendor
106+
tools/psalm/vendor
107+
key: "tool-vendor-${{ runner.os }}-8.3-${{ hashFiles('tools/php-cs-fixer/composer.lock', 'tools/phpstan/composer.lock', 'tools/psalm/composer.lock') }}"
108+
109+
- name: 'Execute php-cs-fixer'
110+
# language=bash
111+
run: |
112+
composer php-cs-fixer -- --dry-run --diff
113+
114+
- name: 'Execute phpstan'
115+
# language=bash
116+
run: |
117+
composer phpstan
118+
119+
- name: 'Execute psalm'
120+
# language=bash
121+
run: |
122+
composer psalm
123+
28124
tests:
29125
runs-on: ubuntu-22.04
30126
strategy:
31127
matrix:
32128
php-version:
33-
- '8.1'
34129
- '8.2'
35130
- '8.3'
36131
- '8.4'
132+
- '8.5'
37133

38134
name: Tests - PHP ${{ matrix.php-version }}
39135
steps:
@@ -46,10 +142,10 @@ jobs:
46142
run: |
47143
_phpunit_version=
48144
case "${{ matrix.php-version }}" in
49-
8.1) _phpunit_version='10.5' ;;
50-
8.2) _phpunit_version='11.1' ;;
51-
8.3) _phpunit_version='11.1' ;;
52-
8.4) _phpunit_version='11.1' ;;
145+
8.2) _phpunit_version='11.5' ;;
146+
8.3) _phpunit_version='12.0' ;;
147+
8.4) _phpunit_version='12.0' ;;
148+
8.5) _phpunit_version='12.0' ;;
53149
*) echo "Unsupported PHP version: ${{ matrix.php-version }}" && exit 1 ;;
54150
esac
55151
echo "phpunit-version=${_phpunit_version}" >> $GITHUB_OUTPUT
@@ -59,6 +155,7 @@ jobs:
59155
php-version: ${{ matrix.php-version }}
60156
extensions: json
61157
ini-values: precision=14,serialize_precision=-1
158+
ini-file: 'development'
62159

63160
- name: 'Install jq'
64161
uses: dcarbone/install-jq-action@v4
@@ -85,7 +182,7 @@ jobs:
85182
uses: actions/cache@v6
86183
with:
87184
path: ${{ steps.composer-cache.outputs.dir }}
88-
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ steps.vars.outputs.phpunit-version }}-${{ hashFiles('composer.lock') }}"
185+
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ steps.vars.outputs.phpunit-version }}-${{ hashFiles('composer.json') }}"
89186

90187
- name: 'Install composer deps'
91188
shell: bash -e {0}
@@ -99,7 +196,7 @@ jobs:
99196
uses: actions/cache/save@v6
100197
with:
101198
path: ${{ steps.composer-cache.outputs.dir }}
102-
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ steps.vars.outputs.phpunit-version }}-${{ hashFiles('composer.lock') }}"
199+
key: "composer-${{ runner.os }}-${{ matrix.php-version }}-${{ steps.vars.outputs.phpunit-version }}-${{ hashFiles('composer.json') }}"
103200

104201
- name: 'Restore consul ${{ env.CONSUL_VERSION }}'
105202
id: consul-cache
@@ -135,4 +232,4 @@ jobs:
135232
- name: 'Execute tests'
136233
# language=bash
137234
run: |
138-
./vendor/bin/phpunit -c phpunit.xml
235+
./vendor/bin/phpunit -c phpunit.xml --display-deprecations

.gitignore

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.idea/
2+
.junie/
3+
.php-cs-fixer.cache
4+
.php_cs.cache
5+
.phpunit.result.cache
16
/composer.phar
2-
/vendor/
3-
/.idea
4-
/*.iml
5-
/consul.log
6-
/.phpunit.result.cache
7-
.php_cs.cache
7+
vendor/
8+
*.iml
9+
consul.log

tools/php-cs-fixer/php-consul-api-rules.php_cs renamed to .php-cs-fixer.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1-
<?php declare(strict_types=1);
1+
<?php
22

3-
require_once __DIR__ . '/../../vendor/autoload.php';
3+
declare(strict_types=1);
4+
5+
require_once __DIR__ . '/tools/php-cs-fixer/vendor/autoload.php';
46

57
use AdamWojs\PhpCsFixerPhpdocForceFQCN\Fixer\Phpdoc\ForceFQCNFixer;
68
use PhpCsFixer\Config;
7-
use PhpCsFixer\RuleSet\Sets\PSR12RiskySet;
8-
use PhpCsFixer\RuleSet\Sets\PSR12Set;
9+
use PhpCsFixer\Finder;
910

1011
$config = new Config('php-consul-api');
1112

1213
$config
1314
->setUsingCache(false)
14-
->setRiskyAllowed(true)
15+
// ->setRiskyAllowed(true)
1516
->setLineEnding("\n")
1617
->setIndent(' ')
1718
->registerCustomFixers(
18-
[
19+
fixers: [
1920
new ForceFQCNFixer(),
2021
]
2122
)
23+
->setFinder(
24+
Finder::create()
25+
->in(__DIR__ . '/src')
26+
->name('*.php')
27+
)
2228
->setRules(
23-
(new PSR12Set())->getRules() +
24-
(new PSR12RiskySet())->getRules() +
2529
[
30+
'@PSR12' => true,
31+
// 'PSR12Risky',
32+
2633
// custom rules
2734

2835
'AdamWojs/phpdoc_force_fqcn_fixer' => true,

Makefile

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

0 commit comments

Comments
 (0)