From e9d01e3c3ff294f15e2311cf89a92bdfb39c3256 Mon Sep 17 00:00:00 2001 From: Ms_Natali Date: Tue, 28 May 2024 15:28:37 +0300 Subject: [PATCH 1/3] ENSITECH-74 --- .../post-checkout/01-install-dependencies.sh | 1 + .../post-merge/01-install-dependencies.sh | 1 + .git_hooks/post-merge/install-dependencies.sh | 21 ------- .git_hooks/pre-commit/01-lint-php.sh | 1 + .git_hooks/pre-commit/02-php-cs-fixer.sh | 1 + .git_hooks/pre-push/01-composer-validate.sh | 1 + .git_hooks/pre-push/02-phpstan.sh | 1 + .git_hooks/pre-push/03-test-code.sh | 1 + .git_hooks/pre-push/var-dump-checker.sh | 23 ------- .../composer-validate.sh | 2 +- .../install-dependencies.sh | 7 +-- .../{pre-commit => scripts}/lint-php.sh | 2 +- .../{pre-commit => scripts}/php-cs-fixer.sh | 2 +- .git_hooks/scripts/phpstan.sh | 20 ++++++ .git_hooks/scripts/test-code.sh | 20 ++++++ .github/CONTRIBUTING.md | 53 ++++++++++++++++ .github/SECURITY.md | 3 + .github/workflows/php-cs-fixer.yml | 23 +++++++ .github/workflows/run-tests.yml | 51 ++++++++++++++++ .gitignore | 28 +++++---- .php-cs-fixer.php | 7 ++- README.md | 41 ++++++++++--- composer.json | 28 +++++++-- phpstan-package.neon | 0 phpstan.neon.dist | 61 +++++++++++++++++++ phpunit.xml | 20 ++++++ {lib => src}/Api/BaseApi.php | 2 +- {lib => src}/Api/SuggestionsApi.php | 0 {lib => src}/ApiException.php | 0 {lib => src}/Configuration.php | 2 +- {lib => src}/DaDataClientProvider.php | 0 {lib => src}/DaDataHostEnum.php | 0 {lib => src}/Dto/BaseBodyDto.php | 0 {lib => src}/Dto/BaseDto.php | 2 +- {lib => src}/Dto/BaseQueryDto.php | 0 {lib => src}/Dto/BaseRequestDto.php | 0 {lib => src}/Dto/BaseResponseDto.php | 0 .../Dto/Suggestions/Data/BoundData.php | 0 .../Suggestions/Data/LocationBoostData.php | 0 .../Dto/Suggestions/Data/LocationData.php | 0 .../Dto/Suggestions/Data/LocationGeoData.php | 0 .../Dto/Suggestions/Data/MetroDto.php | 0 .../Data/SuggestionAddressData.php | 0 .../Dto/Suggestions/Data/SuggestionData.php | 0 .../Dto/Suggestions/Enums/BoundEnum.php | 0 .../Suggestions/Enums/CapitalMarkerEnum.php | 4 +- .../Dto/Suggestions/Enums/DivisionEnum.php | 0 .../Dto/Suggestions/Enums/FiasLevelEnum.php | 0 .../Dto/Suggestions/Enums/LanguageEnum.php | 0 .../Dto/Suggestions/Enums/QCGeoEnum.php | 0 .../Requests/SearchSuggestionsRequest.php | 0 .../Responses/SearchSuggestionsResponse.php | 0 {lib => src}/RequestBuilder.php | 0 tests/ExampleTest.php | 5 ++ tests/Pest.php | 48 +++++++++++++++ tests/TestCase.php | 9 +++ 56 files changed, 405 insertions(+), 86 deletions(-) create mode 120000 .git_hooks/post-checkout/01-install-dependencies.sh create mode 120000 .git_hooks/post-merge/01-install-dependencies.sh delete mode 100755 .git_hooks/post-merge/install-dependencies.sh create mode 120000 .git_hooks/pre-commit/01-lint-php.sh create mode 120000 .git_hooks/pre-commit/02-php-cs-fixer.sh create mode 120000 .git_hooks/pre-push/01-composer-validate.sh create mode 120000 .git_hooks/pre-push/02-phpstan.sh create mode 120000 .git_hooks/pre-push/03-test-code.sh delete mode 100755 .git_hooks/pre-push/var-dump-checker.sh rename .git_hooks/{pre-push => scripts}/composer-validate.sh (80%) rename .git_hooks/{post-checkout => scripts}/install-dependencies.sh (57%) rename .git_hooks/{pre-commit => scripts}/lint-php.sh (88%) rename .git_hooks/{pre-commit => scripts}/php-cs-fixer.sh (90%) create mode 100755 .git_hooks/scripts/phpstan.sh create mode 100755 .git_hooks/scripts/test-code.sh create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/SECURITY.md create mode 100644 .github/workflows/php-cs-fixer.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 phpstan-package.neon create mode 100644 phpstan.neon.dist create mode 100644 phpunit.xml rename {lib => src}/Api/BaseApi.php (97%) rename {lib => src}/Api/SuggestionsApi.php (100%) rename {lib => src}/ApiException.php (100%) rename {lib => src}/Configuration.php (96%) rename {lib => src}/DaDataClientProvider.php (100%) rename {lib => src}/DaDataHostEnum.php (100%) rename {lib => src}/Dto/BaseBodyDto.php (100%) rename {lib => src}/Dto/BaseDto.php (97%) rename {lib => src}/Dto/BaseQueryDto.php (100%) rename {lib => src}/Dto/BaseRequestDto.php (100%) rename {lib => src}/Dto/BaseResponseDto.php (100%) rename {lib => src}/Dto/Suggestions/Data/BoundData.php (100%) rename {lib => src}/Dto/Suggestions/Data/LocationBoostData.php (100%) rename {lib => src}/Dto/Suggestions/Data/LocationData.php (100%) rename {lib => src}/Dto/Suggestions/Data/LocationGeoData.php (100%) rename {lib => src}/Dto/Suggestions/Data/MetroDto.php (100%) rename {lib => src}/Dto/Suggestions/Data/SuggestionAddressData.php (100%) rename {lib => src}/Dto/Suggestions/Data/SuggestionData.php (100%) rename {lib => src}/Dto/Suggestions/Enums/BoundEnum.php (100%) rename {lib => src}/Dto/Suggestions/Enums/CapitalMarkerEnum.php (96%) rename {lib => src}/Dto/Suggestions/Enums/DivisionEnum.php (100%) rename {lib => src}/Dto/Suggestions/Enums/FiasLevelEnum.php (100%) rename {lib => src}/Dto/Suggestions/Enums/LanguageEnum.php (100%) rename {lib => src}/Dto/Suggestions/Enums/QCGeoEnum.php (100%) rename {lib => src}/Dto/Suggestions/Requests/SearchSuggestionsRequest.php (100%) rename {lib => src}/Dto/Suggestions/Responses/SearchSuggestionsResponse.php (100%) rename {lib => src}/RequestBuilder.php (100%) create mode 100644 tests/ExampleTest.php create mode 100644 tests/Pest.php create mode 100644 tests/TestCase.php diff --git a/.git_hooks/post-checkout/01-install-dependencies.sh b/.git_hooks/post-checkout/01-install-dependencies.sh new file mode 120000 index 0000000..43a65ea --- /dev/null +++ b/.git_hooks/post-checkout/01-install-dependencies.sh @@ -0,0 +1 @@ +../scripts/install-dependencies.sh \ No newline at end of file diff --git a/.git_hooks/post-merge/01-install-dependencies.sh b/.git_hooks/post-merge/01-install-dependencies.sh new file mode 120000 index 0000000..43a65ea --- /dev/null +++ b/.git_hooks/post-merge/01-install-dependencies.sh @@ -0,0 +1 @@ +../scripts/install-dependencies.sh \ No newline at end of file diff --git a/.git_hooks/post-merge/install-dependencies.sh b/.git_hooks/post-merge/install-dependencies.sh deleted file mode 100755 index 8222a98..0000000 --- a/.git_hooks/post-merge/install-dependencies.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# В данном хуке выполняется -# - composer install если был изменен composer.lock -# - npm install если был изменен package-lock.json - -ESC_SEQ="\x1b[" -COL_RESET=$ESC_SEQ"39;49;00m" -COL_RED=$ESC_SEQ"0;31m" -COL_GREEN=$ESC_SEQ"0;32m" -COL_YELLOW=$ESC_SEQ"0;33m" - -changed_files="$(git diff-tree -r --name-only --no-commit-id HEAD@{1} HEAD)" - -check_run() { - echo "$changed_files" | grep -q "$1" && echo " * changes detected in $1" && echo " * running $2" && eval "$2" -} - -check_run composer.lock "composer install" -check_run package-lock.json "npm install" -exit 0 diff --git a/.git_hooks/pre-commit/01-lint-php.sh b/.git_hooks/pre-commit/01-lint-php.sh new file mode 120000 index 0000000..5833040 --- /dev/null +++ b/.git_hooks/pre-commit/01-lint-php.sh @@ -0,0 +1 @@ +../scripts/lint-php.sh \ No newline at end of file diff --git a/.git_hooks/pre-commit/02-php-cs-fixer.sh b/.git_hooks/pre-commit/02-php-cs-fixer.sh new file mode 120000 index 0000000..66c2032 --- /dev/null +++ b/.git_hooks/pre-commit/02-php-cs-fixer.sh @@ -0,0 +1 @@ +../scripts/php-cs-fixer.sh \ No newline at end of file diff --git a/.git_hooks/pre-push/01-composer-validate.sh b/.git_hooks/pre-push/01-composer-validate.sh new file mode 120000 index 0000000..61e981f --- /dev/null +++ b/.git_hooks/pre-push/01-composer-validate.sh @@ -0,0 +1 @@ +../scripts/composer-validate.sh \ No newline at end of file diff --git a/.git_hooks/pre-push/02-phpstan.sh b/.git_hooks/pre-push/02-phpstan.sh new file mode 120000 index 0000000..05c8a9b --- /dev/null +++ b/.git_hooks/pre-push/02-phpstan.sh @@ -0,0 +1 @@ +../scripts/phpstan.sh \ No newline at end of file diff --git a/.git_hooks/pre-push/03-test-code.sh b/.git_hooks/pre-push/03-test-code.sh new file mode 120000 index 0000000..b33ab89 --- /dev/null +++ b/.git_hooks/pre-push/03-test-code.sh @@ -0,0 +1 @@ +../scripts/test-code.sh \ No newline at end of file diff --git a/.git_hooks/pre-push/var-dump-checker.sh b/.git_hooks/pre-push/var-dump-checker.sh deleted file mode 100755 index dd44271..0000000 --- a/.git_hooks/pre-push/var-dump-checker.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# В данном хуке выполняется проверка файлов проекта на dd, var_dump и прочие подобные отладочные функции через var-dump-check - -ESC_SEQ="\x1b[" -COL_RESET=$ESC_SEQ"39;49;00m" -COL_RED=$ESC_SEQ"0;31m" -COL_GREEN=$ESC_SEQ"0;32m" -COL_YELLOW=$ESC_SEQ"0;33m" - -echo -printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-push hook: \"var-dump-checker\"" - -./vendor/bin/var-dump-check --laravel --exclude bootstrap --exclude node_modules --exclude clients --exclude vendor . - -# If the grep command has no hits - echo a warning and exit with non-zero status. -if [ $? == 1 ]; then - printf "$COL_RED%s$COL_RESET\r\n\r\n" "Some var_dump usage found. Please fix your code" - exit 1 -fi - -echo "Okay" -exit 0 diff --git a/.git_hooks/pre-push/composer-validate.sh b/.git_hooks/scripts/composer-validate.sh similarity index 80% rename from .git_hooks/pre-push/composer-validate.sh rename to .git_hooks/scripts/composer-validate.sh index 48da49b..543451a 100755 --- a/.git_hooks/pre-push/composer-validate.sh +++ b/.git_hooks/scripts/composer-validate.sh @@ -1,6 +1,6 @@ #!/bin/bash -# В данном хуке выполняется валидация composer.json перед коммитом +# Validate composer.json before commit ESC_SEQ="\x1b[" COL_RESET=$ESC_SEQ"39;49;00m" diff --git a/.git_hooks/post-checkout/install-dependencies.sh b/.git_hooks/scripts/install-dependencies.sh similarity index 57% rename from .git_hooks/post-checkout/install-dependencies.sh rename to .git_hooks/scripts/install-dependencies.sh index 264fc53..3b308e5 100755 --- a/.git_hooks/post-checkout/install-dependencies.sh +++ b/.git_hooks/scripts/install-dependencies.sh @@ -1,8 +1,6 @@ #!/bin/bash -# В данном хуке выполняется -# - composer install если был изменен composer.json -# - npm install если был изменен package-lock.json +# - 'composer update' if changed composer.json ESC_SEQ="\x1b[" COL_RESET=$ESC_SEQ"39;49;00m" @@ -16,6 +14,5 @@ check_run() { echo "$changed_files" | grep -q "$1" && echo " * changes detected in $1" && echo " * running $2" && eval "$2" } -check_run composer.json "composer install" -check_run package-lock.json "npm install" +check_run composer.json "composer update" exit 0 diff --git a/.git_hooks/pre-commit/lint-php.sh b/.git_hooks/scripts/lint-php.sh similarity index 88% rename from .git_hooks/pre-commit/lint-php.sh rename to .git_hooks/scripts/lint-php.sh index ef3d29b..2850447 100755 --- a/.git_hooks/pre-commit/lint-php.sh +++ b/.git_hooks/scripts/lint-php.sh @@ -1,6 +1,6 @@ #!/bin/bash -# В данном хуке выполняется линтинг всех добавленных в коммит php файлов через php -l +# Lint all added php-files via 'php -l' ROOT_DIR="$(pwd)/" LIST=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD) diff --git a/.git_hooks/pre-commit/php-cs-fixer.sh b/.git_hooks/scripts/php-cs-fixer.sh similarity index 90% rename from .git_hooks/pre-commit/php-cs-fixer.sh rename to .git_hooks/scripts/php-cs-fixer.sh index fa1877e..3fe095a 100755 --- a/.git_hooks/pre-commit/php-cs-fixer.sh +++ b/.git_hooks/scripts/php-cs-fixer.sh @@ -1,6 +1,6 @@ #!/bin/bash -# В данном хуке выполняется приведение код-стайла в соответствие с конфигом .php-cs-fixer.php +# Check code style via '.php-cs-fixer.php' EXECUTABLE_NAME=php-cs-fixer EXECUTABLE_COMMAND=fix diff --git a/.git_hooks/scripts/phpstan.sh b/.git_hooks/scripts/phpstan.sh new file mode 100755 index 0000000..7c15b55 --- /dev/null +++ b/.git_hooks/scripts/phpstan.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Run composer phpstan + +ESC_SEQ="\x1b[" +COL_RESET=$ESC_SEQ"39;49;00m" +COL_RED=$ESC_SEQ"0;31m" +COL_GREEN=$ESC_SEQ"0;32m" +COL_YELLOW=$ESC_SEQ"0;33m" + +echo +printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-push hook: \"phpstan\"" + +if composer phpstan; then + echo "Okay" + exit 0 +else + printf "$COL_RED%s$COL_RESET\r\n" "phpstan analysis failed." + exit 1 +fi diff --git a/.git_hooks/scripts/test-code.sh b/.git_hooks/scripts/test-code.sh new file mode 100755 index 0000000..faa22a1 --- /dev/null +++ b/.git_hooks/scripts/test-code.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Run composer test + +ESC_SEQ="\x1b[" +COL_RESET=$ESC_SEQ"39;49;00m" +COL_RED=$ESC_SEQ"0;31m" +COL_GREEN=$ESC_SEQ"0;32m" +COL_YELLOW=$ESC_SEQ"0;33m" + +echo +printf "$COL_YELLOW%s$COL_RESET\n" "Running pre-push hook: \"test-code\"" + +if composer test; then + echo "Okay" + exit 0 +else + printf "$COL_RED%s$COL_RESET\r\n" "Tests failed." + exit 1 +fi diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..8169284 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,53 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the +world that developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient +quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open +source projects are used by many developers, who may have entirely different needs to your own. Think about +whether or not your feature is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + +**Happy coding**! diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..79c6717 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Security Policy + +If you discover any security related issues, please email mail@greensight.ru instead of using the issue tracker. \ No newline at end of file diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..5811f0c --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [push] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php-cs-fixer.php --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..8cc5b7e --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,51 @@ +name: run-tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.1, 8.2, 8.3] + laravel: [9.*, 10.*, 11.*] + exclude: + - laravel: 11.* + php: 8.1 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} + + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update + composer update --prefer-stable --prefer-dist --no-interaction + + - name: Composer Validate + run: ./.git_hooks/scripts/composer-validate.sh + + - name: Execute tests + run: composer test-ci + + - name: Execute phpstan + run: ./.git_hooks/scripts/phpstan.sh diff --git a/.gitignore b/.gitignore index 922b6d6..daa725d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,17 @@ -# From laravel/laravel # +# Project # ######################## +.php_cs.cache +.php-cs-fixer.cache +.huskyrc +clients/* +!clients/.gitkeep +storage/ensi +generated +studio.json +build /node_modules /vendor -docker-compose.override.yml +.phpunit.result.cache composer.lock composer.local.json Homestead.json @@ -14,8 +23,10 @@ yarn-error.log ################### *.sublime-project *.sublime-workspace -/.idea/ +/.idea +/.vscode *.komodoproject +.vscode # Static content # ################### @@ -29,10 +40,7 @@ yarn-error.log !phpunit.xml !psalm.xml *.yml -!.docker/docker-compose.yml *.txt -!robots.txt -!robots_*.txt *.wav *.mp3 *.avi @@ -74,10 +82,4 @@ yarn-error.log ehthumbs.db Thumbs.db sftp-config.json -auth.json - -# Project # -########### -.php_cs.cache -.php-cs-fixer.cache -studio.json +auth.json \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 2ec6347..b9ca63e 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,9 +1,12 @@ notPath('vendor') - ->in(__DIR__) + ->in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) ->name('*.php') + ->notName('*.blade.php') ->ignoreDotFiles(true) ->ignoreVCS(true); diff --git a/README.md b/README.md index c4fafea..1e38c75 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,41 @@ # DaData SDK -# Подключение к сервису +[![Latest Version on Packagist](https://img.shields.io/packagist/v/ensi/dadata-sdk-php.svg?style=flat-square)](https://packagist.org/packages/ensi/dadata-sdk-php) +[![Tests](https://github.com/ensi-platform/dadata-sdk-php/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/ensi-platform/dadata-sdk-php/actions/workflows/run-tests.yml) +[![Total Downloads](https://img.shields.io/packagist/dt/ensi/dadata-sdk-php.svg?style=flat-square)](https://packagist.org/packages/ensi/dadata-sdk-php) -Детали разворота и подключения sdk описана [тут](https://docs.ensi.tech/backend-guides/principles/http-client#шаблон-для-sdk-пакетов) +## Installation -## Requirements +You can install the package via composer: -PHP 8.0 and later - -## Installation & Usage - -```sh +```bash composer require ensi/dadata-sdk-php ``` -## Author +## Version Compatibility + +| DaData SDK | PHP | +|------------|------| +| ^1.0.0 | ^8.0 | +| ^1.1.0 | ^8.1 | + +# Basic usage + +SDK connection details are described [here](https://docs.ensi.tech/backend-guides/principles/http-client#шаблон-для-sdk-пакетов) + +## Contributing + +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. + +### Testing + +1. composer install +2. composer test + +## Security Vulnerabilities + +Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities. -mail@greensight.ru +## License +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json index b245394..52ec439 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "PHP SDK for DaData", "license": "MIT", "require": { - "php": "^8.0", + "php": "^8.1", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", @@ -13,14 +13,34 @@ "webmozart/assert": "^1.11" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.2" + "friendsofphp/php-cs-fixer": "^3.2", + "pestphp/pest": "^1.22 || ^2.0", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.11", + "spaze/phpstan-disallowed-calls": "^2.15" }, "autoload": { "psr-4": { - "Ensi\\DaDataClient\\": "lib/" + "Ensi\\DaDataClient\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Ensi\\DaDataClient\\Tests\\": "tests" } }, "scripts": { - "cs": "php-cs-fixer fix --config .php-cs-fixer.php" + "cs": "php-cs-fixer fix --config .php-cs-fixer.php", + "phpstan": "phpstan analyse", + "test": "./vendor/bin/pest --parallel --no-coverage", + "test-ci": "./vendor/bin/pest --no-coverage", + "test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/pest --parallel --coverage" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } } } diff --git a/phpstan-package.neon b/phpstan-package.neon new file mode 100644 index 0000000..e69de29 diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..a2205ac --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,61 @@ +includes: + - ./vendor/spaze/phpstan-disallowed-calls/disallowed-dangerous-calls.neon + - ./phpstan-package.neon + +parameters: + paths: + - src + + scanFiles: + + # Pest handles loading custom helpers only when running tests + # @see https://pestphp.com/docs/helpers#usage + - tests/Pest.php + + # The level 9 is the highest level + level: 5 + + ignoreErrors: + - '#PHPDoc tag @var#' + + - '#Unsafe usage of new static\(\)\.#' + + # Pest implicitly binds $this to the current test case + # @see https://pestphp.com/docs/underlying-test-case + - + message: '#^Undefined variable: \$this$#' + path: '*Test.php' + + # Pest custom expectations are dynamic and not conducive static analysis + # @see https://pestphp.com/docs/expectations#custom-expectations + - + message: '#Call to an undefined method Pest\\Expectation|Pest\\Support\\Extendable::#' + path: '*Test.php' + + # Pest allow pass any array for TestCall::with + - + message: '#Parameter \#\d ...\$data of method Pest\\PendingCalls\\TestCall::with(.*) array(.*)given#' + path: '*Test.php' + + # Ignore custom method for Faker\Generator + - + message: '#Call to an undefined method Faker\\Generator|Ensi\\TestFactories\\FakerProvider::#' + path: '*Factory.php' + + # Ignore transfer of UploadedFile in auto-generated lib + - + message: '#expects SplFileObject\|null, Illuminate\\Http\\UploadedFile given.#' + path: '*Action.php' + + excludePaths: + - ./*/*/FileToBeExcluded.php + + disallowedFunctionCalls: + - + function: 'dd()' + message: 'use some logger instead' + - + function: 'dump()' + message: 'use some logger instead' + + reportUnmatchedIgnoredErrors: false diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..c2a4f58 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,20 @@ + + + + + tests + + + + + ./src + + + + + + diff --git a/lib/Api/BaseApi.php b/src/Api/BaseApi.php similarity index 97% rename from lib/Api/BaseApi.php rename to src/Api/BaseApi.php index 2b01639..5322798 100644 --- a/lib/Api/BaseApi.php +++ b/src/Api/BaseApi.php @@ -47,7 +47,7 @@ protected function sendAsync(RequestBuilder $request, Closure $fn): PromiseInter return $this->client ->sendAsync($request->build($this->config, $this->getHost())) ->then( - function ($response) use ($fn, $request) { + function ($response) use ($fn) { return $fn($this->deserialize($response)); }, function ($e) { diff --git a/lib/Api/SuggestionsApi.php b/src/Api/SuggestionsApi.php similarity index 100% rename from lib/Api/SuggestionsApi.php rename to src/Api/SuggestionsApi.php diff --git a/lib/ApiException.php b/src/ApiException.php similarity index 100% rename from lib/ApiException.php rename to src/ApiException.php diff --git a/lib/Configuration.php b/src/Configuration.php similarity index 96% rename from lib/Configuration.php rename to src/Configuration.php index 2c5e39f..1438d92 100644 --- a/lib/Configuration.php +++ b/src/Configuration.php @@ -6,7 +6,7 @@ class Configuration { - private static Configuration $defaultConfiguration; + private static ?Configuration $defaultConfiguration = null; protected ?string $apiKey = null; protected ?string $secretKey = null; diff --git a/lib/DaDataClientProvider.php b/src/DaDataClientProvider.php similarity index 100% rename from lib/DaDataClientProvider.php rename to src/DaDataClientProvider.php diff --git a/lib/DaDataHostEnum.php b/src/DaDataHostEnum.php similarity index 100% rename from lib/DaDataHostEnum.php rename to src/DaDataHostEnum.php diff --git a/lib/Dto/BaseBodyDto.php b/src/Dto/BaseBodyDto.php similarity index 100% rename from lib/Dto/BaseBodyDto.php rename to src/Dto/BaseBodyDto.php diff --git a/lib/Dto/BaseDto.php b/src/Dto/BaseDto.php similarity index 97% rename from lib/Dto/BaseDto.php rename to src/Dto/BaseDto.php index 1b51f97..a4e6aa7 100644 --- a/lib/Dto/BaseDto.php +++ b/src/Dto/BaseDto.php @@ -78,7 +78,7 @@ protected function mapAttribute(string $key, string $class, $default = null): vo $this->__set($key, new $class($value)); } - public function jsonSerialize() + public function jsonSerialize(): array { return $this->attributes; } diff --git a/lib/Dto/BaseQueryDto.php b/src/Dto/BaseQueryDto.php similarity index 100% rename from lib/Dto/BaseQueryDto.php rename to src/Dto/BaseQueryDto.php diff --git a/lib/Dto/BaseRequestDto.php b/src/Dto/BaseRequestDto.php similarity index 100% rename from lib/Dto/BaseRequestDto.php rename to src/Dto/BaseRequestDto.php diff --git a/lib/Dto/BaseResponseDto.php b/src/Dto/BaseResponseDto.php similarity index 100% rename from lib/Dto/BaseResponseDto.php rename to src/Dto/BaseResponseDto.php diff --git a/lib/Dto/Suggestions/Data/BoundData.php b/src/Dto/Suggestions/Data/BoundData.php similarity index 100% rename from lib/Dto/Suggestions/Data/BoundData.php rename to src/Dto/Suggestions/Data/BoundData.php diff --git a/lib/Dto/Suggestions/Data/LocationBoostData.php b/src/Dto/Suggestions/Data/LocationBoostData.php similarity index 100% rename from lib/Dto/Suggestions/Data/LocationBoostData.php rename to src/Dto/Suggestions/Data/LocationBoostData.php diff --git a/lib/Dto/Suggestions/Data/LocationData.php b/src/Dto/Suggestions/Data/LocationData.php similarity index 100% rename from lib/Dto/Suggestions/Data/LocationData.php rename to src/Dto/Suggestions/Data/LocationData.php diff --git a/lib/Dto/Suggestions/Data/LocationGeoData.php b/src/Dto/Suggestions/Data/LocationGeoData.php similarity index 100% rename from lib/Dto/Suggestions/Data/LocationGeoData.php rename to src/Dto/Suggestions/Data/LocationGeoData.php diff --git a/lib/Dto/Suggestions/Data/MetroDto.php b/src/Dto/Suggestions/Data/MetroDto.php similarity index 100% rename from lib/Dto/Suggestions/Data/MetroDto.php rename to src/Dto/Suggestions/Data/MetroDto.php diff --git a/lib/Dto/Suggestions/Data/SuggestionAddressData.php b/src/Dto/Suggestions/Data/SuggestionAddressData.php similarity index 100% rename from lib/Dto/Suggestions/Data/SuggestionAddressData.php rename to src/Dto/Suggestions/Data/SuggestionAddressData.php diff --git a/lib/Dto/Suggestions/Data/SuggestionData.php b/src/Dto/Suggestions/Data/SuggestionData.php similarity index 100% rename from lib/Dto/Suggestions/Data/SuggestionData.php rename to src/Dto/Suggestions/Data/SuggestionData.php diff --git a/lib/Dto/Suggestions/Enums/BoundEnum.php b/src/Dto/Suggestions/Enums/BoundEnum.php similarity index 100% rename from lib/Dto/Suggestions/Enums/BoundEnum.php rename to src/Dto/Suggestions/Enums/BoundEnum.php diff --git a/lib/Dto/Suggestions/Enums/CapitalMarkerEnum.php b/src/Dto/Suggestions/Enums/CapitalMarkerEnum.php similarity index 96% rename from lib/Dto/Suggestions/Enums/CapitalMarkerEnum.php rename to src/Dto/Suggestions/Enums/CapitalMarkerEnum.php index e509fb4..f316d59 100644 --- a/lib/Dto/Suggestions/Enums/CapitalMarkerEnum.php +++ b/src/Dto/Suggestions/Enums/CapitalMarkerEnum.php @@ -24,7 +24,7 @@ class CapitalMarkerEnum /** * Gets allowable values of the enum - * @return string[] + * @return int[] */ public static function getAllowableEnumValues(): array { @@ -39,7 +39,7 @@ public static function getAllowableEnumValues(): array /** * Gets allowable values and titles of the enum - * @return string[] + * @return array */ public static function getDescriptions(): array { diff --git a/lib/Dto/Suggestions/Enums/DivisionEnum.php b/src/Dto/Suggestions/Enums/DivisionEnum.php similarity index 100% rename from lib/Dto/Suggestions/Enums/DivisionEnum.php rename to src/Dto/Suggestions/Enums/DivisionEnum.php diff --git a/lib/Dto/Suggestions/Enums/FiasLevelEnum.php b/src/Dto/Suggestions/Enums/FiasLevelEnum.php similarity index 100% rename from lib/Dto/Suggestions/Enums/FiasLevelEnum.php rename to src/Dto/Suggestions/Enums/FiasLevelEnum.php diff --git a/lib/Dto/Suggestions/Enums/LanguageEnum.php b/src/Dto/Suggestions/Enums/LanguageEnum.php similarity index 100% rename from lib/Dto/Suggestions/Enums/LanguageEnum.php rename to src/Dto/Suggestions/Enums/LanguageEnum.php diff --git a/lib/Dto/Suggestions/Enums/QCGeoEnum.php b/src/Dto/Suggestions/Enums/QCGeoEnum.php similarity index 100% rename from lib/Dto/Suggestions/Enums/QCGeoEnum.php rename to src/Dto/Suggestions/Enums/QCGeoEnum.php diff --git a/lib/Dto/Suggestions/Requests/SearchSuggestionsRequest.php b/src/Dto/Suggestions/Requests/SearchSuggestionsRequest.php similarity index 100% rename from lib/Dto/Suggestions/Requests/SearchSuggestionsRequest.php rename to src/Dto/Suggestions/Requests/SearchSuggestionsRequest.php diff --git a/lib/Dto/Suggestions/Responses/SearchSuggestionsResponse.php b/src/Dto/Suggestions/Responses/SearchSuggestionsResponse.php similarity index 100% rename from lib/Dto/Suggestions/Responses/SearchSuggestionsResponse.php rename to src/Dto/Suggestions/Responses/SearchSuggestionsResponse.php diff --git a/lib/RequestBuilder.php b/src/RequestBuilder.php similarity index 100% rename from lib/RequestBuilder.php rename to src/RequestBuilder.php diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php new file mode 100644 index 0000000..482f587 --- /dev/null +++ b/tests/ExampleTest.php @@ -0,0 +1,5 @@ +toEqual(true); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..aedfc6e --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,48 @@ +in(__DIR__); + + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +//expect()->extend('toBeOne', function () { +// return $this->toBe(1); +//}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +//function something() +//{ +// // .. +//} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..22758b3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,9 @@ + Date: Tue, 28 May 2024 15:30:49 +0300 Subject: [PATCH 2/3] ENSITECH-74 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 52ec439..04f705b 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "ext-json": "*", "ext-mbstring": "*", "guzzlehttp/guzzle": "^6.2 || ^7.0", - "symfony/http-foundation": "^5.0 || ^6.0", + "symfony/http-foundation": "^5.0 || ^6.0 || ^7.0", "guzzlehttp/psr7": "^1.6.1 || ^2.4", "webmozart/assert": "^1.11" }, From b772745076c70876d7ed13bd63bb094b054641a9 Mon Sep 17 00:00:00 2001 From: Ms_Natali Date: Thu, 30 May 2024 10:38:31 +0300 Subject: [PATCH 3/3] ENSITECH-74 --- .php-cs-fixer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index b9ca63e..a2dce95 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -39,5 +39,6 @@ 'single_trait_insert_per_statement' => true, 'no_whitespace_in_blank_line' => true, 'method_chaining_indentation' => true, + 'single_space_around_construct' => true, ]) ->setFinder($finder);