Skip to content

Commit cf7a012

Browse files
ISSUE-193: Upgraded to PHP 7.2
1 parent 1a7f7b6 commit cf7a012

File tree

10 files changed

+57
-84
lines changed

10 files changed

+57
-84
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.phpunit.result.cache
2+
/build/
23
/composer.lock
34
/vendor/

src/BirthdayType.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes;
2224

2325
use Symfony\Component\Form\AbstractType;
@@ -35,10 +37,8 @@ class BirthdayType extends AbstractType
3537
{
3638
/**
3739
* Configures the options for this type.
38-
*
39-
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
4040
*/
41-
public function configureOptions(OptionsResolver $resolver)
41+
public function configureOptions(OptionsResolver $resolver): void
4242
{
4343
$resolver->setDefaults([
4444
'years' => range(date('Y'), date('Y') - 120),
@@ -47,10 +47,8 @@ public function configureOptions(OptionsResolver $resolver)
4747

4848
/**
4949
* Returns the name of the parent type.
50-
*
51-
* @return string
5250
*/
53-
public function getParent()
51+
public function getParent(): string
5452
{
5553
return DateType::class;
5654
}

src/BooleanType.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes;
2224

2325
use DarkWebDesign\SymfonyAddonTransformers\BooleanToValueTransformer;
@@ -38,28 +40,23 @@ class BooleanType extends AbstractType
3840
{
3941
/**
4042
* Builds the form.
41-
*
42-
* @param \Symfony\Component\Form\FormBuilderInterface $builder
43-
* @param array $options
4443
*/
45-
public function buildForm(FormBuilderInterface $builder, array $options)
44+
public function buildForm(FormBuilderInterface $builder, array $options): void
4645
{
4746
$builder->addModelTransformer(new BooleanToValueTransformer($options['value_true'], $options['value_false']));
4847
}
4948

5049
/**
5150
* Configures the options for this type.
52-
*
53-
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
5451
*/
55-
public function configureOptions(OptionsResolver $resolver)
52+
public function configureOptions(OptionsResolver $resolver): void
5653
{
5754
$labelTrueNormalizer = function (Options $options, $value) {
58-
return !is_null($value) ? (string) $value : $this->humanize($options['value_true']);
55+
return !is_null($value) ? (string) $value : $this->humanize((string) $options['value_true']);
5956
};
6057

6158
$labelFalseNormalizer = function (Options $options, $value) {
62-
return !is_null($value) ? (string) $value : $this->humanize($options['value_false']);
59+
return !is_null($value) ? (string) $value : $this->humanize((string) $options['value_false']);
6360
};
6461

6562
$choicesNormalizer = function (Options $options) {
@@ -101,22 +98,16 @@ public function configureOptions(OptionsResolver $resolver)
10198

10299
/**
103100
* Returns the name of the parent type.
104-
*
105-
* @return string
106101
*/
107-
public function getParent()
102+
public function getParent(): string
108103
{
109104
return ChoiceType::class;
110105
}
111106

112107
/**
113108
* Makes a technical name human readable.
114-
*
115-
* @param string $text
116-
*
117-
* @return string
118109
*/
119-
public function humanize($text)
110+
public function humanize(string $text): string
120111
{
121112
return ucfirst(trim(strtolower(preg_replace(['/([A-Z])/', '/[_\s]+/'], ['_$1', ' '], $text))));
122113
}

src/EntityType.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes;
2224

2325
use DarkWebDesign\SymfonyAddonTransformers\EntityToIdentifierTransformer;
@@ -51,21 +53,16 @@ public function __construct(ManagerRegistry $registry)
5153

5254
/**
5355
* Builds the form.
54-
*
55-
* @param \Symfony\Component\Form\FormBuilderInterface $builder
56-
* @param array $options
5756
*/
58-
public function buildForm(FormBuilderInterface $builder, array $options)
57+
public function buildForm(FormBuilderInterface $builder, array $options): void
5958
{
6059
$builder->addViewTransformer(new EntityToIdentifierTransformer($options['entity_manager'], $options['class']));
6160
}
6261

6362
/**
6463
* Configures the options for this type.
65-
*
66-
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
6764
*/
68-
public function configureOptions(OptionsResolver $resolver)
65+
public function configureOptions(OptionsResolver $resolver): void
6966
{
7067
$registry = $this->registry;
7168

src/UnstructuredType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes;
2224

2325
use Symfony\Component\Form\AbstractType;
@@ -34,10 +36,8 @@ class UnstructuredType extends AbstractType
3436
{
3537
/**
3638
* Configures the options for this type.
37-
*
38-
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
3939
*/
40-
public function configureOptions(OptionsResolver $resolver)
40+
public function configureOptions(OptionsResolver $resolver): void
4141
{
4242
$compoundNormalizer = function () {
4343
return false;

tests/BirthdayTypeTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes\Tests;
2224

2325
use DarkWebDesign\SymfonyAddonFormTypes\BirthdayType;
2426
use Symfony\Component\Form\Test\TypeTestCase;
2527

2628
class BirthdayTypeTest extends TypeTestCase
2729
{
28-
public function test()
30+
public function test(): void
2931
{
3032
$form = $this->factory->create(BirthdayType::class);
3133

tests/BooleanTypeTest.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes\Tests;
2224

2325
use DarkWebDesign\SymfonyAddonFormTypes\BooleanType;
@@ -26,12 +28,12 @@
2628
class BooleanTypeTest extends TypeTestCase
2729
{
2830
/**
29-
* @param string $valueTrue
30-
* @param string $valueFalse
31+
* @param mixed $valueTrue
32+
* @param mixed $valueFalse
3133
*
3234
* @dataProvider providerValueTrueFalse
3335
*/
34-
public function test($valueTrue, $valueFalse)
36+
public function test($valueTrue, $valueFalse): void
3537
{
3638
$options = [
3739
'value_true' => $valueTrue,
@@ -52,12 +54,12 @@ public function test($valueTrue, $valueFalse)
5254
}
5355

5456
/**
55-
* @param string $valueTrue
56-
* @param string $valueFalse
57+
* @param mixed $valueTrue
58+
* @param mixed $valueFalse
5759
*
5860
* @dataProvider providerValueTrueFalse
5961
*/
60-
public function testInvalidValue($valueTrue, $valueFalse)
62+
public function testInvalidValue($valueTrue, $valueFalse): void
6163
{
6264
$options = [
6365
'value_true' => $valueTrue,
@@ -72,12 +74,9 @@ public function testInvalidValue($valueTrue, $valueFalse)
7274
}
7375

7476
/**
75-
* @param string $widget
76-
* @param bool $expanded
77-
*
7877
* @dataProvider providerWidget
7978
*/
80-
public function testWidget($widget, $expanded)
79+
public function testWidget(string $widget, bool $expanded): void
8180
{
8281
$options = [
8382
'widget' => $widget,
@@ -90,7 +89,7 @@ public function testWidget($widget, $expanded)
9089
$this->assertFalse($view->vars['multiple']);
9190
}
9291

93-
public function testHumanize()
92+
public function testHumanize(): void
9493
{
9594
$options = [
9695
'value_true' => 'an_underscored__label',
@@ -105,10 +104,7 @@ public function testHumanize()
105104
$this->assertSame('A camel cased label', $view->vars['choices'][1]->label);
106105
}
107106

108-
/**
109-
* @return array[]
110-
*/
111-
public function providerValueTrueFalse()
107+
public function providerValueTrueFalse(): array
112108
{
113109
return [
114110
'true/false' => ['true', 'false'],
@@ -120,10 +116,7 @@ public function providerValueTrueFalse()
120116
];
121117
}
122118

123-
/**
124-
* @return array[]
125-
*/
126-
public function providerWidget()
119+
public function providerWidget(): array
127120
{
128121
return [
129122
'choice' => ['choice', false],

tests/EntityTypeTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes\Tests;
2224

2325
use DarkWebDesign\SymfonyAddonFormTypes\EntityType;
@@ -42,16 +44,16 @@ class EntityTypeTest extends TypeTestCase
4244
/** @var int */
4345
private $identifier;
4446

45-
/** @var \Doctrine\Common\Persistence\ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject */
47+
/** @var \Doctrine\Common\Persistence\ManagerRegistry|\PHPUnit\Framework\MockObject\MockObject */
4648
private $registry;
4749

48-
/** @var \Doctrine\Common\Persistence\ObjectManager|\PHPUnit_Framework_MockObject_MockObject */
50+
/** @var \Doctrine\Common\Persistence\ObjectManager|\PHPUnit\Framework\MockObject\MockObject */
4951
private $entityManager;
5052

51-
/** @var \Doctrine\Common\Persistence\ObjectRepository|\PHPUnit_Framework_MockObject_MockObject */
53+
/** @var \Doctrine\Common\Persistence\ObjectRepository|\PHPUnit\Framework\MockObject\MockObject */
5254
private $repository;
5355

54-
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */
56+
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata|\PHPUnit\Framework\MockObject\MockObject */
5557
private $metadata;
5658

5759
protected function setUp(): void
@@ -78,10 +80,7 @@ protected function setUp(): void
7880
parent::setUp();
7981
}
8082

81-
/**
82-
* @return array
83-
*/
84-
protected function getExtensions()
83+
protected function getExtensions(): array
8584
{
8685
$type = new EntityType($this->registry);
8786

@@ -90,7 +89,7 @@ protected function getExtensions()
9089
];
9190
}
9291

93-
public function test()
92+
public function test(): void
9493
{
9594
$this->registry->method('getManagerForClass')->willReturn($this->entityManager);
9695

@@ -107,7 +106,7 @@ public function test()
107106
$this->assertSame($this->entity, $form->getData());
108107
}
109108

110-
public function testEntityNotFound()
109+
public function testEntityNotFound(): void
111110
{
112111
$this->registry->method('getManagerForClass')->willReturn($this->entityManager);
113112

@@ -124,7 +123,7 @@ public function testEntityNotFound()
124123
$this->assertNull($form->getData());
125124
}
126125

127-
public function testEntityManagerObject()
126+
public function testEntityManagerObject(): void
128127
{
129128
$this->repository->method('find')->willReturn($this->entity);
130129

@@ -140,7 +139,7 @@ public function testEntityManagerObject()
140139
$this->assertSame($this->entity, $form->getData());
141140
}
142141

143-
public function testEntityManagerString()
142+
public function testEntityManagerString(): void
144143
{
145144
$this->registry->method('getManager')->willReturn($this->entityManager);
146145

@@ -158,7 +157,7 @@ public function testEntityManagerString()
158157
$this->assertSame($this->entity, $form->getData());
159158
}
160159

161-
public function testNoEntityManager()
160+
public function testNoEntityManager(): void
162161
{
163162
$this->expectException(RuntimeException::class);
164163
$this->expectExceptionMessage('Class "DarkWebDesign\SymfonyAddonFormTypes\Tests\Models\City" seems not to be a managed Doctrine entity. Did you forget to map it?');

tests/Models/City.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* SOFTWARE.
1919
*/
2020

21+
declare(strict_types=1);
22+
2123
namespace DarkWebDesign\SymfonyAddonFormTypes\Tests\Models;
2224

2325
/**
@@ -45,34 +47,22 @@ class City
4547
*/
4648
private $name;
4749

48-
/**
49-
* @return int
50-
*/
51-
public function getId()
50+
public function getId(): ?int
5251
{
5352
return $this->id;
5453
}
5554

56-
/**
57-
* @param int $id
58-
*/
59-
public function setId($id)
55+
public function setId(int $id): void
6056
{
6157
$this->id = $id;
6258
}
6359

64-
/**
65-
* @return string
66-
*/
67-
public function getName()
60+
public function getName(): ?string
6861
{
6962
return $this->name;
7063
}
7164

72-
/**
73-
* @param string $name
74-
*/
75-
public function setName($name)
65+
public function setName(string $name): void
7666
{
7767
$this->name = $name;
7868
}

0 commit comments

Comments
 (0)