├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── .styleci.yml ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── _config.yml ├── composer.json ├── phpunit.xml.dist ├── src ├── AbstractService.php ├── ApiRequestFactory.php ├── JsonMediator.php ├── Model │ ├── AbstractCollection.php │ ├── AbstractModel.php │ ├── ConfigurableInterface.php │ ├── NullableCollection.php │ └── Response │ │ ├── Address.php │ │ ├── Balance.php │ │ ├── Clean │ │ ├── Address.php │ │ ├── AddressCollection.php │ │ ├── BaseModel.php │ │ ├── Metro.php │ │ ├── MetroCollection.php │ │ ├── Name.php │ │ └── NameCollection.php │ │ ├── Error.php │ │ ├── Fio.php │ │ ├── Suggestions │ │ ├── AbstractSuggestion.php │ │ ├── AddressSuggestion.php │ │ ├── AddressSuggestionsCollection.php │ │ ├── AddressSuggestionsResponse.php │ │ ├── FioSuggestion.php │ │ ├── FioSuggestionsCollection.php │ │ └── FioSuggestionsResponse.php │ │ └── Version │ │ ├── BaseVersion.php │ │ ├── BaseVersionWithResources.php │ │ ├── Dadata.php │ │ ├── Factor.php │ │ ├── Suggestions.php │ │ └── Version.php └── Service │ ├── Clean.php │ ├── General.php │ └── Suggestions.php └── tests ├── AbstractModelTest.php ├── ApiRequestFactoryTest.php ├── BaseTestCase.php └── JsonMediatorTest.php /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Additional context** 24 | Add any other context about the problem here. 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /composer.lock 3 | /vendor 4 | /phpunit.xml 5 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: psr2 2 | 3 | risky: false 4 | 5 | enabled: 6 | - alpha_ordered_imports 7 | - binary_operator_spaces 8 | - blank_line_after_opening_tag 9 | - cast_spaces 10 | - concat_with_spaces 11 | - function_typehint_space 12 | - hash_to_slash_comment 13 | - include 14 | - lowercase_cast 15 | - method_separation 16 | - native_function_casing 17 | - no_blank_lines_after_class_opening 18 | - no_blank_lines_after_phpdoc 19 | - no_blank_lines_after_return 20 | - no_blank_lines_after_throw 21 | - no_blank_lines_between_imports 22 | - no_blank_lines_between_traits 23 | - no_empty_statement 24 | - no_extra_consecutive_blank_lines 25 | - no_spaces_inside_offset 26 | - no_spaces_outside_offset 27 | - no_trailing_comma_in_singleline_array 28 | - no_unused_imports 29 | - no_whitespace_before_comma_in_array 30 | - normalize_index_brace 31 | - object_operator_without_whitespace 32 | - return_type_declaration 33 | - short_array_syntax 34 | - short_scalar_cast 35 | - single_blank_line_before_namespace 36 | - single_quote 37 | - trailing_comma_in_multiline_array 38 | - unalign_double_arrow 39 | - unalign_equals 40 | - whitespace_after_comma_in_array 41 | 42 | disabled: 43 | - single_import_per_statement 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | notifications: 2 | email: false 3 | 4 | language: php 5 | 6 | php: 7 | - 7.1 8 | 9 | script: vendor/bin/phpunit 10 | 11 | before_script: 12 | - "composer install --prefer-source --no-interaction" 13 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at spam@onsky.ru. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 4 | 5 | * Reporting a bug 6 | * Discussing the current state of the code 7 | * Submitting a fix 8 | * Proposing new features 9 | * Becoming a maintainer 10 | 11 | ## We develop with Github 12 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 13 | 14 | ## All code changes happen through pull requests 15 | Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests: 16 | 17 | 1. Fork the repo and create your branch from `master`. 18 | 2. If you've added code that should be tested, add tests. 19 | 3. If you've changed APIs, update the documentation. 20 | 4. Ensure the tests pass. 21 | 5. Issue that pull request! 22 | 23 | ## Any contributions you make will be under the MIT Software License 24 | In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. 25 | 26 | ## Report bugs using Github's [issues](https://github.com/gietos/dadata/issues) 27 | We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy! 28 | 29 | ## Write bug reports with detail, background, and sample code 30 | 31 | **Great Bug Reports** tend to have: 32 | 33 | - A quick summary and/or background 34 | - Steps to reproduce 35 | - Be specific! 36 | - Give sample code if you can. 37 | - What you expected would happen 38 | - What actually happens 39 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 40 | 41 | ## Use a consistent coding style 42 | 43 | We follow [PSR-2](https://www.php-fig.org/psr/psr-2/) 44 | 45 | ## License 46 | By contributing, you agree that your contributions will be licensed under its MIT License. 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sergey Kasatkin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Dadata API client 2 | ================= 3 | 4 | Non-official PHP library for the DaData.ru REST API 5 | 6 | [![Latest Stable Version](https://poser.pugx.org/kstkn/dadata/version)](https://packagist.org/packages/kstkn/dadata) 7 | [![Total Downloads](https://poser.pugx.org/kstkn/dadata/downloads)](https://packagist.org/packages/kstkn/dadata) 8 | [![License](https://poser.pugx.org/kstkn/dadata/license)](https://packagist.org/packages/kstkn/dadata) 9 | 10 | [API documentation](https://dadata.ru/api/clean/) 11 | 12 | ## Installation 13 | 14 | The suggested installation method is via [composer](https://getcomposer.org/): 15 | 16 | ```sh 17 | composer require kstkn/dadata 18 | ``` 19 | 20 | ## Usage 21 | 22 | ``` php 23 | $client = new Dadata\Client(new \GuzzleHttp\Client(), [ 24 | 'token' => '...', 25 | 'secret' => '...', 26 | ]); 27 | ``` 28 | 29 | ### Clean 30 | 31 | ``` php 32 | $response = $client->cleanAddress('мск сухонска 11/-89'); 33 | $response = $client->cleanPhone('тел 7165219 доб139'); 34 | $response = $client->cleanPassport('4509 235857'); 35 | $response = $client->cleanName('Срегей владимерович иванов'); 36 | $response = $client->cleanEmail('serega@yandex/ru'); 37 | $response = $client->cleanDate('24/3/12'); 38 | $response = $client->cleanVehicle('форд фокус') 39 | ``` 40 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-hacker -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kstkn/dadata", 3 | "description": "Dadata API client (https://dadata.ru)", 4 | "minimum-stability": "stable", 5 | "license": "MIT", 6 | "support": { 7 | "issues": "https://github.com/kstkn/dadata/issues", 8 | "source": "https://github.com/kstkn/dadata" 9 | }, 10 | "authors": [ 11 | { 12 | "name": "Sergey Kasatkin", 13 | "email": "spam@onsky.ru" 14 | }, 15 | { 16 | "name": "Vitaly Grechkin", 17 | "email": "vitaly.grechkin@gmail.com" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=7.1", 22 | "ext-json": "*", 23 | "doctrine/inflector": "^1.2", 24 | "doctrine/collections": "^1.4", 25 | "psr/http-client": "^1.0", 26 | "psr/http-factory": "^1.0" 27 | }, 28 | "require-dev": { 29 | "phpunit/phpunit": "^7", 30 | "zendframework/zend-diactoros": "^2.0" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Gietos\\Dadata\\": "src/", 35 | "Gietos\\Dadata\\Tests\\": "tests/" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | tests 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/AbstractService.php: -------------------------------------------------------------------------------- 1 | apiRequestFactory = $apiRequestFactory; 24 | $this->httpClient = $httpClient; 25 | } 26 | 27 | protected function getBaseUri(): string 28 | { 29 | return 'https://dadata.ru/api/v2'; 30 | } 31 | 32 | /** 33 | * @param ResponseInterface $response 34 | * @param string $expectedResponseClass 35 | * @return object|Error 36 | */ 37 | public function getResult(ResponseInterface $response, $expectedResponseClass) 38 | { 39 | $responseMediator = new JsonMediator; 40 | $result = $responseMediator->getResult($response, $expectedResponseClass); 41 | 42 | return $result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/ApiRequestFactory.php: -------------------------------------------------------------------------------- 1 | token = $token; 52 | $this->secret = $secret; 53 | $this->requestFactory = $requestFactory; 54 | $this->streamFactory = $streamFactory; 55 | $this->uriFactory = $uriFactory; 56 | } 57 | 58 | /** 59 | * @return string 60 | */ 61 | public function getVersion(): string 62 | { 63 | return $this->version; 64 | } 65 | 66 | /** 67 | * Creates request with necessary headers & encoded body. 68 | * 69 | * @param string $method 70 | * @param string $uri 71 | * @param array $body 72 | * 73 | * @return RequestInterface 74 | */ 75 | public function createRequest(string $method, string $uri, array $body = []): RequestInterface 76 | { 77 | $request = $this->requestFactory->createRequest($method, $uri) 78 | ->withHeader('Content-Type', 'application/json') 79 | ->withHeader('Authorization', 'Token ' . $this->token) 80 | ->withHeader('X-Secret', $this->secret) 81 | ; 82 | 83 | if (!empty($body)) { 84 | $request = $request 85 | ->withBody($this->streamFactory->createStream(json_encode($body, JSON_UNESCAPED_UNICODE))) 86 | ; 87 | } 88 | 89 | return $request; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/JsonMediator.php: -------------------------------------------------------------------------------- 1 | configure($data); 37 | 38 | return $object; 39 | } 40 | 41 | /** 42 | * @param ResponseInterface $response 43 | * @param string $expectedResponseClass 44 | * @return object|Error 45 | */ 46 | public function getResult(ResponseInterface $response, string $expectedResponseClass) 47 | { 48 | $data = json_decode((string) $response->getBody(), true); 49 | 50 | if (json_last_error() !== JSON_ERROR_NONE) { 51 | throw new \Exception(sprintf('Could not parse JSON response: %s', json_last_error_msg())); 52 | } 53 | 54 | if ($response->getStatusCode() !== 200) { 55 | return $this->getError($response->getStatusCode(), $data); 56 | } 57 | 58 | if (!is_array($data)) { 59 | throw new \Exception('Unexpected JSON response. Array is expected'); 60 | } 61 | 62 | return $this->getObject($expectedResponseClass, $data); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Model/AbstractCollection.php: -------------------------------------------------------------------------------- 1 | validateElement($element); 13 | } 14 | parent::__construct($elements); 15 | } 16 | 17 | /** 18 | * Declares which elements can this collection contain. 19 | */ 20 | abstract protected function getClass(): string; 21 | 22 | /** 23 | * Checks if element collection constructed with has correct class. 24 | * 25 | * @param object $element 26 | */ 27 | public function validateElement($element) 28 | { 29 | if (!is_object($element)) { 30 | throw new \InvalidArgumentException(sprintf( 31 | 'Invalid element of type %s passed to %s, expected: %s', 32 | gettype($element), 33 | get_class($this), 34 | $this->getClass() 35 | )); 36 | } 37 | 38 | if (!is_a($element, $this->getClass())) { 39 | throw new \InvalidArgumentException(sprintf( 40 | 'Invalid element (instance of %s) passed to %s, expected: %s', 41 | get_class($element), 42 | get_class($this), 43 | $this->getClass() 44 | )); 45 | } 46 | } 47 | 48 | /** 49 | * @param array $config 50 | */ 51 | public function configure(array $config = []) 52 | { 53 | $className = $this->getClass(); 54 | foreach ($config as $item) { 55 | $reflection = new \ReflectionClass($className); 56 | $object = $reflection->newInstanceWithoutConstructor(); 57 | if ($object instanceof ConfigurableInterface) { 58 | $object->configure($item); 59 | } 60 | $this->add($object); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Model/AbstractModel.php: -------------------------------------------------------------------------------- 1 | $value) { 15 | $propertyName = Inflector::camelize($key); 16 | $this->setProperty($propertyName, $value); 17 | } 18 | } 19 | 20 | /** 21 | * @param string $name 22 | * @param mixed $value 23 | */ 24 | public function setProperty(string $name, $value) 25 | { 26 | $setter = 'set' . ucfirst($name); 27 | 28 | if (method_exists($this, $setter)) { 29 | $methodReflection = new \ReflectionMethod($this, $setter); 30 | $params = $methodReflection->getParameters(); 31 | if (count($params) !== 1) { 32 | throw new \LogicException( 33 | sprintf('Setter method %s::%s must have exactly 1 argument', get_class($this), $setter) 34 | ); 35 | } 36 | $param = $params[0]; 37 | if (null === $value) { 38 | if (false === $param->allowsNull()) { 39 | throw new \LogicException( 40 | sprintf('Setter method %s::%s doesn\'t allow null', get_class($this), $setter) 41 | ); 42 | } 43 | } else { 44 | if ($class = $param->getClass()) { 45 | $object = $class->newInstance(); 46 | if ($object instanceof ConfigurableInterface) { 47 | $object->configure($value); 48 | $value = $object; 49 | } 50 | } 51 | } 52 | 53 | call_user_func([$this, $setter], $value); 54 | 55 | return; 56 | } 57 | 58 | if (property_exists($this, $name)) { 59 | $this->{$name} = $value; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Model/ConfigurableInterface.php: -------------------------------------------------------------------------------- 1 | getClass(); 13 | if (is_null($config)) { 14 | return; 15 | } 16 | foreach ($config as $item) { 17 | $reflection = new \ReflectionClass($className); 18 | $object = $reflection->newInstanceWithoutConstructor(); 19 | if ($object instanceof ConfigurableInterface) { 20 | $object->configure($item); 21 | } 22 | $this->add($object); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Model/Response/Address.php: -------------------------------------------------------------------------------- 1 | postalCode; 525 | } 526 | 527 | public function setPostalCode(?string $postalCode) 528 | { 529 | $this->postalCode = $postalCode; 530 | } 531 | 532 | public function getCountry(): ?string 533 | { 534 | return $this->country; 535 | } 536 | 537 | public function setCountry(?string $country) 538 | { 539 | $this->country = $country; 540 | } 541 | 542 | public function getRegionFiasId(): ?string 543 | { 544 | return $this->regionFiasId; 545 | } 546 | 547 | public function setRegionFiasId(?string $regionFiasId) 548 | { 549 | $this->regionFiasId = $regionFiasId; 550 | } 551 | 552 | public function getRegionKladrId(): ?string 553 | { 554 | return $this->regionKladrId; 555 | } 556 | 557 | public function setRegionKladrId(?string $regionKladrId) 558 | { 559 | $this->regionKladrId = $regionKladrId; 560 | } 561 | 562 | public function getRegionWithType(): ?string 563 | { 564 | return $this->regionWithType; 565 | } 566 | 567 | public function setRegionWithType(?string $regionWithType) 568 | { 569 | $this->regionWithType = $regionWithType; 570 | } 571 | 572 | public function getRegionType(): ?string 573 | { 574 | return $this->regionType; 575 | } 576 | 577 | public function setRegionType(?string $regionType) 578 | { 579 | $this->regionType = $regionType; 580 | } 581 | 582 | public function getRegionTypeFull(): ?string 583 | { 584 | return $this->regionTypeFull; 585 | } 586 | 587 | public function setRegionTypeFull(?string $regionTypeFull) 588 | { 589 | $this->regionTypeFull = $regionTypeFull; 590 | } 591 | 592 | public function getRegion(): ?string 593 | { 594 | return $this->region; 595 | } 596 | 597 | public function setRegion(?string $region) 598 | { 599 | $this->region = $region; 600 | } 601 | 602 | public function getAreaFiasId(): ?string 603 | { 604 | return $this->areaFiasId; 605 | } 606 | 607 | public function setAreaFiasId(?string $areaFiasId) 608 | { 609 | $this->areaFiasId = $areaFiasId; 610 | } 611 | 612 | public function getAreaKladrId(): ?string 613 | { 614 | return $this->areaKladrId; 615 | } 616 | 617 | public function setAreaKladrId(?string $areaKladrId) 618 | { 619 | $this->areaKladrId = $areaKladrId; 620 | } 621 | 622 | public function getAreaWithType(): ?string 623 | { 624 | return $this->areaWithType; 625 | } 626 | 627 | public function setAreaWithType(?string $areaWithType) 628 | { 629 | $this->areaWithType = $areaWithType; 630 | } 631 | 632 | public function getAreaType(): ?string 633 | { 634 | return $this->areaType; 635 | } 636 | 637 | public function setAreaType(?string $areaType) 638 | { 639 | $this->areaType = $areaType; 640 | } 641 | 642 | public function getAreaTypeFull(): ?string 643 | { 644 | return $this->areaTypeFull; 645 | } 646 | 647 | public function setAreaTypeFull(?string $areaTypeFull) 648 | { 649 | $this->areaTypeFull = $areaTypeFull; 650 | } 651 | 652 | public function getArea(): ?string 653 | { 654 | return $this->area; 655 | } 656 | 657 | public function setArea(?string $area) 658 | { 659 | $this->area = $area; 660 | } 661 | 662 | public function getCityFiasId(): ?string 663 | { 664 | return $this->cityFiasId; 665 | } 666 | 667 | public function setCityFiasId(?string $cityFiasId) 668 | { 669 | $this->cityFiasId = $cityFiasId; 670 | } 671 | 672 | public function getCityKladrId(): ?string 673 | { 674 | return $this->cityKladrId; 675 | } 676 | 677 | public function setCityKladrId(?string $cityKladrId) 678 | { 679 | $this->cityKladrId = $cityKladrId; 680 | } 681 | 682 | public function getCityWithType(): ?string 683 | { 684 | return $this->cityWithType; 685 | } 686 | 687 | public function setCityWithType(?string $cityWithType) 688 | { 689 | $this->cityWithType = $cityWithType; 690 | } 691 | 692 | public function getCityType(): ?string 693 | { 694 | return $this->cityType; 695 | } 696 | 697 | public function setCityType(?string $cityType) 698 | { 699 | $this->cityType = $cityType; 700 | } 701 | 702 | public function getCityTypeFull(): ?string 703 | { 704 | return $this->cityTypeFull; 705 | } 706 | 707 | public function setCityTypeFull(?string $cityTypeFull) 708 | { 709 | $this->cityTypeFull = $cityTypeFull; 710 | } 711 | 712 | public function getCity(): ?string 713 | { 714 | return $this->city; 715 | } 716 | 717 | public function setCity(?string $city) 718 | { 719 | $this->city = $city; 720 | } 721 | 722 | public function getCityArea(): ?string 723 | { 724 | return $this->cityArea; 725 | } 726 | 727 | public function setCityArea(?string $cityArea) 728 | { 729 | $this->cityArea = $cityArea; 730 | } 731 | 732 | public function getCityDistrictFiasId(): ?string 733 | { 734 | return $this->cityDistrictFiasId; 735 | } 736 | 737 | public function setCityDistrictFiasId(?string $cityDistrictFiasId) 738 | { 739 | $this->cityDistrictFiasId = $cityDistrictFiasId; 740 | } 741 | 742 | public function getCityDistrictKladrId(): ?string 743 | { 744 | return $this->cityDistrictKladrId; 745 | } 746 | 747 | public function setCityDistrictKladrId(?string $cityDistrictKladrId) 748 | { 749 | $this->cityDistrictKladrId = $cityDistrictKladrId; 750 | } 751 | 752 | public function getCityDistrictWithType(): ?string 753 | { 754 | return $this->cityDistrictWithType; 755 | } 756 | 757 | public function setCityDistrictWithType(?string $cityDistrictWithType) 758 | { 759 | $this->cityDistrictWithType = $cityDistrictWithType; 760 | } 761 | 762 | public function getCityDistrictType(): ?string 763 | { 764 | return $this->cityDistrictType; 765 | } 766 | 767 | public function setCityDistrictType(?string $cityDistrictType) 768 | { 769 | $this->cityDistrictType = $cityDistrictType; 770 | } 771 | 772 | public function getCityDistrictTypeFull(): ?string 773 | { 774 | return $this->cityDistrictTypeFull; 775 | } 776 | 777 | public function setCityDistrictTypeFull(?string $cityDistrictTypeFull) 778 | { 779 | $this->cityDistrictTypeFull = $cityDistrictTypeFull; 780 | } 781 | 782 | public function getCityDistrict(): ?string 783 | { 784 | return $this->cityDistrict; 785 | } 786 | 787 | public function setCityDistrict(?string $cityDistrict) 788 | { 789 | $this->cityDistrict = $cityDistrict; 790 | } 791 | 792 | public function getSettlementFiasId(): ?string 793 | { 794 | return $this->settlementFiasId; 795 | } 796 | 797 | public function setSettlementFiasId(?string $settlementFiasId) 798 | { 799 | $this->settlementFiasId = $settlementFiasId; 800 | } 801 | 802 | public function getSettlementKladrId(): ?string 803 | { 804 | return $this->settlementKladrId; 805 | } 806 | 807 | public function setSettlementKladrId(?string $settlementKladrId) 808 | { 809 | $this->settlementKladrId = $settlementKladrId; 810 | } 811 | 812 | public function getSettlementWithType(): ?string 813 | { 814 | return $this->settlementWithType; 815 | } 816 | 817 | public function setSettlementWithType(?string $settlementWithType) 818 | { 819 | $this->settlementWithType = $settlementWithType; 820 | } 821 | 822 | public function getSettlementType(): ?string 823 | { 824 | return $this->settlementType; 825 | } 826 | 827 | public function setSettlementType(?string $settlementType) 828 | { 829 | $this->settlementType = $settlementType; 830 | } 831 | 832 | public function getSettlementTypeFull(): ?string 833 | { 834 | return $this->settlementTypeFull; 835 | } 836 | 837 | public function setSettlementTypeFull(?string $settlementTypeFull) 838 | { 839 | $this->settlementTypeFull = $settlementTypeFull; 840 | } 841 | 842 | public function getSettlement(): ?string 843 | { 844 | return $this->settlement; 845 | } 846 | 847 | public function setSettlement(?string $settlement) 848 | { 849 | $this->settlement = $settlement; 850 | } 851 | 852 | public function getStreetFiasId(): ?string 853 | { 854 | return $this->streetFiasId; 855 | } 856 | 857 | public function setStreetFiasId(?string $streetFiasId) 858 | { 859 | $this->streetFiasId = $streetFiasId; 860 | } 861 | 862 | public function getStreetKladrId(): ?string 863 | { 864 | return $this->streetKladrId; 865 | } 866 | 867 | public function setStreetKladrId(?string $streetKladrId) 868 | { 869 | $this->streetKladrId = $streetKladrId; 870 | } 871 | 872 | public function getStreetWithType(): ?string 873 | { 874 | return $this->streetWithType; 875 | } 876 | 877 | public function setStreetWithType(?string $streetWithType) 878 | { 879 | $this->streetWithType = $streetWithType; 880 | } 881 | 882 | public function getStreetType(): ?string 883 | { 884 | return $this->streetType; 885 | } 886 | 887 | public function setStreetType(?string $streetType) 888 | { 889 | $this->streetType = $streetType; 890 | } 891 | 892 | public function getStreetTypeFull(): ?string 893 | { 894 | return $this->streetTypeFull; 895 | } 896 | 897 | public function setStreetTypeFull(?string $streetTypeFull) 898 | { 899 | $this->streetTypeFull = $streetTypeFull; 900 | } 901 | 902 | public function getStreet(): ?string 903 | { 904 | return $this->street; 905 | } 906 | 907 | public function setStreet(?string $street) 908 | { 909 | $this->street = $street; 910 | } 911 | 912 | public function getHouseFiasId(): ?string 913 | { 914 | return $this->houseFiasId; 915 | } 916 | 917 | public function setHouseFiasId(?string $houseFiasId) 918 | { 919 | $this->houseFiasId = $houseFiasId; 920 | } 921 | 922 | public function getHouseKladrId(): ?string 923 | { 924 | return $this->houseKladrId; 925 | } 926 | 927 | public function setHouseKladrId(?string $houseKladrId) 928 | { 929 | $this->houseKladrId = $houseKladrId; 930 | } 931 | 932 | public function getHouseType(): ?string 933 | { 934 | return $this->houseType; 935 | } 936 | 937 | public function setHouseType(?string $houseType) 938 | { 939 | $this->houseType = $houseType; 940 | } 941 | 942 | public function getHouseTypeFull(): ?string 943 | { 944 | return $this->houseTypeFull; 945 | } 946 | 947 | public function setHouseTypeFull(?string $houseTypeFull) 948 | { 949 | $this->houseTypeFull = $houseTypeFull; 950 | } 951 | 952 | public function getHouse(): ?string 953 | { 954 | return $this->house; 955 | } 956 | 957 | public function setHouse(?string $house) 958 | { 959 | $this->house = $house; 960 | } 961 | 962 | public function getBlockType(): ?string 963 | { 964 | return $this->blockType; 965 | } 966 | 967 | public function setBlockType(?string $blockType) 968 | { 969 | $this->blockType = $blockType; 970 | } 971 | 972 | public function getBlockTypeFull(): ?string 973 | { 974 | return $this->blockTypeFull; 975 | } 976 | 977 | public function setBlockTypeFull(?string $blockTypeFull) 978 | { 979 | $this->blockTypeFull = $blockTypeFull; 980 | } 981 | 982 | public function getBlock(): ?string 983 | { 984 | return $this->block; 985 | } 986 | 987 | public function setBlock(?string $block) 988 | { 989 | $this->block = $block; 990 | } 991 | 992 | public function getFlatType(): ?string 993 | { 994 | return $this->flatType; 995 | } 996 | 997 | public function setFlatType(?string $flatType) 998 | { 999 | $this->flatType = $flatType; 1000 | } 1001 | 1002 | public function getFlatTypeFull(): ?string 1003 | { 1004 | return $this->flatTypeFull; 1005 | } 1006 | 1007 | public function setFlatTypeFull(?string $flatTypeFull) 1008 | { 1009 | $this->flatTypeFull = $flatTypeFull; 1010 | } 1011 | 1012 | public function getFlat(): ?string 1013 | { 1014 | return $this->flat; 1015 | } 1016 | 1017 | public function setFlat(?string $flat) 1018 | { 1019 | $this->flat = $flat; 1020 | } 1021 | 1022 | public function getPostalBox(): ?string 1023 | { 1024 | return $this->postalBox; 1025 | } 1026 | 1027 | public function setPostalBox(?string $postalBox) 1028 | { 1029 | $this->postalBox = $postalBox; 1030 | } 1031 | 1032 | public function getFiasId(): ?string 1033 | { 1034 | return $this->fiasId; 1035 | } 1036 | 1037 | public function setFiasId(?string $fiasId) 1038 | { 1039 | $this->fiasId = $fiasId; 1040 | } 1041 | 1042 | public function getFiasLevel(): ?int 1043 | { 1044 | return $this->fiasLevel; 1045 | } 1046 | 1047 | public function setFiasLevel(?int $fiasLevel) 1048 | { 1049 | $this->fiasLevel = $fiasLevel; 1050 | } 1051 | 1052 | public function getKladrId(): ?string 1053 | { 1054 | return $this->kladrId; 1055 | } 1056 | 1057 | public function setKladrId(?string $kladrId) 1058 | { 1059 | $this->kladrId = $kladrId; 1060 | } 1061 | 1062 | public function getCapitalMarker(): ?int 1063 | { 1064 | return $this->capitalMarker; 1065 | } 1066 | 1067 | public function setCapitalMarker(?int $capitalMarker) 1068 | { 1069 | $this->capitalMarker = $capitalMarker; 1070 | } 1071 | 1072 | public function getOkato(): ?string 1073 | { 1074 | return $this->okato; 1075 | } 1076 | 1077 | public function setOkato(?string $okato) 1078 | { 1079 | $this->okato = $okato; 1080 | } 1081 | 1082 | public function getOktmo(): ?string 1083 | { 1084 | return $this->oktmo; 1085 | } 1086 | 1087 | public function setOktmo(?string $oktmo) 1088 | { 1089 | $this->oktmo = $oktmo; 1090 | } 1091 | 1092 | public function getTaxOffice(): ?string 1093 | { 1094 | return $this->taxOffice; 1095 | } 1096 | 1097 | public function setTaxOffice(?string $taxOffice) 1098 | { 1099 | $this->taxOffice = $taxOffice; 1100 | } 1101 | 1102 | public function getGeoLat(): ?float 1103 | { 1104 | return $this->geoLat; 1105 | } 1106 | 1107 | public function setGeoLat(?float $geoLat) 1108 | { 1109 | $this->geoLat = $geoLat; 1110 | } 1111 | 1112 | public function getGeoLon(): ?float 1113 | { 1114 | return $this->geoLon; 1115 | } 1116 | 1117 | public function setGeoLon(?float $geoLon) 1118 | { 1119 | $this->geoLon = $geoLon; 1120 | } 1121 | 1122 | public function getQcGeo(): ?int 1123 | { 1124 | return $this->qcGeo; 1125 | } 1126 | 1127 | public function setQcGeo(?int $qcGeo) 1128 | { 1129 | $this->qcGeo = $qcGeo; 1130 | } 1131 | } 1132 | -------------------------------------------------------------------------------- /src/Model/Response/Balance.php: -------------------------------------------------------------------------------- 1 | balance; 17 | } 18 | 19 | public function setBalance(float $balance) 20 | { 21 | $this->balance = $balance; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Response/Clean/Address.php: -------------------------------------------------------------------------------- 1 | result; 69 | } 70 | 71 | public function getFlatArea(): ?float 72 | { 73 | return $this->flatArea; 74 | } 75 | 76 | public function setFlatArea(?float $flatArea) 77 | { 78 | $this->flatArea = $flatArea; 79 | } 80 | 81 | public function getSquareMeterPrice(): ?string 82 | { 83 | return $this->squareMeterPrice; 84 | } 85 | 86 | public function setSquareMeterPrice(?string $squareMeterPrice) 87 | { 88 | $this->squareMeterPrice = $squareMeterPrice; 89 | } 90 | 91 | public function getFlatPrice(): ?string 92 | { 93 | return $this->flatPrice; 94 | } 95 | 96 | public function setFlatPrice(?string $flatPrice) 97 | { 98 | $this->flatPrice = $flatPrice; 99 | } 100 | 101 | public function getTaxOfficeLegal(): ?string 102 | { 103 | return $this->taxOfficeLegal; 104 | } 105 | 106 | public function setTaxOfficeLegal(?string $taxOfficeLegal) 107 | { 108 | $this->taxOfficeLegal = $taxOfficeLegal; 109 | } 110 | 111 | public function getTimezone(): ?string 112 | { 113 | return $this->timezone; 114 | } 115 | 116 | public function setTimezone(?string $timezone) 117 | { 118 | $this->timezone = $timezone; 119 | } 120 | 121 | public function getBeltwayHit(): ?string 122 | { 123 | return $this->beltwayHit; 124 | } 125 | 126 | public function setBeltwayHit(?string $beltwayHit) 127 | { 128 | $this->beltwayHit = $beltwayHit; 129 | } 130 | 131 | public function getBeltwayDistance(): ?int 132 | { 133 | return $this->beltwayDistance; 134 | } 135 | 136 | public function setBeltwayDistance(?int $beltwayDistance) 137 | { 138 | $this->beltwayDistance = $beltwayDistance; 139 | } 140 | 141 | public function getQcComplete(): ?int 142 | { 143 | return $this->qcComplete; 144 | } 145 | 146 | public function setQcComplete(?int $qcComplete) 147 | { 148 | $this->qcComplete = $qcComplete; 149 | } 150 | 151 | public function getQcHouse(): ?int 152 | { 153 | return $this->qcHouse; 154 | } 155 | 156 | public function setQcHouse(?int $qcHouse) 157 | { 158 | $this->qcHouse = $qcHouse; 159 | } 160 | 161 | public function getUnparsedParts(): ?string 162 | { 163 | return $this->unparsedParts; 164 | } 165 | 166 | public function setUnparsedParts(?string $unparsedParts) 167 | { 168 | $this->unparsedParts = $unparsedParts; 169 | } 170 | 171 | public function getMetro(): MetroCollection 172 | { 173 | return $this->metro; 174 | } 175 | 176 | public function setMetro(MetroCollection $metro) 177 | { 178 | $this->metro = $metro; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /src/Model/Response/Clean/AddressCollection.php: -------------------------------------------------------------------------------- 1 | source; 20 | } 21 | 22 | public function setSource(string $source) 23 | { 24 | $this->source = $source; 25 | } 26 | 27 | public function getResult(): string 28 | { 29 | return $this->result; 30 | } 31 | 32 | public function setResult(string $result) 33 | { 34 | $this->result = $result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Model/Response/Clean/Metro.php: -------------------------------------------------------------------------------- 1 | distance; 27 | } 28 | 29 | public function setDistance(float $distance) 30 | { 31 | $this->distance = $distance; 32 | } 33 | 34 | public function getLine(): string 35 | { 36 | return $this->line; 37 | } 38 | 39 | public function setLine(string $line) 40 | { 41 | $this->line = $line; 42 | } 43 | 44 | public function getName(): string 45 | { 46 | return $this->name; 47 | } 48 | 49 | public function setName(string $name) 50 | { 51 | $this->name = $name; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Model/Response/Clean/MetroCollection.php: -------------------------------------------------------------------------------- 1 | resultGenitive; 40 | } 41 | 42 | public function setResultGenitive(string $resultGenitive) 43 | { 44 | $this->resultGenitive = $resultGenitive; 45 | } 46 | 47 | public function getResultDative(): string 48 | { 49 | return $this->resultDative; 50 | } 51 | 52 | public function setResultDative(string $resultDative) 53 | { 54 | $this->resultDative = $resultDative; 55 | } 56 | 57 | public function getResultAblative(): string 58 | { 59 | return $this->resultAblative; 60 | } 61 | 62 | public function setResultAblative(string $resultAblative) 63 | { 64 | $this->resultAblative = $resultAblative; 65 | } 66 | 67 | public function getQc(): int 68 | { 69 | return $this->qc; 70 | } 71 | 72 | public function setQc(int $qc) 73 | { 74 | $this->qc = $qc; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Model/Response/Clean/NameCollection.php: -------------------------------------------------------------------------------- 1 | code = $code; 22 | $this->detail = $detail; 23 | } 24 | 25 | public function getCode(): int 26 | { 27 | return $this->code; 28 | } 29 | 30 | public function getDetail(): string 31 | { 32 | return $this->detail; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Model/Response/Fio.php: -------------------------------------------------------------------------------- 1 | surname; 38 | } 39 | 40 | public function setSurname(string $surname) 41 | { 42 | $this->surname = $surname; 43 | } 44 | 45 | public function getName(): ?string 46 | { 47 | return $this->name; 48 | } 49 | 50 | public function setName(?string $name) 51 | { 52 | $this->name = $name; 53 | } 54 | 55 | public function getPatronymic(): ?string 56 | { 57 | return $this->patronymic; 58 | } 59 | 60 | public function setPatronymic(?string $patronymic) 61 | { 62 | $this->patronymic = $patronymic; 63 | } 64 | 65 | public function getGender(): string 66 | { 67 | return $this->gender; 68 | } 69 | 70 | public function setGender(string $gender) 71 | { 72 | $this->gender = $gender; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Model/Response/Suggestions/AbstractSuggestion.php: -------------------------------------------------------------------------------- 1 | value; 22 | } 23 | 24 | public function setValue(string $value) 25 | { 26 | $this->value = $value; 27 | } 28 | 29 | public function getUnrestrictedValue(): string 30 | { 31 | return $this->unrestrictedValue; 32 | } 33 | 34 | public function setUnrestrictedValue(string $unrestrictedValue) 35 | { 36 | $this->unrestrictedValue = $unrestrictedValue; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Model/Response/Suggestions/AddressSuggestion.php: -------------------------------------------------------------------------------- 1 | data; 17 | } 18 | 19 | public function setData(Address $data) 20 | { 21 | $this->data = $data; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Response/Suggestions/AddressSuggestionsCollection.php: -------------------------------------------------------------------------------- 1 | suggestions; 17 | } 18 | 19 | public function setSuggestions(AddressSuggestionsCollection $suggestions) 20 | { 21 | $this->suggestions = $suggestions; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Response/Suggestions/FioSuggestion.php: -------------------------------------------------------------------------------- 1 | data; 17 | } 18 | 19 | public function setData(Fio $data) 20 | { 21 | $this->data = $data; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Response/Suggestions/FioSuggestionsCollection.php: -------------------------------------------------------------------------------- 1 | suggestions; 17 | } 18 | 19 | public function setSuggestions(FioSuggestionsCollection $suggestions) 20 | { 21 | $this->suggestions = $suggestions; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Response/Version/BaseVersion.php: -------------------------------------------------------------------------------- 1 | version; 17 | } 18 | 19 | public function setVersion(string $version) 20 | { 21 | $this->version = $version; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Model/Response/Version/BaseVersionWithResources.php: -------------------------------------------------------------------------------- 1 | resources; 15 | } 16 | 17 | public function setResources(array $resources) 18 | { 19 | $this->resources = $resources; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Model/Response/Version/Dadata.php: -------------------------------------------------------------------------------- 1 | dadata; 27 | } 28 | 29 | public function setDadata(Dadata $dadata) 30 | { 31 | $this->dadata = $dadata; 32 | } 33 | 34 | public function getSuggestions(): Suggestions 35 | { 36 | return $this->suggestions; 37 | } 38 | 39 | public function setSuggestions(Suggestions $suggestions) 40 | { 41 | $this->suggestions = $suggestions; 42 | } 43 | 44 | public function getFactor(): Factor 45 | { 46 | return $this->factor; 47 | } 48 | 49 | public function setFactor(Factor $factor) 50 | { 51 | $this->factor = $factor; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Service/Clean.php: -------------------------------------------------------------------------------- 1 | apiRequestFactory->createRequest('POST', $this->getBaseUri() . '/address', $addresses); 27 | $response = $this->httpClient->sendRequest($request); 28 | return $this->getResult($response, AddressCollection::class); 29 | } 30 | 31 | public function cleanPhone() 32 | { 33 | // todo 34 | } 35 | 36 | public function cleanPassport() 37 | { 38 | // todo 39 | } 40 | 41 | /** 42 | * Cleans name. 43 | * 44 | * @param array $names 45 | * @return NameCollection|Error 46 | */ 47 | public function cleanName(array $names) 48 | { 49 | $request = $this->apiRequestFactory->createRequest('POST', $this->getBaseUri() . '/name', $names); 50 | $response = $this->httpClient->sendRequest($request); 51 | return $this->getResult($response, NameCollection::class); 52 | } 53 | 54 | public function cleanEmail() 55 | { 56 | // todo 57 | } 58 | 59 | public function cleanBirthDate() 60 | { 61 | // todo 62 | } 63 | 64 | public function cleanVehicle() 65 | { 66 | // todo 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Service/General.php: -------------------------------------------------------------------------------- 1 | apiRequestFactory->createRequest('GET', $this->getBaseUri() . '/version'); 20 | $response = $this->httpClient->sendRequest($request); 21 | 22 | return $this->getResult($response, Version::class); 23 | } 24 | 25 | /** 26 | * Gets clean service status. 27 | * If service is OK returns true, otherwise - false. 28 | * 29 | * @return bool|Error 30 | */ 31 | public function getStatus() 32 | { 33 | $request = $this->apiRequestFactory->createRequest('GET', $this->getBaseUri() . '/status/CLEAN'); 34 | $response = $this->httpClient->sendRequest($request); 35 | 36 | return $response->getStatusCode() === 200; 37 | } 38 | 39 | /** 40 | * Gets balance. 41 | * 42 | * @return float|Error 43 | */ 44 | public function getBalance() 45 | { 46 | $request = $this->apiRequestFactory->createRequest('GET', $this->getBaseUri() . '/profile/balance'); 47 | $response = $this->httpClient->sendRequest($request); 48 | 49 | $result = $this->getResult($response, Balance::class); 50 | 51 | if ($result instanceof Balance) { 52 | return $result->getBalance(); 53 | } 54 | 55 | return $result; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Service/Suggestions.php: -------------------------------------------------------------------------------- 1 | apiRequestFactory->createRequest('POST', $this->getBaseUri() . '/suggest/fio', ['query' => $query]); 36 | $response = $this->httpClient->sendRequest($request); 37 | $result = $this->getResult($response, FioSuggestionsResponse::class); 38 | if ($result instanceof FioSuggestionsResponse) { 39 | return $result->getSuggestions(); 40 | } 41 | return $result; 42 | } 43 | 44 | /** 45 | * @param string $query 46 | * @param int $count 47 | * @return AddressSuggestionsCollection|Error 48 | */ 49 | public function suggestAddress(string $query, int $count = 10) 50 | { 51 | $body = ['query' => $query, 'count' => $count]; 52 | $request = $this->apiRequestFactory->createRequest('POST', $this->getBaseUri() . '/suggest/address', $body); 53 | $response = $this->httpClient->sendRequest($request); 54 | $result = $this->getResult($response, AddressSuggestionsResponse::class); 55 | if ($result instanceof AddressSuggestionsResponse) { 56 | return $result->getSuggestions(); 57 | } 58 | return $result; 59 | } 60 | 61 | public function suggestParty() 62 | { 63 | // todo 64 | } 65 | 66 | public function suggestBank() 67 | { 68 | // todo 69 | } 70 | 71 | public function suggestEmail() 72 | { 73 | // todo 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/AbstractModelTest.php: -------------------------------------------------------------------------------- 1 | someChildScalarProperty; 14 | } 15 | } 16 | 17 | class DummyConfigurableModel extends AbstractModel 18 | { 19 | protected $someScalarProperty; 20 | 21 | protected $someArrayProperty; 22 | 23 | protected $someChild; 24 | 25 | public function setSomeArrayProperty(array $someArrayProperty) 26 | { 27 | $this->someArrayProperty = $someArrayProperty; 28 | } 29 | 30 | public function getSomeScalarProperty() 31 | { 32 | return $this->someScalarProperty; 33 | } 34 | 35 | public function getSomeArrayProperty() 36 | { 37 | return $this->someArrayProperty; 38 | } 39 | 40 | public function getSomeChild() 41 | { 42 | return $this->someChild; 43 | } 44 | 45 | public function setSomeChild(DummyConfigurableChildModel $someChild) 46 | { 47 | $this->someChild = $someChild; 48 | } 49 | } 50 | 51 | class ConfigureTest extends BaseTestCase 52 | { 53 | public function testScalarConfigured() 54 | { 55 | $object = new DummyConfigurableModel; 56 | $object->configure(['SomeScalarProperty' => 1]); 57 | 58 | $this->assertEquals(1, $object->getSomeScalarProperty()); 59 | } 60 | 61 | public function testArrayConfigured() 62 | { 63 | $object = new DummyConfigurableModel; 64 | $object->configure(['SomeArrayProperty' => [1, 2, 3]]); 65 | 66 | $this->assertEquals([1, 2, 3], $object->getSomeArrayProperty()); 67 | } 68 | 69 | public function testChildConfigured() 70 | { 71 | $object = new DummyConfigurableModel(); 72 | $object->configure(['SomeChild' => [ 73 | 'SomeChildScalarProperty' => 'someValue', 74 | ]]); 75 | 76 | $child = $object->getSomeChild(); 77 | $this->assertInstanceOf(DummyConfigurableChildModel::class, $child); 78 | /** @var DummyConfigurableChildModel $child */ 79 | $this->assertEquals('someValue', $child->getSomeChildScalarProperty()); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /tests/ApiRequestFactoryTest.php: -------------------------------------------------------------------------------- 1 | apiRequestFactory = new ApiRequestFactory( 30 | $this->token, 31 | $this->secret, 32 | new RequestFactory(), 33 | new StreamFactory(), 34 | new UriFactory() 35 | ); 36 | } 37 | 38 | public function testRequestWithCorrectMethodCreated() 39 | { 40 | $method = 'GET'; 41 | $request = $this->apiRequestFactory->createRequest($method, ''); 42 | $this->assertEquals($method, $request->getMethod()); 43 | } 44 | 45 | public function testRequestWithCorrectEndpointCreated() 46 | { 47 | $endpoint = 'https://example.com/endpoint'; 48 | $request = $this->apiRequestFactory->createRequest('GET', $endpoint); 49 | $this->assertEquals($endpoint, (string) $request->getUri()); 50 | } 51 | 52 | public function testRequestWithCorrectHeadersCreated() 53 | { 54 | $expectedHeaders = [ 55 | 'Content-Type' => 'application/json', 56 | 'Authorization' => 'Token ' . $this->token, 57 | 'X-Secret' => $this->secret, 58 | ]; 59 | 60 | $request = $this->apiRequestFactory->createRequest('POST', 'https://example.com/endpoint'); 61 | 62 | foreach ($expectedHeaders as $name => $value) { 63 | $this->assertEquals($value, (string) $request->getHeaderLine($name)); 64 | } 65 | } 66 | 67 | public function testRequestWithCorrectBodyCreated() 68 | { 69 | $body = ['one' => 1]; 70 | $encodedBody = '{"one":1}'; 71 | 72 | $request = $this->apiRequestFactory->createRequest('GET', 'https://example.com/endpoint', $body); 73 | 74 | $this->assertEquals($encodedBody, (string) $request->getBody()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /tests/BaseTestCase.php: -------------------------------------------------------------------------------- 1 | getMethod($methodName); 22 | $method->setAccessible(true); 23 | 24 | return $method->invokeArgs($object, $parameters); 25 | } 26 | 27 | protected function loadDataFile(string $name) 28 | { 29 | return file_get_contents(__DIR__ . '/data/' . $name); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/JsonMediatorTest.php: -------------------------------------------------------------------------------- 1 | requestFactory = new RequestFactory(); 38 | $this->responseFactory = new ResponseFactory(); 39 | $this->streamFactory = new StreamFactory(); 40 | $this->jsonMediator = new JsonMediator(); 41 | } 42 | 43 | public function testExceptionOnInvalidJsonSyntax() 44 | { 45 | $response = $this->responseFactory->createResponse(); 46 | $this->expectException(\Exception::class); 47 | $this->jsonMediator->getResult($response, \stdClass::class); 48 | } 49 | 50 | public function testError() 51 | { 52 | $response = $this->responseFactory->createResponse(401) 53 | ->withBody($this->streamFactory->createStream('{"detail":"Some details"}')) 54 | ; 55 | $result = $this->jsonMediator->getResult($response, \stdClass::class); 56 | 57 | $this->assertInstanceOf(Error::class, $result); 58 | } 59 | } 60 | --------------------------------------------------------------------------------