Skip to content

Commit bd3ecc1

Browse files
add rector
1 parent 9ff15a6 commit bd3ecc1

30 files changed

Lines changed: 331 additions & 173 deletions

.github/workflows/build.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
name: Build Symftony/form-handler
2-
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
2+
run-name: 🧑‍💻${{ github.actor }} Run build.
33
on: [ push ]
44
jobs:
55
Build:
6-
name: PHP ${{ matrix.php-versions }}
6+
name: PHP ${{ matrix.php-versions }} // composer ${{ matrix.composer-command }}
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
1010
php-versions: [ '8.1', '8.2', '8.3' ]
11+
composer-command:
12+
- 'install'
13+
- 'update --prefer-lowest'
1114
steps:
1215
- name: Checkout
1316
uses: actions/checkout@v4
@@ -17,7 +20,6 @@ jobs:
1720
with:
1821
php-version: ${{ matrix.php-versions }}
1922
coverage: xdebug
20-
tools: php-cs-fixer, phpunit, phpstan
2123

2224
- name: "Composer -> Get cache directory"
2325
id: composer-cache
@@ -31,16 +33,22 @@ jobs:
3133
restore-keys: ${{ runner.os }}-composer-
3234

3335
- name: "Composer -> Install dependencies"
34-
run: composer install --no-progress --prefer-dist --optimize-autoloader
36+
run: composer ${{ matrix.composer-command }} --no-progress --prefer-dist --optimize-autoloader
37+
38+
- name: "Composer -> Show"
39+
run: composer show
3540

3641
- name: "Composer -> check platform requirements"
3742
run: composer check-platform-reqs
3843

44+
# - name: "Rector -> Run"
45+
# run: rector --dry-run
46+
3947
- name: "PHP cs fixer -> check"
40-
run: php-cs-fixer check src
48+
run: vendor/bin/php-cs-fixer check src
4149

4250
- name: "PHPStan -> Run"
43-
run: phpstan analyse src
51+
run: vendor/bin/phpstan analyse src
4452

