diff --git a/docs/generators/php-slim.md b/docs/generators/php-slim.md index 629056bb928a..ee452b57fa20 100644 --- a/docs/generators/php-slim.md +++ b/docs/generators/php-slim.md @@ -40,7 +40,4 @@ CONFIG OPTIONS for php-slim artifactVersion The version to use in the composer package version field. e.g. 1.2.3 - phpcsStandard - PHP CodeSniffer option. Accepts name or path of the coding standard to use. (Default: PSR12) - Back to the [generators list](README.md) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java index 3ff9aad4eaac..d8480e4cc9e8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java @@ -35,12 +35,10 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class); - public static final String PHPCS_STANDARD = "phpcsStandard"; public static final String USER_CLASSNAME_KEY = "userClassname"; protected String groupId = "org.openapitools"; protected String artifactId = "openapi-server"; - protected String phpcsStandard = "PSR12"; public PhpSlimServerCodegen() { super(); @@ -74,9 +72,6 @@ public PhpSlimServerCodegen() { break; } } - - cliOptions.add(new CliOption(PHPCS_STANDARD, "PHP CodeSniffer option. Accepts name or path of the coding standard to use.") - .defaultValue("PSR12")); } @Override @@ -116,18 +111,13 @@ public String modelFileFolder() { public void processOpts() { super.processOpts(); - if (additionalProperties.containsKey(PHPCS_STANDARD)) { - this.setPhpcsStandard((String) additionalProperties.get(PHPCS_STANDARD)); - } else { - additionalProperties.put(PHPCS_STANDARD, phpcsStandard); - } - supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json")); supportingFiles.add(new SupportingFile("index.mustache", "", "index.php")); supportingFiles.add(new SupportingFile(".htaccess", "", ".htaccess")); supportingFiles.add(new SupportingFile("SlimRouter.mustache", toSrcPath(invokerPackage, srcBasePath), "SlimRouter.php")); supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist")); + supportingFiles.add(new SupportingFile("phpcs.xml.mustache", "", "phpcs.xml.dist")); } @Override @@ -161,15 +151,6 @@ public int compare(CodegenOperation one, CodegenOperation another) { return objs; } - /** - * Sets PHP CodeSniffer <standard> option. Accepts name or path of the coding standard to use. - * - * @param phpcsStandard standard option value - */ - public void setPhpcsStandard(String phpcsStandard) { - this.phpcsStandard = phpcsStandard; - } - @Override public String toApiName(String name) { if (name.length() == 0) { diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/.gitignore b/modules/openapi-generator/src/main/resources/php-slim-server/.gitignore index cd37c4a9b990..db204792ea34 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/.gitignore +++ b/modules/openapi-generator/src/main/resources/php-slim-server/.gitignore @@ -8,4 +8,10 @@ composer.phar # composer.lock # phplint tool creates cache file which is not necessary in a codebase -/.phplint-cache \ No newline at end of file +/.phplint-cache + +# Do not commit local PHPUnit config +/phpunit.xml + +# Do not commit local PHP_CodeSniffer config +/phpcs.xml \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache index 389484693fab..1620492e5e25 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache @@ -28,21 +28,54 @@ $ php -S localhost:8888 -t php-slim-server > It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. > It is not intended to be a full-featured web server. It should not be used on a public network. -## Run tests +## Tests -This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing and PHP Codesniffer to check source code against user defined coding standard(`phpcsStandard` generator config option). +### PHPUnit + +This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing. [Test folder]({{testBasePath}}) contains templates which you can fill with real test assertions. How to write tests read at [PHPUnit Manual - Chapter 2. Writing Tests for PHPUnit](https://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html). -How to configure PHP CodeSniffer read at [PHP CodeSniffer Documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki). -There is [phplint](https://github.com/overtrue/phplint) tool to check php syntax automatically. - -Command | Tool | Target ----- | ---- | ---- -`$ composer test` | PHPUnit | All tests -`$ composer run test-apis` | PHPUnit | Apis tests -`$ composer run test-models` | PHPUnit | Models tests -`$ composer run phpcs` | PHP CodeSniffer | All files -`$ composer run phplint` | phplint | All files + +#### Run + +Command | Target +---- | ---- +`$ composer test` | All tests +`$ composer test-apis` | Apis tests +`$ composer test-models` | Models tests + +#### Config + +Package contains fully functional config `./phpunit.xml.dist` file. Create `./phpunit.xml` in root folder to override it. + +Quote from [3. The Command-Line Test Runner — PHPUnit 7.4 Manual](https://phpunit.readthedocs.io/en/7.4/textui.html#command-line-options): + +> If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file. + +### PHP CodeSniffer + +[PHP CodeSniffer Documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki). This tool helps to follow coding style and avoid common PHP coding mistakes. + +#### Run + +```bash +$ composer phpcs +``` + +#### Config + +Package contains fully functional config `./phpcs.xml.dist` file. It checks source code against PSR-1 and PSR-2 coding standards. +Create `./phpcs.xml` in root folder to override it. More info at [Using a Default Configuration File](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) + +### PHPLint + +[PHPLint Documentation](https://github.com/overtrue/phplint). Checks PHP syntax only. + +#### Run + +```bash +$ composer phplint +``` ## Show errors diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/composer.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/composer.mustache index 6f23f467e299..8dfeed44a846 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/composer.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim-server/composer.mustache @@ -26,7 +26,7 @@ ], "test-apis": "phpunit --testsuite Apis", "test-models": "phpunit --testsuite Models", - "phpcs": "phpcs ./ --ignore=vendor --warning-severity=0 --standard={{phpcsStandard}}", + "phpcs": "phpcs", "phplint": "phplint ./ --exclude=vendor" } } diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/phpcs.xml.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/phpcs.xml.mustache new file mode 100644 index 000000000000..024e5f3371f2 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/php-slim-server/phpcs.xml.mustache @@ -0,0 +1,31 @@ + + + PHP_CodeSniffer config for {{appName}} + + + ./ + + + ./vendor + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PhpSlimServerOptionsProvider.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PhpSlimServerOptionsProvider.java index 39186e7b0515..c170e2ff5776 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PhpSlimServerOptionsProvider.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/options/PhpSlimServerOptionsProvider.java @@ -19,7 +19,6 @@ import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.languages.AbstractPhpCodegen; -import org.openapitools.codegen.languages.PhpSlimServerCodegen; import com.google.common.collect.ImmutableMap; @@ -39,7 +38,6 @@ public class PhpSlimServerOptionsProvider implements OptionsProvider { public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true"; public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false"; public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true"; - public static final String PHPCS_STANDARD_VALUE = "PSR12"; @Override public String getLanguage() { @@ -62,7 +60,6 @@ public Map createOptions() { .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) .put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE) .put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE) - .put(PhpSlimServerCodegen.PHPCS_STANDARD, PHPCS_STANDARD_VALUE) .build(); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/slim/PhpSlimServerOptionsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/slim/PhpSlimServerOptionsTest.java index 57a87adaf3f2..25cd43077aa0 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/slim/PhpSlimServerOptionsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/slim/PhpSlimServerOptionsTest.java @@ -63,8 +63,6 @@ protected void setExpectations() { times = 1; clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(PhpSlimServerOptionsProvider.SORT_PARAMS_VALUE)); times = 1; - clientCodegen.setPhpcsStandard(PhpSlimServerOptionsProvider.PHPCS_STANDARD_VALUE); - times = 1; }}; } } diff --git a/samples/server/petstore-security-test/php-slim/.gitignore b/samples/server/petstore-security-test/php-slim/.gitignore index cd37c4a9b990..db204792ea34 100644 --- a/samples/server/petstore-security-test/php-slim/.gitignore +++ b/samples/server/petstore-security-test/php-slim/.gitignore @@ -8,4 +8,10 @@ composer.phar # composer.lock # phplint tool creates cache file which is not necessary in a codebase -/.phplint-cache \ No newline at end of file +/.phplint-cache + +# Do not commit local PHPUnit config +/phpunit.xml + +# Do not commit local PHP_CodeSniffer config +/phpcs.xml \ No newline at end of file diff --git a/samples/server/petstore-security-test/php-slim/README.md b/samples/server/petstore-security-test/php-slim/README.md index 31a73e777ea8..b1820697b66c 100644 --- a/samples/server/petstore-security-test/php-slim/README.md +++ b/samples/server/petstore-security-test/php-slim/README.md @@ -28,21 +28,54 @@ $ php -S localhost:8888 -t php-slim-server > It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. > It is not intended to be a full-featured web server. It should not be used on a public network. -## Run tests +## Tests -This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing and PHP Codesniffer to check source code against user defined coding standard(`phpcsStandard` generator config option). +### PHPUnit + +This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing. [Test folder](test) contains templates which you can fill with real test assertions. How to write tests read at [PHPUnit Manual - Chapter 2. Writing Tests for PHPUnit](https://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html). -How to configure PHP CodeSniffer read at [PHP CodeSniffer Documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki). -There is [phplint](https://github.com/overtrue/phplint) tool to check php syntax automatically. - -Command | Tool | Target ----- | ---- | ---- -`$ composer test` | PHPUnit | All tests -`$ composer run test-apis` | PHPUnit | Apis tests -`$ composer run test-models` | PHPUnit | Models tests -`$ composer run phpcs` | PHP CodeSniffer | All files -`$ composer run phplint` | phplint | All files + +#### Run + +Command | Target +---- | ---- +`$ composer test` | All tests +`$ composer test-apis` | Apis tests +`$ composer test-models` | Models tests + +#### Config + +Package contains fully functional config `./phpunit.xml.dist` file. Create `./phpunit.xml` in root folder to override it. + +Quote from [3. The Command-Line Test Runner — PHPUnit 7.4 Manual](https://phpunit.readthedocs.io/en/7.4/textui.html#command-line-options): + +> If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file. + +### PHP CodeSniffer + +[PHP CodeSniffer Documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki). This tool helps to follow coding style and avoid common PHP coding mistakes. + +#### Run + +```bash +$ composer phpcs +``` + +#### Config + +Package contains fully functional config `./phpcs.xml.dist` file. It checks source code against PSR-1 and PSR-2 coding standards. +Create `./phpcs.xml` in root folder to override it. More info at [Using a Default Configuration File](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) + +### PHPLint + +[PHPLint Documentation](https://github.com/overtrue/phplint). Checks PHP syntax only. + +#### Run + +```bash +$ composer phplint +``` ## Show errors diff --git a/samples/server/petstore-security-test/php-slim/composer.json b/samples/server/petstore-security-test/php-slim/composer.json index 5b4e586c7c8c..9c1a1d936ca3 100644 --- a/samples/server/petstore-security-test/php-slim/composer.json +++ b/samples/server/petstore-security-test/php-slim/composer.json @@ -26,7 +26,7 @@ ], "test-apis": "phpunit --testsuite Apis", "test-models": "phpunit --testsuite Models", - "phpcs": "phpcs ./ --ignore=vendor --warning-severity=0 --standard=PSR12", + "phpcs": "phpcs", "phplint": "phplint ./ --exclude=vendor" } } diff --git a/samples/server/petstore-security-test/php-slim/phpcs.xml.dist b/samples/server/petstore-security-test/php-slim/phpcs.xml.dist new file mode 100644 index 000000000000..744c14c40a4a --- /dev/null +++ b/samples/server/petstore-security-test/php-slim/phpcs.xml.dist @@ -0,0 +1,31 @@ + + + PHP_CodeSniffer config for OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + + + ./ + + + ./vendor + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/server/petstore/php-slim/.gitignore b/samples/server/petstore/php-slim/.gitignore index cd37c4a9b990..db204792ea34 100644 --- a/samples/server/petstore/php-slim/.gitignore +++ b/samples/server/petstore/php-slim/.gitignore @@ -8,4 +8,10 @@ composer.phar # composer.lock # phplint tool creates cache file which is not necessary in a codebase -/.phplint-cache \ No newline at end of file +/.phplint-cache + +# Do not commit local PHPUnit config +/phpunit.xml + +# Do not commit local PHP_CodeSniffer config +/phpcs.xml \ No newline at end of file diff --git a/samples/server/petstore/php-slim/README.md b/samples/server/petstore/php-slim/README.md index 00e100cca4fa..6930213b7d47 100644 --- a/samples/server/petstore/php-slim/README.md +++ b/samples/server/petstore/php-slim/README.md @@ -28,21 +28,54 @@ $ php -S localhost:8888 -t php-slim-server > It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. > It is not intended to be a full-featured web server. It should not be used on a public network. -## Run tests +## Tests -This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing and PHP Codesniffer to check source code against user defined coding standard(`phpcsStandard` generator config option). +### PHPUnit + +This package uses PHPUnit 6 or 7(depends from your PHP version) for unit testing. [Test folder](test) contains templates which you can fill with real test assertions. How to write tests read at [PHPUnit Manual - Chapter 2. Writing Tests for PHPUnit](https://phpunit.de/manual/6.5/en/writing-tests-for-phpunit.html). -How to configure PHP CodeSniffer read at [PHP CodeSniffer Documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki). -There is [phplint](https://github.com/overtrue/phplint) tool to check php syntax automatically. - -Command | Tool | Target ----- | ---- | ---- -`$ composer test` | PHPUnit | All tests -`$ composer run test-apis` | PHPUnit | Apis tests -`$ composer run test-models` | PHPUnit | Models tests -`$ composer run phpcs` | PHP CodeSniffer | All files -`$ composer run phplint` | phplint | All files + +#### Run + +Command | Target +---- | ---- +`$ composer test` | All tests +`$ composer test-apis` | Apis tests +`$ composer test-models` | Models tests + +#### Config + +Package contains fully functional config `./phpunit.xml.dist` file. Create `./phpunit.xml` in root folder to override it. + +Quote from [3. The Command-Line Test Runner — PHPUnit 7.4 Manual](https://phpunit.readthedocs.io/en/7.4/textui.html#command-line-options): + +> If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file. + +### PHP CodeSniffer + +[PHP CodeSniffer Documentation](https://github.com/squizlabs/PHP_CodeSniffer/wiki). This tool helps to follow coding style and avoid common PHP coding mistakes. + +#### Run + +```bash +$ composer phpcs +``` + +#### Config + +Package contains fully functional config `./phpcs.xml.dist` file. It checks source code against PSR-1 and PSR-2 coding standards. +Create `./phpcs.xml` in root folder to override it. More info at [Using a Default Configuration File](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) + +### PHPLint + +[PHPLint Documentation](https://github.com/overtrue/phplint). Checks PHP syntax only. + +#### Run + +```bash +$ composer phplint +``` ## Show errors diff --git a/samples/server/petstore/php-slim/composer.json b/samples/server/petstore/php-slim/composer.json index 5b4e586c7c8c..9c1a1d936ca3 100644 --- a/samples/server/petstore/php-slim/composer.json +++ b/samples/server/petstore/php-slim/composer.json @@ -26,7 +26,7 @@ ], "test-apis": "phpunit --testsuite Apis", "test-models": "phpunit --testsuite Models", - "phpcs": "phpcs ./ --ignore=vendor --warning-severity=0 --standard=PSR12", + "phpcs": "phpcs", "phplint": "phplint ./ --exclude=vendor" } } diff --git a/samples/server/petstore/php-slim/phpcs.xml.dist b/samples/server/petstore/php-slim/phpcs.xml.dist new file mode 100644 index 000000000000..69f4ddac71c3 --- /dev/null +++ b/samples/server/petstore/php-slim/phpcs.xml.dist @@ -0,0 +1,31 @@ + + + PHP_CodeSniffer config for OpenAPI Petstore + + + ./ + + + ./vendor + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file