1 | <?php |
||||
2 | require '../vendor/autoload.php'; |
||||
3 | |||||
4 | use AndreDeBrito\PHPViaCep\PhpViaCep; |
||||
5 | |||||
6 | $findByCep = (new PhpViaCep())->findByCep("01001000")->json()->fetch()->jsonToObject(); |
||||
7 | $findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")->json()->fetch()->jsonToObject(); |
||||
8 | ?> |
||||
9 | <html> |
||||
10 | <head> |
||||
11 | <title>PHPViaCep exemplos</title> |
||||
12 | <meta charset="utf-8"> |
||||
13 | <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"> |
||||
14 | |||||
15 | </head> |
||||
16 | |||||
17 | <body class="bg-light"> |
||||
18 | |||||
19 | <container> |
||||
20 | |||||
21 | <div class="bg-white container" style="padding-top: 20px; padding-bottom: 20px;"> |
||||
22 | <header class="text-center" style="margin-bottom: 15px;"> |
||||
23 | <h1>Classe PhpViaCep</h1> |
||||
24 | </header> |
||||
25 | |||||
26 | <p> |
||||
27 | Este projeto tem por objetivo consumir o webservice ViaCEP. |
||||
28 | Utilizando o PHP e CURL. |
||||
29 | </p> |
||||
30 | |||||
31 | <p> |
||||
32 | Baseado no webservice <a href="https://viacep.com.br/" target="_blank">https://viacep.com.br/</a>. |
||||
33 | Através dessa classe é possível consultar e obter dados de endereços com retorno nos formatos |
||||
34 | <b>JSON</b>, <b>XML</b>, <b>PIPED</b> e <b>QWERT</b>. |
||||
35 | </p> |
||||
36 | |||||
37 | <div> |
||||
38 | <h4>Bibliotecas e tecnlogias utiladas</h4> |
||||
39 | <ul> |
||||
40 | <li>PHP 7.2</li> |
||||
41 | <li>CURL</li> |
||||
42 | </ul> |
||||
43 | </div> |
||||
44 | |||||
45 | <div> |
||||
46 | <h4>Exemplos de utilização</h4> |
||||
47 | |||||
48 | <div id="cep"> |
||||
49 | <h5>Pesquisa por CEP</h5> |
||||
50 | <p> |
||||
51 | Instancie um novo objeto da classe PhpViaCep e invoque o método <code>findByCep()</code> |
||||
52 | passando o CEP como parâmentro, utilize uma opção de retorno (<code>json</code>, <code>json_unicode</code>, <code>xml</code>, <code>piped</code> ou <code>querty</code>), |
||||
53 | invoque o método <code>fetch()</code> (no exemplo abaixo foi utilizado o método <code>jsonToObject</code> para |
||||
54 | tornar o response e um objeto). |
||||
55 | Utilize o método <code>getResponse()</code> para exibir os dados. |
||||
56 | </p> |
||||
57 | |||||
58 | |||||
59 | <div class="bg-secondary text-light" style="padding: 15px;"> |
||||
60 | <code class="text-light"> |
||||
61 | require '../vendor/autoload.php';<br><br> |
||||
62 | |||||
63 | use AndreDeBrito\PHPViaCep\PhpViaCep;<br><br> |
||||
64 | |||||
65 | $findByCep = (new PhpViaCep())->findByCep("01001000")->json()->fetch()->jsonToObject(); |
||||
66 | </code> |
||||
67 | </div> |
||||
68 | |||||
69 | <div style="margin-top: 20px;"> |
||||
70 | <p><b>Resultado jsonToObject:</b></p> |
||||
71 | <code class="text-light bg-light"> |
||||
72 | <?= var_dump($findByCep->getResponse()); ?> |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() Are you sure the usage of
var_dump($findByCep->getResponse()) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
73 | </code> |
||||
74 | |||||
75 | <p><b>Resultado XML:</b></p> |
||||
76 | <code class="text-light bg-light"> |
||||
77 | <div class="bg-secondary" style="padding: 15px;"> |
||||
78 | <code class="text-light"> |
||||
79 | $findByCep = (new PhpViaCep())->findByCep("01001000")->xml()->fetch(); |
||||
80 | </code> |
||||
81 | </div> |
||||
82 | <?php $findByCep = (new PhpViaCep())->findByCep("01001000")->xml()->fetch(); ?> |
||||
83 | <?= var_dump($findByCep->getResponse()); ?> |
||||
0 ignored issues
–
show
Are you sure the usage of
var_dump($findByCep->getResponse()) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
84 | </code> |
||||
85 | |||||
86 | <p><b>Resultado PIPED:</b></p> |
||||
87 | <code class="text-light bg-light"> |
||||
88 | <div class="bg-secondary" style="padding: 15px;"> |
||||
89 | <code class="text-light"> |
||||
90 | $findByCep = (new PhpViaCep())->findByCep("01001000")->piped()->fetch(); |
||||
91 | </code> |
||||
92 | </div> |
||||
93 | <?php $findByCep = (new PhpViaCep())->findByCep("01001000")->piped()->fetch(); ?> |
||||
94 | <?= var_dump($findByCep->getResponse()); ?> |
||||
0 ignored issues
–
show
Are you sure the usage of
var_dump($findByCep->getResponse()) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
95 | </code> |
||||
96 | |||||
97 | <p><b>Resultado QUERTY:</b></p> |
||||
98 | <code class="text-light bg-light"> |
||||
99 | <div class="bg-secondary" style="padding: 15px;"> |
||||
100 | <code class="text-light"> |
||||
101 | $findByCep = (new PhpViaCep())->findByCep("01001000")->querty()->fetch(); |
||||
102 | </code> |
||||
103 | </div> |
||||
104 | <?php $findByCep = (new PhpViaCep())->findByCep("01001000")->querty()->fetch(); ?> |
||||
105 | <?= var_dump($findByCep->getResponse()); ?> |
||||
0 ignored issues
–
show
Are you sure the usage of
var_dump($findByCep->getResponse()) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
106 | </code> |
||||
107 | |||||
108 | </div> |
||||
109 | </div> |
||||
110 | |||||
111 | |||||
112 | <div style="margin-top: 50px;" id="address"> |
||||
113 | <h5>Pesquisa por Endereço</h5> |
||||
114 | <p> |
||||
115 | Instancie um novo objeto da classe PhpViaCep e invoque o método <code>findByAddress()</code> |
||||
116 | passando UF, Cidade e Endereço como parâmentros, utilize uma opção de retorno (<code>json</code>, <code>json_unicode</code> ou <code>xml</code>), |
||||
117 | invoque o método <code>fetch()</code> (no exemplo abaixo foi utilizado o método <code>jsonToObject</code> para |
||||
118 | tornar o response e um objeto). |
||||
119 | Utilize o método <code>getResponse()</code> para exibir os dados. |
||||
120 | </p> |
||||
121 | |||||
122 | |||||
123 | <div class="bg-secondary text-light" style="padding: 15px;"> |
||||
124 | <code class="text-light"> |
||||
125 | require '../vendor/autoload.php';<br><br> |
||||
126 | |||||
127 | use AndreDeBrito\PHPViaCep\PhpViaCep;<br><br> |
||||
128 | |||||
129 | $findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")->json()->fetch()->jsonToObject(); |
||||
130 | </code> |
||||
131 | </div> |
||||
132 | |||||
133 | <div style="margin-top: 20px;"> |
||||
134 | <p><b>Resultado jsonToObject:</b></p> |
||||
135 | <code class="text-light bg-light"> |
||||
136 | <?= var_dump($findByAddress->getResponse()); ?> |
||||
0 ignored issues
–
show
Are you sure
var_dump($findByAddress->getResponse()) of type void can be used in echo ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() Are you sure the usage of
var_dump($findByAddress->getResponse()) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
137 | </code> |
||||
138 | |||||
139 | <p><b>Resultado XML:</b></p> |
||||
140 | <code class="text-light bg-light"> |
||||
141 | <div class="bg-secondary" style="padding: 15px;"> |
||||
142 | <code class="text-light"> |
||||
143 | $findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")->xml()->fetch(); |
||||
144 | </code> |
||||
145 | </div> |
||||
146 | <?php $findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")->xml()->fetch(); ?> |
||||
147 | <?= var_dump($findByAddress->getResponse()); ?> |
||||
0 ignored issues
–
show
Are you sure the usage of
var_dump($findByAddress->getResponse()) is correct as it seems to always return null .
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||
148 | </code> |
||||
149 | |||||
150 | |||||
151 | </div> |
||||
152 | </div> |
||||
153 | </div> |
||||
154 | |||||
155 | |||||
156 | <div style="margin-top: 50px;"> |
||||
157 | <h4>Tratamento de erros</h4> |
||||
158 | <p> |
||||
159 | Caso o retorno do método <code>getResponse()</code> seja null utilize o método |
||||
160 | <code>getError()</code> para visualizar o erro. |
||||
161 | </p> |
||||
162 | </div> |
||||
163 | </div> |
||||
164 | |||||
165 | </container> |
||||
166 | </body> |
||||
167 | </html> |
||||
168 | |||||
169 |