Skip to content

Commit d0b53fd

Browse files
authored
Merge pull request #131 from jolicode/php-cs-fixer
Update php-cs-fixer and its config and fix the codebase
2 parents e5f9685 + c21cedb commit d0b53fd

19 files changed

+67
-53
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ jobs:
2828
uses: actions/checkout@v2
2929

3030
- name: Install dependencies
31-
run: composer update --prefer-dist --no-interaction
31+
run: composer update --no-interaction
3232

33-
- name: Generate SDK in ci_generated directory
34-
run: CI_TEST=1 vendor/bin/jane-openapi generate --config-file=.jane-openapi.php
33+
- name: Regenerate SDK library
34+
run: rm -rf generated && vendor/bin/jane-openapi generate --config-file=.jane-openapi.php
3535

36-
- name: Fix CS on ci_generated directory
37-
run: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run ci_generated
38-
39-
- name: Check ci_generated and generated directories are equal
40-
run: diff ci_generated generated
36+
- name: Check is something changed
37+
run: |
38+
set -e
39+
git diff --exit-code
4140
4241
tests:
4342
name: Test PHP ${{ matrix.php-version }} ${{ matrix.name }}
@@ -63,7 +62,7 @@ jobs:
6362
extensions: mbstring, xml
6463

6564
- name: Install dependencies
66-
run: "composer update --prefer-dist --no-interaction ${{ matrix.composer-flags }}"
65+
run: "composer update --no-interaction ${{ matrix.composer-flags }}"
6766

6867
- name: Run tests
6968
run: php vendor/bin/simple-phpunit

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ composer.lock
66
composer.phar
77

88
# CS
9-
.php_cs.cache
109
.php-cs-fixer.cache
1110

1211
# tests

.jane-openapi.php

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

