[php] Add PSR-12 rule set (#12302)

* Upgrade PHPCS-Fixer to 3.5 version

This version requires PHP 7.4 or 8.0 which perfectly meets our supported
PHP right now.

* Rename config file to .php-cs-fixer.dist.php

This way it can be overwritten with local file(same name without "dist"
part). Also it's recommended filename from the package doc.

* Add PSR12 rule set to config

I've changed config file a bit to look like example from the doc.
Ref: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/HEAD/doc/config.rst

* Ignore new cache format

* Remove blank line after class opening

* Set constants in models public

* Refresh samples
This commit is contained in:
Yuriy Belenko 2022-05-09 19:34:38 +03:00 committed by GitHub
parent 8d4c9e2472
commit e639dad66a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 105 additions and 72 deletions

View File

@ -108,7 +108,7 @@ public class PhpClientCodegen extends AbstractPhpCodegen {
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile(".php_cs", "", ".php_cs"));
supportingFiles.add(new SupportingFile(".php-cs-fixer.dist.php", "", ".php-cs-fixer.dist.php"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* @generated
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/HEAD/doc/config.rst
*/
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('test')
->exclude('tests')
;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'phpdoc_order' => true,
'array_syntax' => [ 'syntax' => 'short' ],
'strict_comparison' => true,
'strict_param' => true,
'no_trailing_whitespace' => false,
'no_trailing_whitespace_in_comment' => false,
'braces' => false,
'single_blank_line_at_eof' => false,
'blank_line_after_namespace' => false,
'no_leading_import_slash' => false,
])
->setFinder($finder)
;

View File

@ -1,23 +0,0 @@
<?php
return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'@PSR2' => true,
'ordered_imports' => true,
'phpdoc_order' => true,
'array_syntax' => [ 'syntax' => 'short' ],
'strict_comparison' => true,
'strict_param' => true,
'no_trailing_whitespace' => false,
'no_trailing_whitespace_in_comment' => false,
'braces' => false,
'single_blank_line_at_eof' => false,
'blank_line_after_namespace' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('test')
->exclude('tests')
->in(__DIR__)
);

View File

@ -30,7 +30,6 @@ use \Exception;
*/
class ApiException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*

View File

