Skip to content

Commit

Permalink
Merge pull request #102 from DoclerLabs/generator-php-8
Browse files Browse the repository at this point in the history
generator php 8
  • Loading branch information
vsouz4 authored Dec 19, 2023
2 parents 75e15df + ef9fdca commit 393bb25
Show file tree
Hide file tree
Showing 186 changed files with 3,849 additions and 2,281 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
tests:
runs-on: ubuntu-latest

name: Tests on PHP 7.4
name: Tests on PHP 8.2

steps:
- name: Checkout code
Expand All @@ -17,7 +17,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
tools: composer:v2
coverage: pcov

Expand Down
62 changes: 62 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

use PhpCsFixer\Config;

$rules = [
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'no_blank_lines_after_class_opening' => true,
'echo_tag_syntax' => ['format' => 'long'],
'no_unused_imports' => true,
'blank_line_after_opening_tag' => true,
'not_operator_with_successor_space' => false,
'no_useless_else' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'class_attributes_separation' => [
'elements' => [
'const' => 'one',
'method' => 'one',
'property' => 'one',
],
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'return', 'try'],
],
'no_alternative_syntax' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => ['align' => 'vertical'],
'phpdoc_indent' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_var_without_name' => true,
'phpdoc_to_comment' => false,
'phpdoc_scalar' => [
'types' => ['boolean', 'double', 'integer', 'real', 'str'],
],
'single_quote' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'no_leading_import_slash' => true,
'declare_strict_types' => true,
'single_line_after_imports' => true,
'not_operator_with_space' => false,
'no_spaces_inside_parenthesis' => true,
'unary_operator_spaces' => true,
'return_type_declaration' => ['space_before' => 'none'],
'braces' => ['allow_single_line_closure' => true],
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal']],
'no_superfluous_phpdoc_tags' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
];

return (new Config())
->setRiskyAllowed(true)
->setRules($rules)
->setIndent(' ')
->setUsingCache(false);
45 changes: 17 additions & 28 deletions .php_cs.php → .php-cs-fixer.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,58 @@
$rules = [
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'no_multiline_whitespace_before_semicolons' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'no_blank_lines_after_class_opening' => true,
'no_short_echo_tag' => true,
'echo_tag_syntax' => ['format' => 'long'],
'no_unused_imports' => true,
'blank_line_after_opening_tag' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_successor_space' => false,
'no_useless_else' => true,
'ordered_imports' => [
'sortAlgorithm' => 'alpha',
],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'class_attributes_separation' => [
'elements' => ['const', 'method', 'property'],
'elements' => [
'const' => 'one',
'method' => 'one',
'property' => 'one',
],
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'return', 'try'],
],
'no_alternative_syntax' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => [
'align' => 'vertical',
],
'phpdoc_align' => ['align' => 'vertical'],
'phpdoc_indent' => true,
'phpdoc_no_package' => true,
'phpdoc_order' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_var_without_name' => true,
'phpdoc_to_comment' => true,
'phpdoc_to_comment' => false,
'phpdoc_scalar' => [
'types' => ['boolean', 'double', 'integer', 'real', 'str'],
],
'single_quote' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'no_leading_import_slash' => true,
'declare_strict_types' => true,
'single_line_after_imports' => true,
'header_comment' => [
'header' => $header,
],
'header_comment' => ['header' => $header],
'not_operator_with_space' => false,
'no_spaces_inside_parenthesis' => true,
'unary_operator_spaces' => true,
'return_type_declaration' => [
'space_before' => 'none',
],
'native_function_invocation' => [
'include' => ['@all'],
],
'braces' => [
'allow_single_line_closure' => true,
],
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
],
'return_type_declaration' => ['space_before' => 'none'],
'braces' => ['allow_single_line_closure' => true],
'binary_operator_spaces' => ['operators' => ['=>' => 'align_single_space_minimal', '=' => 'align_single_space_minimal']],
'no_superfluous_phpdoc_tags' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
];

return Config::create()
return (new Config())
->setRiskyAllowed(true)
->setRules($rules)
->setIndent(' ')
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [10.4.0] - 2023.12.13
### Added
- Added generated code support for php 8.0
### Changed
- php-cs-fixer rules `not_operator_with_successor_space`, `phpdoc_to_comment`, `native_function_invocation`

## [10.3.0] - 2023.12.08
### Added
- Added support for multiple responses
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.4-cli-alpine3.13 as dependencies
FROM php:8.2-cli-alpine as dependencies

WORKDIR /dependencies