4553
- name: "PHPUnit -> Run"
46-
run: phpunit --coverage-text
54+
run: vendor/bin/phpunit --coverage-text

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
"symfony/translation": "^6.1",
2525
"symfony/contracts": "^3.5@dev",
2626
"symfony/validator": "^6.1",
27-
"phpstan/phpstan": "2.0.x-dev",
28-
"friendsofphp/php-cs-fixer": "dev-master"
27+
"phpstan/phpstan": "^1.11",
28+
"friendsofphp/php-cs-fixer": "dev-master",
29+
"rector/rector": "dev-main"
2930
},
3031
"suggest": {
3132
"symfony/dependency-injection": "^6.1",

examples/CustomFormHandler.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Example;
46

57
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -8,10 +10,7 @@
810

911
class CustomFormHandler extends FormHandler
1012
{
11-
/**
12-
* @return \Symfony\Component\Form\FormInterface
13-
*/
14-
public function formChoice()
13+
public function formChoice(): \Symfony\Component\Form\FormInterface
1514
{
1615
return $this->createForm(ChoiceType::class, 'my-value', null, [
1716
'method' => 'GET',
@@ -30,7 +29,7 @@ public function formChoice()
3029
]);
3130
}
3231

33-
public function createFromRequest($request = null, $notSubmitted = true, $invalid = true)
32+
public function createFromRequest(?mixed $request = null, $notSubmitted = true, $invalid = true)
3433
{
3534
$form = $this->createForm(ChoiceType::class, 'my-value', null, [
3635
'method' => 'GET',
@@ -49,4 +48,4 @@ public function createFromRequest($request = null, $notSubmitted = true, $invali
4948

5049
return $this->handleRequest($form, $request);
5150
}
52-
}
51+
}

examples/custom-form-api.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Example;
46

57
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once 'CustomFormHandler.php';
8+
require_once __DIR__ . '/CustomFormHandler.php';
79
use Symftony\FormHandler\Exception\FormException;
810
use Symftony\FormHandler\Form\Extension\Invalid\Type\InvalidTypeExtension;
911
use Symftony\FormHandler\Form\Extension\NotSubmitted\Type\NotSubmittedTypeExtension;
1012
use Symftony\FormHandler\Form\Extension\TransformationFailed\Type\TransformationFailedTypeExtension;
1113
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
1214
use Symfony\Component\Form\Forms;
1315
use Symfony\Component\Validator\Validation;
14-
1516
// Initialize form component
1617
// add not submitted type extension
1718
// add invalid type extension
@@ -22,26 +23,26 @@
2223
->addTypeExtension(new TransformationFailedTypeExtension())
2324
->addExtension(new ValidatorExtension(Validation::createValidator()))
2425
->getFormFactory();
25-
2626
// Initialize form handler
2727
$formHandler = new CustomFormHandler();
2828
$formHandler->setFormFactory($formFactory);
29-
3029
// Create the form
3130
// Handle request
3231
$exception = null;
3332
try {
3433
$result = $formHandler->createFromRequest();
35-
} catch (FormException $e) {
36-
$exception = $e;
34+
} catch (FormException $formException) {
35+
$exception = $formException;
3736
}
3837
?>
3938
<html>
4039
<head>
4140
<title>Form handler throw NotSubmitted/Invalid Exception example</title>
4241
</head>
4342
<body>
44-
<?php include 'menu.php'; ?>
43+
<?php
44+
include __DIR__ . '/menu.php';
45+
?>
4546
<div class="container">
4647
<h1>Form handler will return default data when exception append</h1>
4748
<div class="content">
@@ -67,13 +68,22 @@
6768

6869
<p class="important">/!\ When you use the handler to do some API you dont need the form in your controller. You just need your data or Exception /!\</p>
6970
<div class="formdebug">
70-
<code>$formHandler->handleRequest($form) : <?php if (isset($result)) var_export($result); ?>
71-
<?php if (null !== $exception): ?>
72-
<span class="error"><?= get_class($exception) . ' : ' . $exception->getMessage() ?></span>
71+
<code>$formHandler->handleRequest($form) : <?php
72+
if (isset($result)) {
73+
var_export($result);
74+
}
75+
76+
?>
77+
<?php
78+
if ($exception instanceof \Symftony\FormHandler\Exception\FormException): ?>
79+
<span class="error"><?= $exception::class . ' : ' . $exception->getMessage() ?></span>
7380
<?php endif ?>
81+
82+
?>
7483
</code>
7584
</div>
7685
</div>
7786
</div>
7887
</body>
7988
</html>
89+
<?php

examples/custom-form-web.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Example;
46

57
require_once __DIR__ . '/../vendor/autoload.php';
6-
require_once 'CustomFormHandler.php';
8+
require_once __DIR__ . '/CustomFormHandler.php';
79
use Symftony\FormHandler\Exception\FormException;
810
use Symftony\FormHandler\Form\Extension\Invalid\Type\InvalidTypeExtension;
911
use Symftony\FormHandler\Form\Extension\NotSubmitted\Type\NotSubmittedTypeExtension;
1012
use Symftony\FormHandler\Form\Extension\TransformationFailed\Type\TransformationFailedTypeExtension;
1113
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
1214
use Symfony\Component\Form\Forms;
1315
use Symfony\Component\Validator\Validation;
14-
1516
// Initialize form component
1617
// add not submitted type extension
1718
// add invalid type extension
@@ -22,27 +23,27 @@
2223
->addTypeExtension(new TransformationFailedTypeExtension())
2324
->addExtension(new ValidatorExtension(Validation::createValidator()))
2425
->getFormFactory();
25-
2626
// Initialize form handler
2727
$formHandler = new CustomFormHandler();
2828
$formHandler->setFormFactory($formFactory);
29-
3029
// Create the form
3130
$form = $formHandler->formChoice();
3231
// Handle request
3332
$exception = null;
3433
try {
3534
$result = $formHandler->handleRequest($form);
36-
} catch (FormException $e) {
37-
$exception = $e;
35+
} catch (FormException $formException) {
36+
$exception = $formException;
3837
}
3938
?>
4039
<html>
4140
<head>
4241
<title>Form handler throw NotSubmitted/Invalid Exception example</title>
4342
</head>
4443
<body>
45-
<?php include 'menu.php'; ?>
44+
<?php
45+
include __DIR__ . '/menu.php';
46+
?>
4647
<div class="container">
4748
<h1>Form handler will return default data when exception append</h1>
4849
<div class="content">
@@ -67,23 +68,41 @@
6768
</form>
6869

6970
<div class="formdebug">
70-
<code>$form->isSubmitted() : <?= var_export($form->isSubmitted()) ?></code>
71-
<code>$form->isValid() : <?= $form->isSubmitted() &&var_export($form->isValid()) ?></code>
71+
<code>$form->isSubmitted() : <?php
72+
<?= var_export($form->isSubmitted()) ?>
73+
?></code>
74+
<code>$form->isValid() : <?php
75+
<?= $form->isSubmitted() &&var_export($form->isValid()) ?>
76+
?></code>
7277
<code>$form->getTransformationFailure() :
73-
<?php if ($form->getTransformationFailure()): ?>
78+
<?php
79+
if ($form->getTransformationFailure()): ?>
7480
<span class="warning"><?= $form->getTransformationFailure()->getMessage(); ?></span>
7581
<?php else: ?>
7682
null
7783
<?php endif ?>
84+
85+
?>
7886
</code>
79-
<code>$form->getData() : <?= var_export($form->getData()); ?></code>
80-
<code>$formHandler->handleRequest($form) : <?php if (isset($result)) var_export($result); ?>
81-
<?php if (null !== $exception): ?>
87+
<code>$form->getData() : <?php
88+
<?= var_export($form->getData());
89+
?></code>
90+
<code>$formHandler->handleRequest($form) : <?php
91+
if (isset($result)) {
92+
var_export($result);
93+
}
94+
95+
?>
96+
<?php
97+
if ($exception instanceof \Symftony\FormHandler\Exception\FormException): ?>
8298
<span class="error"><?= get_class($exception) . ' : ' . $exception->getMessage() ?></span>
8399
<?php endif ?>
100+
101+
?>
84102
</code>
85103
</div>
86104
</div>
87105
</div>
88106
</body>
89107
</html>
108+
<?php

examples/default-return.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Example;
46

57
require_once __DIR__ . '/../vendor/autoload.php';
6-
78
use Symfony\Component\Validator\Constraints\Choice;
89
use Symftony\FormHandler\Exception\FormException;
910
use Symftony\FormHandler\Form\Extension\Invalid\Type\InvalidTypeExtension;
@@ -14,7 +15,6 @@
1415
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
1516
use Symfony\Component\Form\Forms;
1617
use Symfony\Component\Validator\Validation;
17-
1818
// Initialize form component
1919
// add not submitted type extension
2020
// add invalid type extension
@@ -25,11 +25,9 @@
2525
->addTypeExtension(new TransformationFailedTypeExtension())
2626
->addExtension(new ValidatorExtension(Validation::createValidator()))
2727
->getFormFactory();
28-
2928
// Initialize form handler
3029
$formHandler = new FormHandler();
3130
$formHandler->setFormFactory($formFactory);
32-
3331
// Create the form
3432
$form = $formHandler->createForm(ChoiceType::class, 'my-value', null, [
3533
'method' => 'GET',
@@ -46,21 +44,22 @@
4644
'handler_not_submitted' => 'not submitted return data',
4745
'handler_transformation_failed' => 'transformation fail return data',
4846
]);
49-
5047
// Handle request
5148
$exception = null;
5249
try {
5350
$result = $formHandler->handleRequest($form);
54-
} catch (FormException $e) {
55-
$exception = $e;
51+
} catch (FormException $formException) {
52+
$exception = $formException;
5653
}
5754
?>
5855
<html>
5956
<head>
6057
<title>Form handler throw NotSubmitted/Invalid Exception example</title>
6158
</head>
6259
<body>
63-
<?php include 'menu.php'; ?>
60+
<?php
61+
include __DIR__ . '/menu.php';
62+
?>
6463
<div class="container">
6564
<h1>Form handler will return default data when exception append</h1>
6665
<div class="content">
@@ -85,23 +84,41 @@
8584
</form>
8685

8786
<div class="formdebug">
88-
<code>$form->isSubmitted() : <?= var_export($form->isSubmitted()) ?></code>
89-
<code>$form->isValid() : <?= $form->isSubmitted() && var_export($form->isValid()) ?></code>
87+
<code>$form->isSubmitted() : <?php
88+
<?= var_export($form->isSubmitted()) ?>
89+
?></code>
90+
<code>$form->isValid() : <?php
91+
<?= $form->isSubmitted() && var_export($form->isValid()) ?>
92+
?></code>
9093
<code>$form->getTransformationFailure() :
91-
<?php if ($form->getTransformationFailure()): ?>
94+
<?php
95+
if ($form->getTransformationFailure() instanceof \Symfony\Component\Form\Exception\TransformationFailedException): ?>
9296
<span class="warning"><?= $form->getTransformationFailure()->getMessage(); ?></span>
9397
<?php else: ?>
9498
null
9599
<?php endif ?>
100+
101+
?>
96102
</code>
97-
<code>$form->getData() : <?= var_export($form->getData()); ?></code>
98-
<code>$formHandler->handleRequest($form) : <?php if (isset($result)) var_export($result); ?>
99-
<?php if (null !== $exception): ?>
103+
<code>$form->getData() : <?php
104+
<?= var_export($form->getData());
105+
?></code>
106+
<code>$formHandler->handleRequest($form) : <?php
107+
if (isset($result)) {
108+
var_export($result);
109+
}
110+
111+
?>
112+
<?php
113+
if ($exception instanceof \Symftony\FormHandler\Exception\FormException): ?>
100114
<span class="error"><?= get_class($exception) . ' : ' . $exception->getMessage() ?></span>
101115
<?php endif ?>
116+
117+
?>
102118
</code>
103119
</div>
104120
</div>
105121
</div>
106122
</body>
107123
</html>
124+
<?php

0 commit comments

Comments
 (0)