MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/www/lhh/vendor/flyingluscas/viacep-php/src/ViaCEP.php
<?php

namespace FlyingLuscas\ViaCEP;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;

class ViaCEP
{
    /**
     * HTTP client.
     *
     * @var \GuzzleHttp\Client
     */
    protected $http;

    /**
     * Creta a new ZipCode class instance.
     *
     * @param \GuzzleHttp\ClientInterface $http
     */
    public function __construct(ClientInterface $http = null)
    {
        $this->http = $http ?: new Client;
    }

    /**
     * Find address by zip code (CEP).
     *
     * @param  string $zipCode
     *
     * @return \FlyingLuscas\ViaCEP\Address
     */
    public function findByZipCode($zipCode)
    {
        $url = sprintf('https://viacep.com.br/ws/%s/json', $zipCode);

        $response = $this->http->request('GET', $url);

        $attributes = json_decode($response->getBody(), true);

        if (array_key_exists('erro', $attributes) && $attributes['erro'] === true) {
            return new Address;
        }

        return new Address($attributes);
    }

    /**
     * Find addresses by state, city and street name.
     *
     * @param  string $state
     * @param  string $city
     * @param  string $street
     *
     * @return \FlyingLuscas\ViaCEP\Address[]
     */
    public function findByStreetName($state, $city, $street)
    {
        $url = sprintf(
            'https://viacep.com.br/ws/%s/%s/%s/json',
            rawurlencode($state),
            rawurlencode($city),
            rawurlencode($street)
        );

        $response = $this->http->request('GET', $url);

        $results = json_decode($response->getBody(), true);

        if (array_key_exists('erro', $results) && $results['erro'] === true) {
            return [];
        }

        return array_map(function ($attributes) {
            return new Address($attributes);
        }, $results);
    }
}