Skip to content

Commit 23fcbbb

Browse files
feat: adicionar regras de estilo e melhorar testes de expiração de cache
1 parent 5b715e8 commit 23fcbbb

10 files changed

Lines changed: 185 additions & 320 deletions

File tree

phpcs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
<property name="absoluteLineLimit" value="180"/>
1414
</properties>
1515
</rule>
16+
17+
<!-- Exclude test helper classes from one-class-per-file rule -->
18+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
19+
<exclude-pattern>*/tests/*</exclude-pattern>
20+
</rule>
1621
<rule ref="PSR2.Classes.PropertyDeclaration"/>
1722
<rule ref="Generic.Arrays.ArrayIndent"/>
1823
<rule ref="Squiz.WhiteSpace.OperatorSpacing">

scripts/quality-check.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ rm "$coverage_output"
178178
log "🎨 4. Padrões de Codificação (PSR-12) - CRÍTICO"
179179

180180
cs_output=$(mktemp)
181-
if composer cs:check > "$cs_output" 2>&1; then
182-
cs_result=0
183-
success "Code Style PSR-12 - PASSOU"
184-
else
181+
composer cs:check > "$cs_output" 2>&1
182+
cs_exit_code=$?
183+
184+
# Check if there are actual ERRORS (not just warnings)
185+
if grep -q "FOUND.*ERROR" "$cs_output"; then
185186
cs_result=1
186187
critical "Code Style PSR-12 - FALHOU"
187188

@@ -195,11 +196,21 @@ else
195196
success "Correções aplicadas automaticamente"
196197

197198
# Verificar novamente
198-
if composer cs:check > /dev/null 2>&1; then
199+
composer cs:check > "$cs_output" 2>&1
200+
if ! grep -q "FOUND.*ERROR" "$cs_output"; then
199201
success "Code Style agora está conforme"
200202
cs_result=0
201203
fi
202204
fi
205+
elif [ $cs_exit_code -eq 0 ]; then
206+
cs_result=0
207+
success "Code Style PSR-12 - PASSOU"
208+
else
209+
# Only warnings, not errors
210+
cs_result=0
211+
success "Code Style PSR-12 - PASSOU (apenas avisos, sem erros)"
212+
info "Avisos encontrados (não bloqueiam):"
213+
grep "WARNING" "$cs_output" | head -5 || true
203214
fi
204215

205216
count_check $cs_result "critical"

src/Core/Container.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ public function make(string $abstract, array $parameters = [])
202202
if (isset($this->bindings[$abstract])) {
203203
$binding = $this->bindings[$abstract];
204204

205-
if (!is_array($binding) || !array_key_exists('singleton', $binding) || !array_key_exists('instance', $binding) || !array_key_exists('concrete', $binding)) {
205+
if (
206+
!is_array($binding) ||
207+
!array_key_exists('singleton', $binding) ||
208+
!array_key_exists('instance', $binding) ||
209+
!array_key_exists('concrete', $binding)
210+
) {
206211
throw new Exception("Invalid binding configuration for {$abstract}");
207212
}
208213

src/Routing/MockRequest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PivotPHP\Core\Routing;
6+
7+
/**
8+
* Mock Request para capturar responses estáticas
9+
*/
10+
class MockRequest
11+
{
12+
/**
13+
* @param mixed $default
14+
* @return mixed
15+
*/
16+
public function param(string $name, $default = null)
17+
{
18+
return $default;
19+
}
20+
21+
/**
22+
* @param mixed $default
23+
* @return mixed
24+
*/
25+
public function get(string $name, $default = null)
26+
{
27+
return $default;
28+
}
29+
30+
/**
31+
* @param array<mixed> $args
32+
* @return mixed
33+
*/
34+
public function __call(string $method, array $args)
35+
{
36+
return null;
37+
}
38+
}