@ -30,7 +30,6 @@ use \Exception;
*/
class HeaderSelector
{
/**
* @param string[] $accept
* @param string[] $contentTypes

View File

@ -33,7 +33,7 @@
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^2.12"
"friendsofphp/php-cs-fixer": "^3.5"
},
"autoload": {
"psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" }

View File

@ -9,6 +9,7 @@ composer.phar
# php-cs-fixer cache
.php_cs.cache
.php-cs-fixer.cache
# PHPUnit cache
.phpunit.result.cache

View File

@ -5,7 +5,7 @@ class {{classname}}
*/
{{#allowableValues}}
{{#enumVars}}
const {{^isString}}NUMBER_{{/isString}}{{{name}}} = {{{value}}};
public const {{^isString}}NUMBER_{{/isString}}{{{name}}} = {{{value}}};
{{/enumVars}}
{{/allowableValues}}

View File

@ -127,7 +127,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
{{#isEnum}}
{{#allowableValues}}
{{#enumVars}}
const {{enumName}}_{{{name}}} = {{{value}}};
public const {{enumName}}_{{{name}}} = {{{value}}};
{{/enumVars}}
{{/allowableValues}}
{{/isEnum}}

View File

@ -9,6 +9,7 @@ composer.phar
# php-cs-fixer cache
.php_cs.cache
.php-cs-fixer.cache
# PHPUnit cache
.phpunit.result.cache

View File

@ -1,5 +1,5 @@
.gitignore
.php_cs
.php-cs-fixer.dist.php
.travis.yml
README.md
composer.json

View File

@ -0,0 +1,29 @@
<?php
/**
* @generated
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/HEAD/doc/config.rst
*/
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('vendor')
->exclude('test')
->exclude('tests')
;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'phpdoc_order' => true,
'array_syntax' => [ 'syntax' => 'short' ],
'strict_comparison' => true,
'strict_param' => true,
'no_trailing_whitespace' => false,
'no_trailing_whitespace_in_comment' => false,
'braces' => false,
'single_blank_line_at_eof' => false,
'blank_line_after_namespace' => false,
'no_leading_import_slash' => false,
])
->setFinder($finder)
;

View File

@ -27,7 +27,7 @@
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^2.12"
"friendsofphp/php-cs-fixer": "^3.5"
},
"autoload": {
"psr-4": { "OpenAPI\\Client\\" : "lib/" }

View File

@ -39,7 +39,6 @@ use \Exception;
*/
class ApiException extends Exception
{
/**
* The HTTP body of the server response either as Json or string.
*

View File

@ -39,7 +39,6 @@ use \Exception;
*/
class HeaderSelector
{
/**
* @param string[] $accept
* @param string[] $contentTypes

View File

@ -167,10 +167,10 @@ class EnumArrays implements ModelInterface, ArrayAccess, \JsonSerializable
return self::$openAPIModelName;
}
const JUST_SYMBOL_GREATER_THAN_OR_EQUAL_TO = '>=';
const JUST_SYMBOL_DOLLAR = '$';
const ARRAY_ENUM_FISH = 'fish';
const ARRAY_ENUM_CRAB = 'crab';
public const JUST_SYMBOL_GREATER_THAN_OR_EQUAL_TO = '>=';
public const JUST_SYMBOL_DOLLAR = '$';
public const ARRAY_ENUM_FISH = 'fish';
public const ARRAY_ENUM_CRAB = 'crab';
/**
* Gets allowable values of the enum

View File

@ -42,11 +42,11 @@ class EnumClass
/**
* Possible values of this enum
*/
const ABC = '_abc';
public const ABC = '_abc';
const EFG = '-efg';
public const EFG = '-efg';
const XYZ = '(xyz)';
public const XYZ = '(xyz)';
/**
* Gets allowable values of the enum

View File

@ -197,16 +197,16 @@ class EnumTest implements ModelInterface, ArrayAccess, \JsonSerializable
return self::$openAPIModelName;
}
const ENUM_STRING_UPPER = 'UPPER';
const ENUM_STRING_LOWER = 'lower';
const ENUM_STRING_EMPTY = '';
const ENUM_STRING_REQUIRED_UPPER = 'UPPER';
const ENUM_STRING_REQUIRED_LOWER = 'lower';
const ENUM_STRING_REQUIRED_EMPTY = '';
const ENUM_INTEGER_1 = 1;
const ENUM_INTEGER_MINUS_1 = -1;
const ENUM_NUMBER_1_DOT_1 = 1.1;
const ENUM_NUMBER_MINUS_1_DOT_2 = -1.2;
public const ENUM_STRING_UPPER = 'UPPER';
public const ENUM_STRING_LOWER = 'lower';
public const ENUM_STRING_EMPTY = '';
public const ENUM_STRING_REQUIRED_UPPER = 'UPPER';
public const ENUM_STRING_REQUIRED_LOWER = 'lower';
public const ENUM_STRING_REQUIRED_EMPTY = '';
public const ENUM_INTEGER_1 = 1;
public const ENUM_INTEGER_MINUS_1 = -1;
public const ENUM_NUMBER_1_DOT_1 = 1.1;
public const ENUM_NUMBER_MINUS_1_DOT_2 = -1.2;
/**
* Gets allowable values of the enum

View File

@ -177,8 +177,8 @@ class MapTest implements ModelInterface, ArrayAccess, \JsonSerializable
return self::$openAPIModelName;
}
const MAP_OF_ENUM_STRING_UPPER = 'UPPER';
const MAP_OF_ENUM_STRING_LOWER = 'lower';
public const MAP_OF_ENUM_STRING_UPPER = 'UPPER';
public const MAP_OF_ENUM_STRING_LOWER = 'lower';
/**
* Gets allowable values of the enum

View File

@ -187,9 +187,9 @@ class Order implements ModelInterface, ArrayAccess, \JsonSerializable
return self::$openAPIModelName;
}
const STATUS_PLACED = 'placed';
const STATUS_APPROVED = 'approved';
const STATUS_DELIVERED = 'delivered';
public const STATUS_PLACED = 'placed';
public const STATUS_APPROVED = 'approved';
public const STATUS_DELIVERED = 'delivered';
/**
* Gets allowable values of the enum

View File

@ -42,11 +42,11 @@ class OuterEnum
/**
* Possible values of this enum
*/
const PLACED = 'placed';
public const PLACED = 'placed';
const APPROVED = 'approved';
public const APPROVED = 'approved';
const DELIVERED = 'delivered';
public const DELIVERED = 'delivered';
/**
* Gets allowable values of the enum

View File

@ -42,11 +42,11 @@ class OuterEnumDefaultValue
/**
* Possible values of this enum
*/
const PLACED = 'placed';
public const PLACED = 'placed';
const APPROVED = 'approved';
public const APPROVED = 'approved';
const DELIVERED = 'delivered';
public const DELIVERED = 'delivered';
/**
* Gets allowable values of the enum

View File

@ -42,11 +42,11 @@ class OuterEnumInteger
/**
* Possible values of this enum
*/
const NUMBER_0 = 0;
public const NUMBER_0 = 0;
const NUMBER_1 = 1;
public const NUMBER_1 = 1;
const NUMBER_2 = 2;
public const NUMBER_2 = 2;
/**
* Gets allowable values of the enum

View File

@ -42,11 +42,11 @@ class OuterEnumIntegerDefaultValue
/**
* Possible values of this enum
*/
const NUMBER_0 = 0;
public const NUMBER_0 = 0;
const NUMBER_1 = 1;
public const NUMBER_1 = 1;
const NUMBER_2 = 2;
public const NUMBER_2 = 2;
/**
* Gets allowable values of the enum

View File

@ -187,9 +187,9 @@ class Pet implements ModelInterface, ArrayAccess, \JsonSerializable
return self::$openAPIModelName;
}
const STATUS_AVAILABLE = 'available';
const STATUS_PENDING = 'pending';
const STATUS_SOLD = 'sold';
public const STATUS_AVAILABLE = 'available';
public const STATUS_PENDING = 'pending';
public const STATUS_SOLD = 'sold';
/**
* Gets allowable values of the enum

View File

@ -42,9 +42,9 @@ class SingleRefType
/**
* Possible values of this enum
*/
const ADMIN = 'admin';
public const ADMIN = 'admin';
const USER = 'user';
public const USER = 'user';
/**
* Gets allowable values of the enum