Skip to content

Commit 560cd81

Browse files
ISSUE-193: Upgraded to PHP 7.2
1 parent 0eb4139 commit 560cd81

9 files changed

+80
-141
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/BooleanToValueTransformer.php

Lines changed: 7 additions & 5 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\SymfonyAddonTransformers;
2224

2325
use Symfony\Component\Form\DataTransformerInterface;
@@ -53,9 +55,9 @@ public function __construct($trueValue = true, $falseValue = false)
5355
/**
5456
* Transforms a value from the original representation to a transformed representation.
5557
*
56-
* @param bool $value
58+
* @param bool|null $value
5759
*
58-
* @return string|int|float|bool
60+
* @return string|int|float|bool|null
5961
*
6062
* @throws \Symfony\Component\Form\Exception\TransformationFailedException
6163
*/
@@ -75,13 +77,13 @@ public function transform($value)
7577
/**
7678
* Transforms a value from the transformed representation to its original representation.
7779
*
78-
* @param string|int|float|bool $value
80+
* @param string|int|float|bool|null $value
7981
*
80-
* @return bool
82+
* @return bool|null
8183
*
8284
* @throws \Symfony\Component\Form\Exception\TransformationFailedException
8385
*/
84-
public function reverseTransform($value)
86+
public function reverseTransform($value): ?bool
8587
{
8688
if (null === $value || '' === $value) {
8789
return null;

src/EntityToIdentifierTransformer.php

Lines changed: 5 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\SymfonyAddonTransformers;
2224

2325
use Doctrine\Common\Persistence\ObjectManager;
@@ -50,12 +52,9 @@ class EntityToIdentifierTransformer implements DataTransformerInterface
5052
/**
5153
* Constructor.
5254
*
53-
* @param \Doctrine\Common\Persistence\ObjectManager $entityManager
54-
* @param string $className
55-
*
5655
* @throws \Symfony\Component\Form\Exception\InvalidArgumentException
5756
*/
58-
public function __construct(ObjectManager $entityManager, $className)
57+
public function __construct(ObjectManager $entityManager, string $className)
5958
{
6059
$this->entityManager = $entityManager;
6160
$this->repository = $this->entityManager->getRepository($className);
@@ -102,11 +101,11 @@ public function transform($value)
102101
*
103102
* @param mixed $value
104103
*
105-
* @return object
104+
* @return object|null
106105
*
107106
* @throws \Symfony\Component\Form\Exception\TransformationFailedException
108107
*/
109-
public function reverseTransform($value)
108+
public function reverseTransform($value): ?object
110109
{
111110
if (null === $value || '' === $value) {
112111
return null;

tests/BooleanToValueTransformerTest.php

Lines changed: 19 additions & 26 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\SymfonyAddonTransformers\Tests;
2224

2325
use DarkWebDesign\SymfonyAddonTransformers\BooleanToValueTransformer;
@@ -27,12 +29,12 @@
2729
class BooleanToValueTransformerTest extends TestCase
2830
{
2931
/**
30-
* @param string $trueValue
31-
* @param string $falseValue
32+
* @param mixed $trueValue
33+
* @param mixed $falseValue
3234
*
3335
* @dataProvider providerTrueFalseValue
3436
*/
35-
public function testTransform($trueValue, $falseValue)
37+
public function testTransform($trueValue, $falseValue): void
3638
{
3739
$transformer = new BooleanToValueTransformer($trueValue, $falseValue);
3840

@@ -45,7 +47,7 @@ public function testTransform($trueValue, $falseValue)
4547
$this->assertSame($falseValue, $returnValue);
4648
}
4749

48-
public function testTransformNull()
50+
public function testTransformNull(): void
4951
{
5052
$transformer = new BooleanToValueTransformer();
5153

@@ -59,7 +61,7 @@ public function testTransformNull()
5961
*
6062
* @dataProvider providerNoBool
6163
*/
62-
public function testTransformNoBool($value)
64+
public function testTransformNoBool($value): void
6365
{
6466
$this->expectException(TransformationFailedException::class);
6567
$this->expectExceptionMessage('Expected a boolean.');
@@ -70,12 +72,12 @@ public function testTransformNoBool($value)
7072
}
7173

7274
/**
73-
* @param string $trueValue
74-
* @param string $falseValue
75+
* @param mixed $trueValue
76+
* @param mixed $falseValue
7577
*
7678
* @dataProvider providerTrueFalseValue
7779
*/
78-
public function testReverseTransform($trueValue, $falseValue)
80+
public function testReverseTransform($trueValue, $falseValue): void
7981
{
8082
$transformer = new BooleanToValueTransformer($trueValue, $falseValue);
8183

@@ -88,7 +90,7 @@ public function testReverseTransform($trueValue, $falseValue)
8890
$this->assertFalse($returnValue);
8991
}
9092

91-
public function testReverseTransformNull()
93+
public function testReverseTransformNull(): void
9294
{
9395
$transformer = new BooleanToValueTransformer();
9496

@@ -97,7 +99,7 @@ public function testReverseTransformNull()
9799
$this->assertNull($returnValue);
98100
}
99101

100-
public function testReverseTransformEmptyString()
102+
public function testReverseTransformEmptyString(): void
101103
{
102104
$transformer = new BooleanToValueTransformer();
103105

@@ -111,7 +113,7 @@ public function testReverseTransformEmptyString()
111113
*
112114
* @dataProvider providerNoScalar
113115
*/
114-
public function testReverseTransformNoScalar($value)
116+
public function testReverseTransformNoScalar($value): void
115117
{
116118
$this->expectException(TransformationFailedException::class);
117119
$this->expectExceptionMessage('Expected a scalar.');
@@ -122,12 +124,12 @@ public function testReverseTransformNoScalar($value)
122124
}
123125

124126
/**
125-
* @param string $trueValue
126-
* @param string $falseValue
127+
* @param mixed $trueValue
128+
* @param mixed $falseValue
127129
*
128130
* @dataProvider providerTrueFalseValue
129131
*/
130-
public function testReverseTransformInvalidValue($trueValue, $falseValue)
132+
public function testReverseTransformInvalidValue($trueValue, $falseValue): void
131133
{
132134
$this->expectException(TransformationFailedException::class);
133135
$this->expectExceptionMessage('Expected true/false boolean value.');
@@ -137,10 +139,7 @@ public function testReverseTransformInvalidValue($trueValue, $falseValue)
137139
$transformer->reverseTransform('foo');
138140
}
139141

140-
/**
141-
* @return array[]
142-
*/
143-
public function providerTrueFalseValue()
142+
public function providerTrueFalseValue(): array
144143
{
145144
return [
146145
'true/false' => [true, false],
@@ -150,10 +149,7 @@ public function providerTrueFalseValue()
150149
];
151150
}
152151

153-
/**
154-
* @return array[]
155-
*/
156-
public function providerNoBool()
152+
public function providerNoBool(): array
157153
{
158154
return [
159155
'int' => [1],
@@ -166,10 +162,7 @@ public function providerNoBool()
166162
];
167163
}
168164

169-
/**
170-
* @return array[]
171-
*/
172-
public function providerNoScalar()
165+
public function providerNoScalar(): array
173166
{
174167
return [
175168
'array' => [['foo', 'bar']],

tests/EntityToIdentifierTransformerTest.php

Lines changed: 21 additions & 31 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\SymfonyAddonTransformers\Tests;
2224

2325
use DarkWebDesign\SymfonyAddonTransformers\EntityToIdentifierTransformer;
@@ -43,13 +45,13 @@ class EntityToIdentifierTransformerTest extends TestCase
4345
/** @var int */
4446
private $identifier;
4547

46-
/** @var \Doctrine\Common\Persistence\ObjectManager|\PHPUnit_Framework_MockObject_MockObject */
48+
/** @var \Doctrine\Common\Persistence\ObjectManager|\PHPUnit\Framework\MockObject\MockObject */
4749
private $entityManager;
4850

49-
/** @var \Doctrine\Common\Persistence\ObjectRepository|\PHPUnit_Framework_MockObject_MockObject */
51+
/** @var \Doctrine\Common\Persistence\ObjectRepository|\PHPUnit\Framework\MockObject\MockObject */
5052
private $repository;
5153

52-
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */
54+
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata|\PHPUnit\Framework\MockObject\MockObject */
5355
private $metadata;
5456

5557
protected function setUp(): void
@@ -73,23 +75,17 @@ protected function setUp(): void
7375
$this->metadata->isIdentifierComposite = false;
7476
}
7577

76-
/**
77-
* @return string
78-
*/
79-
public function getClassName()
78+
public function getClassName(): string
8079
{
8180
return $this->className;
8281
}
8382

84-
/**
85-
* @return array
86-
*/
87-
public function getIdentifier()
83+
public function getIdentifier(): array
8884
{
8985
return ['id' => $this->identifier];
9086
}
9187

92-
public function testConstructIdentifierComposite()
88+
public function testConstructIdentifierComposite(): void
9389
{
9490
$this->expectException(InvalidArgumentException::class);
9591
$this->expectExceptionMessage('Expected an entity with a single identifier.');
@@ -99,7 +95,7 @@ public function testConstructIdentifierComposite()
9995
new EntityToIdentifierTransformer($this->entityManager, $this->className);
10096
}
10197

102-
public function testTransform()
98+
public function testTransform(): void
10399
{
104100
$transformer = new EntityToIdentifierTransformer($this->entityManager, $this->className);
105101

@@ -108,7 +104,7 @@ public function testTransform()
108104
$this->assertSame($this->identifier, $identifier);
109105
}
110106

111-
public function testTransformAlias()
107+
public function testTransformAlias(): void
112108
{
113109
$transformer = new EntityToIdentifierTransformer($this->entityManager, 'AppBundle:City');
114110

@@ -117,7 +113,7 @@ public function testTransformAlias()
117113
$this->assertSame($this->identifier, $identifier);
118114
}
119115

120-
public function testTransformDiscriminated()
116+
public function testTransformDiscriminated(): void
121117
{
122118
$this->className = AbstractPerson::class;
123119

@@ -130,7 +126,7 @@ public function testTransformDiscriminated()
130126
$this->assertSame($this->identifier, $identifier);
131127
}
132128

133-
public function testTransformNull()
129+
public function testTransformNull(): void
134130
{
135131
$transformer = new EntityToIdentifierTransformer($this->entityManager, $this->className);
136132

@@ -144,7 +140,7 @@ public function testTransformNull()
144140
*
145141
* @dataProvider providerNoObject
146142
*/
147-
public function testTransformNoObject($value)
143+
public function testTransformNoObject($value): void
148144
{
149145
$this->expectException(TransformationFailedException::class);
150146
$this->expectExceptionMessage('Expected an object.');
@@ -154,7 +150,7 @@ public function testTransformNoObject($value)
154150
$transformer->transform($value);
155151
}
156152

157-
public function testTransformInvalidEntity()
153+
public function testTransformInvalidEntity(): void
158154
{
159155
$this->expectException(TransformationFailedException::class);
160156
$this->expectExceptionMessage('Expected entity DarkWebDesign\SymfonyAddonTransformers\Tests\Models\City.');
@@ -166,7 +162,7 @@ public function testTransformInvalidEntity()
166162
$transformer->transform($entity);
167163
}
168164

169-
public function testReverseTransform()
165+
public function testReverseTransform(): void
170166
{
171167
$transformer = new EntityToIdentifierTransformer($this->entityManager, $this->className);
172168

@@ -177,7 +173,7 @@ public function testReverseTransform()
177173
$this->assertSame($this->identifier, $entity->getId());
178174
}
179175

180-
public function testReverseTransformNull()
176+
public function testReverseTransformNull(): void
181177
{
182178
$transformer = new EntityToIdentifierTransformer($this->entityManager, $this->className);
183179

@@ -186,7 +182,7 @@ public function testReverseTransformNull()
186182
$this->assertNull($entity);
187183
}
188184

189-
public function testReverseTransformEmptyString()
185+
public function testReverseTransformEmptyString(): void
190186
{
191187
$transformer = new EntityToIdentifierTransformer($this->entityManager, $this->className);
192188

@@ -200,7 +196,7 @@ public function testReverseTransformEmptyString()
200196
*
201197
* @dataProvider providerNoScalar
202198
*/
203-
public function testReverseTransformNoScalar($value)
199+
public function testReverseTransformNoScalar($value): void
204200
{
205201
$this->expectException(TransformationFailedException::class);
206202
$this->expectExceptionMessage('Expected a scalar.');
@@ -210,7 +206,7 @@ public function testReverseTransformNoScalar($value)
210206
$transformer->reverseTransform($value);
211207
}
212208

213-
public function testReverseTransformEntityNotFound()
209+
public function testReverseTransformEntityNotFound(): void
214210
{
215211
$this->expectException(TransformationFailedException::class);
216212
$this->expectExceptionMessage('Entity DarkWebDesign\SymfonyAddonTransformers\Tests\Models\City with identifier "123" not found.');
@@ -222,10 +218,7 @@ public function testReverseTransformEntityNotFound()
222218
$transformer->reverseTransform($this->identifier);
223219
}
224220

225-
/**
226-
* @return array[]
227-
*/
228-
public function providerNoObject()
221+
public function providerNoObject(): array
229222
{
230223
return [
231224
'bool' => [true],
@@ -238,10 +231,7 @@ public function providerNoObject()
238231
];
239232
}
240233

241-
/**
242-
* @return array[]
243-
*/
244-
public function providerNoScalar()
234+
public function providerNoScalar(): array
245235
{
246236
return [
247237
'array' => [['foo', 'bar']],

0 commit comments

Comments
 (0)