src/Routing/MockResponse.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PivotPHP\Core\Routing;
6+
7+
/**
8+
* Mock Response para capturar responses estáticas
9+
*/
10+
class MockResponse
11+
{
12+
private string $content = '';
13+
14+
/** @var array<string, string> */
15+
private array $headers = [];
16+
17+
private int $statusCode = 200;
18+
19+
public function send(string $content): self
20+
{
21+
$this->content = $content;
22+
return $this;
23+
}
24+
25+
/**
26+
* @param array<mixed> $data
27+
*/
28+
public function json(array $data): self
29+
{
30+
$json = json_encode($data);
31+
$this->content = $json !== false ? $json : '';
32+
$this->headers['Content-Type'] = 'application/json';
33+
return $this;
34+
}
35+
36+
public function write(string $content): self
37+
{
38+
$this->content .= $content;
39+
return $this;
40+
}
41+
42+
public function header(string $name, string $value): self
43+
{
44+
$this->headers[$name] = $value;
45+
return $this;
46+
}
47+
48+
public function withHeader(string $name, string $value): self
49+
{
50+
$this->headers[$name] = $value;
51+
return $this;
52+
}
53+
54+
public function status(int $code): self
55+
{
56+
$this->statusCode = $code;
57+
return $this;
58+
}
59+
60+
public function getContent(): string
61+
{
62+
return $this->content;
63+
}
64+
65+
/**
66+
* @return array<string, string>
67+
*/
68+
public function getHeaders(): array
69+
{
70+
return $this->headers;
71+
}
72+
73+
public function getStatusCode(): int
74+
{
75+
return $this->statusCode;
76+
}
77+
78+
/**
79+
* @param array<mixed> $args
80+
* @return mixed
81+
*/
82+
public function __call(string $method, array $args)
83+
{
84+
return $this;
85+
}
86+
}

src/Routing/StaticFileManager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ class StaticFileManager
4242

4343
/**
4444
* Configurações
45-
* @var array{enable_cache: bool, max_file_size: int, max_cache_entries: int, allowed_extensions: array<int, string>, security_check: bool, send_etag: bool, send_last_modified: bool, cache_control_max_age: int}
45+
* @var array{
46+
* enable_cache: bool,
47+
* max_file_size: int,
48+
* max_cache_entries: int,
49+
* allowed_extensions: array<int, string>,
50+
* security_check: bool,
51+
* send_etag: bool,
52+
* send_last_modified: bool,
53+
* cache_control_max_age: int
54+
* }
4655
*/
4756
private static array $config = [
4857
'enable_cache' => true,

src/Routing/StaticRouteManager.php

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -227,100 +227,3 @@ public static function warmup(): void
227227
// Esta é a vantagem da abordagem explícita
228228
}
229229
}
230-
231-
/**
232-
* Mock Request para capturar responses estáticas
233-
*/
234-
class MockRequest
235-
{
236-
/**
237-
* @param mixed $default
238-
* @return mixed
239-
*/
240-
public function param(string $name, $default = null)
241-
{
242-
return $default;
243-
}
244-
245-
/**
246-
* @param mixed $default
247-
* @return mixed
248-
*/
249-
public function get(string $name, $default = null)
250-
{
251-
return $default;
252-
}
253-
254-
/**
255-
* @param array<mixed> $args
256-
* @return mixed
257-
*/
258-
public function __call(string $method, array $args)
259-
{
260-
return null;
261-
}
262-
}
263-
264-
/**
265-
* Mock Response para capturar responses estáticas
266-
*/
267-
class MockResponse
268-
{
269-
private string $content = '';
270-
/** @var array<string, string> */
271-
private array $headers = [];
272-
private int $statusCode = 200;
273-
274-
/**
275-
* @param array<mixed> $data
276-
*/
277-
public function json(array $data): self
278-
{
279-
$json = json_encode($data);
280-
$this->content = $json !== false ? $json : '';
281-
$this->headers['Content-Type'] = 'application/json';
282-
return $this;
283-
}
284-
285-
public function send(string $content): self
286-
{
287-
$this->content = $content;
288-
return $this;
289-
}
290-
291-
public function write(string $content): self
292-
{
293-
$this->content .= $content;
294-
return $this;
295-
}
296-
297-
public function withHeader(string $name, string $value): self
298-
{
299-
$this->headers[$name] = $value;
300-
return $this;
301-
}
302-
303-
public function status(int $code): self
304-
{
305-
$this->statusCode = $code;
306-
return $this;
307-
}
308-
309-
public function getContent(): string
310-
{
311-
return $this->content;
312-
}
313-
314-
/**
315-
* @return array<string, string>
316-
*/
317-
public function getHeaders(): array
318-
{
319-
return $this->headers;
320-
}
321-
322-
public function getStatusCode(): int
323-
{
324-
return $this->statusCode;
325-
}
326-
}

0 commit comments

Comments
 (0)