3-
$directory = __DIR__ . '/generated/';
4-
5-
if (!empty($_SERVER['CI_TEST'])) {
6-
$directory = __DIR__ . '/ci_generated/';
7-
}
8-
93
return [
104
'openapi-file' => __DIR__ . '/resources/slack-openapi-patched.json',
115
'namespace' => 'JoliCode\Slack\Api',
12-
'directory' => $directory,
6+
'directory' => __DIR__ . '/generated/',
137
'reference' => true,
148
'strict' => false,
159
'clean-generated' => true,

.php-cs-fixer.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
<?php
22

3-
$header = <<<'EOF'
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of JoliCode's Slack PHP API project.
7+
*
8+
* (c) JoliCode <coucou@jolicode.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
$fileHeaderComment = <<<'EOF'
415
This file is part of JoliCode's Slack PHP API project.
516
617
(c) JoliCode <coucou@jolicode.com>
@@ -13,18 +24,26 @@
1324
->in(__DIR__)
1425
->exclude('docs')
1526
->exclude('ci_generated')
27+
->append([
28+
__FILE__,
29+
])
1630
;
17-
$config = new PhpCsFixer\Config();
1831

19-
return $config->setRules([
32+
return (new PhpCsFixer\Config())
33+
->setRiskyAllowed(true)
34+
->setRules([
35+
'@PHP71Migration' => true,
36+
'@PhpCsFixer' => true,
2037
'@Symfony' => true,
2138
'@Symfony:risky' => true,
22-
'@PHP71Migration' => true,
23-
'@PHP71Migration:risky' => true,
24-
'header_comment' => array('header' => $header),
25-
'strict_param' => true,
26-
'array_syntax' => ['syntax' => 'short'],
39+
'php_unit_internal_class' => false, // From @PhpCsFixer but we don't want it
40+
'php_unit_test_class_requires_covers' => false, // From @PhpCsFixer but we don't want it
41+
'phpdoc_add_missing_param_annotation' => false, // From @PhpCsFixer but we don't want it
42+
'header_comment' => ['header' => $fileHeaderComment],
43+
'concat_space' => ['spacing' => 'one'],
44+
'declare_strict_types' => true,
45+
'ordered_class_elements' => true, // Symfony(PSR12) override the default value, but we don't want
46+
'blank_line_before_statement' => true, // Symfony(PSR12) override the default value, but we don't want
2747
])
28-
->setRiskyAllowed(true)
2948
->setFinder($finder)
3049
;

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"jane-php/open-api-2": "~6.3.0",
3838
"symfony/http-client": "^4.3.3 || ^5.1",
3939
"nyholm/psr7": "^1.2",
40-
"friendsofphp/php-cs-fixer": "^3.0",
40+
"friendsofphp/php-cs-fixer": "^3.2.2",
4141
"symfony/phpunit-bridge": "^5.2",
4242
"opis/json-schema": "^1.0",
4343
"symfony/console": "^5.1",

generated/Runtime/Client/BaseEndpoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function getMultipartBody($streamFactory = null): array
7878
$bodyBuilder->addResource($key, $value);
7979
}
8080

81-
return [['Content-Type' => ['multipart/form-data; boundary="'.($bodyBuilder->getBoundary().'"')]], $bodyBuilder->build()];
81+
return [['Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '"')]], $bodyBuilder->build()];
8282
}
8383

8484
protected function getFormOptionsResolver(): OptionsResolver

generated/Runtime/Client/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ public function executeEndpoint(Endpoint $endpoint, string $fetch = self::FETCH_
5454
[$bodyHeaders, $body] = $endpoint->getBody($this->serializer, $this->streamFactory);
5555
$queryString = $endpoint->getQueryString();
5656
$uriGlue = false === strpos($endpoint->getUri(), '?') ? '?' : '&';
57-
$uri = '' !== $queryString ? $endpoint->getUri().$uriGlue.$queryString : $endpoint->getUri();
57+
$uri = '' !== $queryString ? $endpoint->getUri() . $uriGlue . $queryString : $endpoint->getUri();
5858
$request = $this->requestFactory->createRequest($endpoint->getMethod(), $uri);
5959
if ($body) {
6060
if ($body instanceof StreamInterface) {
6161
$request = $request->withBody($body);
6262
} elseif (\is_resource($body)) {
6363
$request = $request->withBody($this->streamFactory->createStreamFromResource($body));
64-
} elseif (\strlen($body) <= 4000 && is_file($body)) {
64+
} elseif (\strlen($body) <= 4000 && @file_exists($body)) {
6565
// more than 4096 chars will trigger an error
6666
$request = $request->withBody($this->streamFactory->createStreamFromFile($body));
6767
} else {

generated/Runtime/Client/Endpoint.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ interface Endpoint
2323
*
2424
* Return value consist of an array where the first item will be a list of headers to add on the request (like the Content Type)
2525
* And the second value consist of the body object.
26-
*
27-
* @param mixed|null $streamFactory
2826
*/
2927
public function getBody(SerializerInterface $serializer, $streamFactory = null): array;
3028

generated/Runtime/Client/EndpointTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function parseResponse(ResponseInterface $response, SerializerInterface $
2929
if (Client::FETCH_RESPONSE === $fetchMode) {
3030
return $response;
3131
}
32+
3233
throw new InvalidFetchModeException(sprintf('Fetch mode %s is not supported', $fetchMode));
3334
}
3435

src/Checker/JsonSorter.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function recursiveAlphabeticalSort($item)
3434
}
3535

3636
foreach ($asArray as $key => $subItem) {
37-
$asArray[$key] = $this->recursiveAlphabeticalSort($item->$key);
37+
$asArray[$key] = $this->recursiveAlphabeticalSort($item->{$key});
3838

3939
if ('parameters' === $key) {
4040
usort($asArray['parameters'], function ($a, $b) {
41-
return (isset($a['name']) && isset($b['name']) && $a['name'] > $b['name']) ? 1 : 0;
41+
return (isset($a['name'], $b['name']) && $a['name'] > $b['name']) ? 1 : 0;
4242
});
4343
}
4444
}
@@ -47,7 +47,8 @@ public function recursiveAlphabeticalSort($item)
4747
ksort($item, \SORT_STRING);
4848

4949
return $item;
50-
} elseif (!\is_array($item)) {
50+
}
51+
if (!\is_array($item)) {
5152
return $item;
5253
}
5354

@@ -97,10 +98,10 @@ private function mergeNodeItems($items)
9798
private function union($cargo, $addition)
9899
{
99100
foreach ($addition as $key => $value) {
100-
if (isset($cargo->$key) && \is_object($cargo->$key)) {
101-
$cargo->$key = $this->union($cargo->$key, $value);
101+
if (isset($cargo->{$key}) && \is_object($cargo->{$key})) {
102+
$cargo->{$key} = $this->union($cargo->{$key}, $value);
102103
} else {
103-
$cargo->$key = $value;
104+
$cargo->{$key} = $value;
104105
}
105106
}
106107

0 commit comments

Comments
 (0)