Skip to content

Commit 9d23d7d

Browse files
committed
chore: configure linters and fixers
1 parent c35b1ec commit 9d23d7d

12 files changed

Lines changed: 615 additions & 68 deletions

File tree

.junie/guidelines.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ The project includes comprehensive Composer scripts for development:
3232

3333
```bash
3434
# Via Docker (recommended)
35-
make test # Run PHPUnit tests with coverage
3635
make lint # Run all linting tools
3736
make ci # Full CI pipeline (lint + test)
3837

@@ -58,14 +57,14 @@ make lint-psalm # Static analysis
5857

5958
```bash
6059
# Run all tests with coverage
61-
make test
60+
docker compose exec constructo composer test
6261

6362
# Run specific test file (within Docker container)
6463
docker compose exec constructo vendor/bin/phpunit tests/Path/To/TestFile.php
6564

6665
# Run tests by filter/pattern (correct approach)
67-
docker compose exec constructo vendor/bin/phpunit --filter=TestClassName
6866
# Note: make test FILTER=TestName is NOT the correct command for filtering
67+
docker compose exec constructo vendor/bin/phpunit --filter=TestClassName
6968
```
7069

7170
### Test Structure and Patterns

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
"Constructo\\": "src/"
1212
},
1313
"files": [
14+
"src/_/@schemata.php",
1415
"src/_/cast.php",
1516
"src/_/crypt.php",
1617
"src/_/json.php",
1718
"src/_/notation.php",
19+
"src/_/polyfill.php",
1820
"src/_/util.php"
1921
]
2022
},
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
require_once __DIR__ . '/../../vendor/autoload.php';
66

7-
/**
8-
* @see tests/Examples/BuilderExamplesTest.php:testShouldBuildUserBasic
9-
*/
10-
117
use Constructo\Core\Serialize\Builder;
128
use Constructo\Support\Set;
139
use Constructo\Type\Timestamp;
@@ -36,9 +32,9 @@ public function __construct(
3632
// Crie um novo builder e use-o para construir o objeto
3733
$user = (new Builder())->build(User::class, $set);
3834

39-
echo "Usuário: \n";
40-
echo sprintf(" ID: %s\n", $user->id);
41-
echo sprintf(" Nome: %s\n", $user->name);
42-
echo sprintf(" Ativo: %s\n", $user->isActive);
43-
echo sprintf(" Tags: %s\n", implode(', ', $user->tags));
44-
echo sprintf(" Data de Nascimento: %s\n", $user->birthDate->format('Y-m-d'));
35+
echo "# Usuário: \n";
36+
echo sprintf("# ID: %s\n", $user->id);
37+
echo sprintf("# Nome: %s\n", $user->name);
38+
echo sprintf("# Ativo: %s\n", $user->isActive ? 'Sim' : 'Não');
39+
echo sprintf("# Tags: %s\n", implode(', ', $user->tags));
40+
echo sprintf("# Data de Nascimento: %s\n", $user->birthDate->format('Y-m-d'));

examples/demolisher/basic.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Examples\Demolisher;
4+
5+
require_once __DIR__ . '/../../vendor/autoload.php';
6+
7+
use Constructo\Core\Deserialize\Demolisher;
8+
use Constructo\Support\Set;
9+
use Constructo\Type\Timestamp;
10+
11+
// Defina sua entidade informando os valores das propriedades no construtor
12+
readonly class User
13+
{
14+
public function __construct(
15+
public int $id,
16+
public string $name,
17+
public Timestamp $birthDate,
18+
public bool $isActive = true,
19+
public array $tags = [],
20+
) {}
21+
}
22+
23+
// Instancie o objeto que deseja destruir
24+
$user = new User(
25+
id: 1,
26+
name: 'João Silva',
27+
birthDate: new Timestamp('1981-08-13'),
28+
isActive: true,
29+
tags: ['nice', 'welcome'],
30+
);
31+
32+
// Crie um novo demolisher e use-o para destruir o objeto
33+
$object = (new Demolisher())->demolish($user);
34+
35+
$set = Set::createFrom((array) $object);
36+
echo "# Usuário: \n";
37+
echo sprintf("# ID: %s\n", $set->get('id'));
38+
echo sprintf("# Nome: %s\n", $set->get('name'));
39+
echo sprintf("# Ativo: %s\n", $set->get('is_active') ? 'Sim' : 'Não');
40+
echo sprintf("# Tags: %s\n", implode(', ', $set->get('tags')));
41+
echo sprintf("# Data de Nascimento: %s\n", $set->get('birth_date'));

examples/reflector/basic.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Examples\Reflector;
4+
5+
require_once __DIR__ . '/../../vendor/autoload.php';
6+
7+
use Constructo\Factory\ReflectorFactory;
8+
use Constructo\Type\Timestamp;
9+
10+
use function array_export;
11+
12+
// Defina sua entidade informando os valores das propriedades no construtor
13+
readonly class User
14+
{
15+
public function __construct(
16+
public int $id,
17+
public string $name,
18+
public Timestamp $birthDate,
19+
public bool $isActive = true,
20+
public array $tags = [],
21+
) {
22+
}
23+
}
24+
25+
// Crie o reflector e obtenha o schema da entidade
26+
$schema = ReflectorFactory::createFrom()->make()->reflect(User::class);
27+
28+
echo "# Regras de validação \n";
29+
echo array_export($schema->rules(), 1);
30+
echo "\n";

src/Factory/ReflectorFactory.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
use Constructo\Contract\Reflect\TypesFactory;
88
use Constructo\Core\Reflect\Introspection\Introspector;
99
use Constructo\Core\Reflect\Reflector;
10+
use Constructo\Core\Serialize\Builder;
1011
use Constructo\Support\Cache;
1112
use Constructo\Support\Reflective\Notation;
13+
use Constructo\Testing\MakeExtension;
14+
15+
use function Constructo\Cast\arrayify;
1216

1317
readonly class ReflectorFactory
1418
{
19+
use MakeExtension;
20+
1521
public function __construct(
1622
private TypesFactory $typesFactory,
1723
private SchemaFactory $schemaFactory,
@@ -21,6 +27,22 @@ public function __construct(
2127
) {
2228
}
2329

30+
public static function createFrom(array $specs = [], array $types = [], Notation $notation = Notation::SNAKE): self
31+
{
32+
$schemata = CONSTRUCTO_SCHEMATA;
33+
$specs = array_merge(arrayify($schemata['specs'] ?? null), $specs);
34+
$types = array_merge(arrayify($schemata['types'] ?? null), $types);
35+
$builder = new Builder($notation);
36+
$specsFactory = new DefaultSpecsFactory($builder, $specs);
37+
return new self(
38+
new DefaultTypesFactory($types),
39+
new SchemaFactory($specsFactory),
40+
new Cache(),
41+
new Introspector(),
42+
$notation
43+
);
44+
}
45+
2446
public function make(): Reflector
2547
{
2648
$types = $this->typesFactory->make();

src/_/@schemata.php

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
use Constructo\Support\Metadata\Schema\Field\Formatter\MergeFormatter;
7+
use Constructo\Support\Metadata\Schema\Field\Formatter\PatternFormatter;
8+
9+
$schemata = [
10+
'specs' => [
11+
# Special setup
12+
'bail' => [],
13+
'sometimes' => [],
14+
15+
# Requirements
16+
'required_if' => [
17+
'params' => [
18+
'field',
19+
'value',
20+
],
21+
],
22+
'required_unless' => [
23+
'params' => [
24+
'field',
25+
'value',
26+
],
27+
],
28+
'required_with' => [
29+
'params' => '...',
30+
],
31+
'required_with_all' => [
32+
'params' => '...',
33+
],
34+
'required_without' => [
35+
'params' => '...',
36+
],
37+
'required_without_all' => [
38+
'params' => '...',
39+
],
40+
'required' => [],
41+
'nullable' => [],
42+
'filled' => [],
43+
'present' => [],
44+
45+
# Types
46+
'string' => ['kind' => 'type'],
47+
'integer' => ['kind' => 'type'],
48+
'numeric' => ['kind' => 'type'],
49+
'array' => ['kind' => 'type'],
50+
'boolean' => ['kind' => 'type'],
51+
'date' => ['kind' => 'type'],
52+
'json' => ['kind' => 'type'],
53+
'file' => ['kind' => 'type'],
54+
'image' => ['kind' => 'type'],
55+
'email' => ['kind' => 'type'],
56+
'url' => ['kind' => 'type'],
57+
'active_url' => ['kind' => 'type'],
58+
'uuid' => ['kind' => 'type'],
59+
'ip' => ['kind' => 'type'],
60+
'ipv4' => ['kind' => 'type'],
61+
'ipv6' => ['kind' => 'type'],
62+
'timezone' => ['kind' => 'type'],
63+
64+
# Constraints
65+
## Numbers constraints
66+
'min' => ['params' => ['min']],
67+
'max' => ['params' => ['max']],
68+
'between' => [
69+
'params' => [
70+
'min',
71+
'max',
72+
],
73+
],
74+
'digits' => ['params' => ['digits']],
75+
'digits_between' => [
76+
'params' => [
77+
'min',
78+
'max',
79+
],
80+
],
81+
## Among fields constraints
82+
'gt' => ['params' => ['field']],
83+
'gte' => ['params' => ['field']],
84+
'lt' => ['params' => ['field']],
85+
'lte' => ['params' => ['field']],
86+
'same' => ['params' => ['field']],
87+
'different' => ['params' => ['field']],
88+
'confirmed' => [],
89+
'distinct' => [],
90+
'in_array' => ['params' => ['field']],
91+
## String constraints
92+
'accepted' => [],
93+
'alpha' => [],
94+
'alpha_dash' => [],
95+
'alpha_num' => [],
96+
'starts_with' => [],
97+
## Date constraints
98+
'after' => ['params' => ['date']],
99+
'after_or_equal' => ['params' => ['date']],
100+
'before' => ['params' => ['date']],
101+
'before_or_equal' => ['params' => ['date']],
102+
'date_equals' => ['params' => ['date']],
103+
'date_format' => ['params' => ['format']],
104+
## Multiple types constraints
105+
'size' => ['params' => ['size']],
106+
## File constraints
107+
'mimes' => ['params' => '...'],
108+
'mimetypes' => ['params' => '...'],
109+
'dimensions' => ['params' => '...'],
110+
111+
# Database
112+
'unique' => [
113+
'params' => [
114+
'table',
115+
'column',
116+
'except',
117+
'id_column',
118+
],
119+
],
120+
'exists' => [
121+
'params' => [
122+
'table',
123+
'column',
124+
],
125+
],
126+
127+
# Behaviors
128+
'in' => [
129+
'formatter' => MergeFormatter::class,
130+
'params' => ['items'],
131+
],
132+
'not_in' => [
133+
'formatter' => MergeFormatter::class,
134+
'params' => ['items'],
135+
],
136+
'regex' => [
137+
'formatter' => PatternFormatter::class,
138+
'params' => [
139+
'pattern',
140+
'parameters:optional',
141+
],
142+
],
143+
'not_regex' => [
144+
'formatter' => PatternFormatter::class,
145+
'params' => [
146+
'pattern',
147+
'parameters:optional',
148+
],
149+
],
150+
],
151+
'types' => [
152+
'DateTime' => 'date',
153+
'DateTimeImmutable' => 'date',
154+
'DateTimeInterface' => 'date',
155+
],
156+
];
157+
158+
if (! defined('CONSTRUCTO_SCHEMATA')) {
159+
define('CONSTRUCTO_SCHEMATA', $schemata);
160+
}

0 commit comments

Comments
 (0)