Expand All @@ -18,7 +18,7 @@ COPY composer.lock /dependencies
RUN composer install \
&& git config --global --add safe.directory /app

FROM php:7.4-cli-alpine3.13
FROM php:8.2-cli-alpine

ARG API_CLIENT_GENERATOR_VERSION
ENV API_CLIENT_GENERATOR_VERSION=$API_CLIENT_GENERATOR_VERSION
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cs: ## fix code style
docker-compose run php vendor/bin/php-cs-fixer fix .

stan: ## statically analyse code
docker-compose run php vendor/bin/phpstan analyse src
docker-compose run php vendor/bin/phpstan --memory-limit=1G analyse

coverage: ## coverage for pipeline
docker-compose run -e COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN} -e GITHUB_REF=${GITHUB_REF} -e GITHUB_ACTIONS=${GITHUB_ACTIONS} -e GITHUB_RUN_ID=${GITHUB_RUN_ID} -e GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME} php vendor/bin/php-coveralls -v
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ API client generator is a console application capable of auto-generating a [PSR1
## Why using it?
- With generated client you are always sure that your OpenAPI specification is up-to-date.
- Work with objects instead of raw data, it is OOP friendly.
- Saves your time. You don't need to write data mappers youself to populate those objects with the data from the response.
- Saves your time. You don't need to write data mappers yourself to populate those objects with the data from the response.
- All the basic type validations in the request and the response done automatically.
- Despite the fact the code is generated it's clear and readable, simple to debug and to reason about.
- Highly configurable and extensible.
Expand All @@ -27,7 +27,7 @@ API client generator is a console application capable of auto-generating a [PSR1
* application/json
* application/x-www-form-urlencoded
* application/xml
- Supports new PHP versions synthax features.
- Supports new PHP versions syntax features.
- It is base client independent, you are free to choose any [existing PSR-18 compliant client](https://packagist.org/providers/psr/http-client-implementation). Just choose the one which you already use, so generated client would not cause any conflicts with your dependencies. Although not recommended, you can also use or build your own PSR-18 implementation, as the generated client depends on PSR interfaces only.
- Applies code style rules to generated code, you can specify your own.
- Generates README and composer.json files with possibility to use your own template.
Expand Down Expand Up @@ -74,9 +74,9 @@ The following environment variables are available:
| `PACKAGE` | yes | | | group/some-api-client |
| `OPENAPI ` | yes | | | /api/openapi.yaml |
| `OUTPUT_DIR` | yes | | | /client |
| `CODE_STYLE` | no | {path-to-repository}/.php_cs.php | | /client/myCodeStyle.php |
| `CODE_STYLE` | no | {path-to-repository}/.php-cs-fixer.php.dist | | /client/myCodeStyle.php |
| `SOURCE_DIR` | no | src | | src |
| `CLIENT_PHP_VERSION` | no | 7.4 | 7.0, 7.1, 7.2, 7.3, 7.4 | 7.4 |
| `CLIENT_PHP_VERSION` | no | 7.4 | 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 | 7.4 |
| `COMPOSER_JSON_TEMPLATE_DIR` | no | {path-to-repository}/template/composer.json.twig | | /path/composer.json.twig |
| `README_MD_TEMPLATE_DIR` | no | {path-to-repository}/template/README.md.twig | | /path/README.md.twig |
| `HTTP_MESSAGE` | no | guzzle | guzzle, nyholm | nyholm |
Expand Down
8 changes: 4 additions & 4 deletions bin/api-client-generator
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

use DoclerLabs\ApiClientGenerator\Application;

require_once __DIR__ . '/../vendor/autoload.php';

$application = new Application();

return $application->run();
return (new Application())->run();
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"api-client-generator"
],
"require": {
"php": ">=7.4",
"php": ">=8.2",
"ext-dom": "*",
"ext-json": "*",
"ext-xml": "*",
"cebe/php-openapi": "^1.4",
"docler-labs/api-client-exception": "^1.0.1 || ^2.0",
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^3.0",
"guzzlehttp/psr7": "^1.6",
"icecave/parity": "^3.0",
"nikic/php-parser": "^4.10",
Expand All @@ -37,7 +37,7 @@
"composer/composer": "^2.1",
"mikey179/vfsstream": "^1.6",
"php-coveralls/php-coveralls": "^2.2",
"phpstan/phpstan": "^0.12.32",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-latest",
"symfony/filesystem": "^5.1"
Expand Down
Loading

0 comments on commit 393bb25

Please sign in to comment.