Skip to content

Commit 914ed49

Browse files
committed
cs
1 parent 866f9a7 commit 914ed49

File tree

5 files changed

+38
-49
lines changed

5 files changed

+38
-49
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ of external values without wrapping them in an instance.
101101
If it returns true, a new object can be instantiated with that value.
102102
Implement this in every subclass!
103103

104-
* <code>final public function <b>value</b>()</code>
104+
* <code>final public function <b>value</b>(): mixed</code>
105105

106106
Returns the object's wrapped initializer value.
107107

108-
* <code>final public function <b>equals</b>($test\_value)</code>
108+
* <code>final public function <b>equals</b>($test\_value): bool</code>
109109

110110
Equality test.
111111
This method performs an equality check on other instances or raw values.
@@ -140,12 +140,12 @@ of external values without wrapping them in an instance.
140140
This extension of `AbstractValue` provides easy serializability for the Value objects.
141141
It implements the [JsonSerializable](https://php.net/manual/class.jsonserializable.php) interface.
142142

143-
* <code>public function <b>\_\_toString</b> (): string</code>
143+
* <code>public function <b>\_\_toString</b>(): string</code>
144144

145145
Returns the wrapped value like `value()`, but with an explicit
146146
`string` typecast. This allows string concatenation of Value objects.
147147

148-
* <code>public function <b>jsonSerialize</b> ()</code>
148+
* <code>public function <b>jsonSerialize</b>(): mixed</code>
149149

150150
Returns the wrapped value –
151151
like `value()`.

test/10-ValueTest.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace mle86\Value\Tests;
34

45
use mle86\Value\AbstractValue;
@@ -23,19 +24,19 @@ class ValueTest extends TestCase
2324
protected static $tw2;
2425

2526

26-
public function validInputs() { return [
27+
public static function validInputs(): array { return [
2728
["41111"],
2829
["42020"],
2930
]; }
3031

31-
public function invalidInputs() { return [
32+
public static function invalidInputs(): array { return [
3233
[811],
3334
["z"],
3435
[array("41111")],
3536
[null],
3637
]; }
3738

38-
public function validInputs9() { return [
39+
public static function validInputs9(): array { return [
3940
["91111"],
4041
["92020"],
4142
["93330"],
@@ -44,13 +45,12 @@ public function validInputs9() { return [
4445

4546
public function testClassExists()
4647
{
47-
$class = 'mle86\\Value\\AbstractValue';
48-
$interface = 'mle86\\Value\\Value';
48+
$class = 'mle86\\Value\\AbstractValue';
4949

5050
$this->assertTrue(class_exists($class),
5151
"Class {$class} not found!");
52-
$this->assertTrue(is_a($class, $interface, true),
53-
"Class {$class} does not implement the {$interface} interface!");
52+
$this->assertTrue(is_a(AbstractValue::class, Value::class, true),
53+
"Class ".AbstractValue::class." does not implement the ".Value::class." interface!");
5454
}
5555

5656
/**
@@ -111,9 +111,8 @@ public function testCrossInvalidInitializer($initializer)
111111

112112
/**
113113
* @depends testConstructor
114-
* @return TestWrapper4
115114
*/
116-
public function testValue()
115+
public function testValue(): TestWrapper4
117116
{
118117
$vi = self::validInputs();
119118
$initializer = $vi[0][0];
@@ -200,9 +199,8 @@ public function testConstructorWithInstance()
200199

201200
/**
202201
* @depends testConstructor9
203-
* @return TestWrapper9
204202
*/
205-
public function testWrap()
203+
public function testWrap(): TestWrapper9
206204
{
207205
$vi = self::validInputs9();
208206
$v = $vi[0][0];
@@ -249,9 +247,8 @@ public function testWrapCrossInvalid($initializer)
249247

250248
/**
251249
* @depends testWrap
252-
* @return TestWrapper9
253250
*/
254-
public function testRewrap(TestWrapper9 $tw)
251+
public function testRewrap(TestWrapper9 $tw): TestWrapper9
255252
{
256253
$tx = $tw;
257254
TestWrapper9::wrap($tx);
@@ -282,14 +279,14 @@ public function testRewrapInvalid(TestWrapper9 $tx)
282279
public function testWrapArray()
283280
{
284281
$vi = self::validInputs();
285-
$a = array(
282+
$a = [
286283
'k1' => $vi[0][0],
287284
'kk22' => $vi[1][0],
288285
0 => self::$tw1, // includes an instance
289-
);
286+
];
290287

291288
$orig_a = $a;
292-
$this->assertTrue((array_keys($a) === array('k1', 'kk22', 0)));
289+
$this->assertTrue((array_keys($a) === ['k1', 'kk22', 0]));
293290

294291
$ret = TestWrapper4::wrapArray($a);
295292
/** @type TestWrapper4[] $a */
@@ -301,7 +298,7 @@ public function testWrapArray()
301298

302299
$this->assertSame(count($orig_a), count($a),
303300
"wrapArray() changed the array size!");
304-
$this->assertSame(array_keys($a), array('k1', 'kk22', 0),
301+
$this->assertSame(array_keys($a), ['k1', 'kk22', 0],
305302
"wrapArray() did not preserve array indices!");
306303

307304
$this->assertTrue(
@@ -322,10 +319,10 @@ public function testWrapArray()
322319
*/
323320
public function testWrapArray_empty()
324321
{
325-
$e = array();
322+
$e = [];
326323
$ret = TestWrapper9::wrapArray($e);
327324

328-
$this->assertSame(array(), $e, "wrapArray() did not leave an empty array untouched!");
325+
$this->assertSame([], $e, "wrapArray() did not leave an empty array untouched!");
329326
$this->assertSame($e, $ret, "wrapArray([]) handled its argument correctly, but returned something else!");
330327
}
331328

@@ -337,11 +334,11 @@ public function testWrapArray_invalids($invalid_initializer)
337334
{
338335
$vi = self::validInputs9();
339336

340-
$a = array(
337+
$a = [
341338
$vi[0][0],
342339
$invalid_initializer,
343340
'j' => $vi[2][0],
344-
);
341+
];
345342

346343
$orig_a = $a;
347344

@@ -389,12 +386,12 @@ public function testWrapOrNull()
389386
*/
390387
public function testWrapOrNullArray()
391388
{
392-
$vi = self::validInputs();
393-
$a = array(
389+
$vi = self::validInputs();
390+
$a = [
394391
'k1' => $vi[0][0],
395392
'k2' => null,
396393
'k3' => $vi[1][0],
397-
);
394+
];
398395
$orig_a = $a;
399396

400397
TestWrapper4::wrapOrNullArray($a);
@@ -412,7 +409,7 @@ public function testWrapOrNullArray()
412409
}
413410

414411

415-
public function additionalPropertyValues() { return [
412+
public static function additionalPropertyValues(): array { return [
416413
[0],
417414
[\PHP_INT_MAX],
418415
[false],
@@ -424,9 +421,8 @@ public function additionalPropertyValues() { return [
424421
* Tries to instantiate a wrapper object from an extended class, i.e. it has additional properties (for whatever reason).
425422
*
426423
* @depends testConstructor
427-
* @return ExtTestWrapper4
428424
*/
429-
public function testExtendedObject()
425+
public function testExtendedObject(): ExtTestWrapper4
430426
{
431427
$vi = self::validInputs();
432428

test/15-SerializableValueTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace mle86\Value\Tests;
34

45
use mle86\Value\AbstractSerializableValue;
@@ -21,20 +22,18 @@ class SerializableValueTest extends TestCase
2122

2223
public function testClassExists()
2324
{
24-
$class = 'mle86\\Value\\AbstractValue';
25-
$interface = 'mle86\\Value\\Value';
25+
$class = 'mle86\\Value\\AbstractSerializableValue';
2626

2727
$this->assertTrue(class_exists($class),
2828
"Class {$class} not found!");
29-
$this->assertTrue(is_a($class, $interface, true),
30-
"Class {$class} does not implement the {$interface} interface!");
29+
$this->assertTrue(is_a(AbstractSerializableValue::class, Value::class, true),
30+
"Class ".AbstractSerializableValue::class." does not implement the ".Value::class." interface!");
3131
}
3232

3333
/**
3434
* @depends testClassExists
35-
* @return AbstractSerializableValue
3635
*/
37-
public function testInstance()
36+
public function testInstance(): AbstractSerializableValue
3837
{
3938
$tw = new TestSWrapper6(self::VALID_INPUT);
4039

@@ -61,8 +60,8 @@ public function testString(AbstractSerializableValue $tw)
6160
*/
6261
public function testJson(AbstractSerializableValue $tw)
6362
{
64-
$j = json_decode(json_encode(array($tw)));
65-
$expected = array($tw->value());
63+
$j = json_decode(json_encode([$tw]));
64+
$expected = [$tw->value()];
6665

6766
$this->assertSame($expected, $j,
6867
"serializable wrapper has a jsonSerialize() method, but returned wrong value!");

test/90-DoubleConstructorCallTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ class DoubleConstructorCallTest extends TestCase
1717
const VALID_VALUE1 = "41111";
1818
const VALID_VALUE2 = "42222";
1919

20-
/**
21-
* @return Value
22-
*/
23-
public function testInstance()
20+
public function testInstance(): Value
2421
{
2522
$tw = new TestWrapper4(self::VALID_VALUE1);
2623

test/90-MagicPropertiesTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class MagicPropertiesTest extends TestCase
2020

2121
const VALID_VALUE = "41111";
2222

23-
/**
24-
* @return Value
25-
*/
26-
public function testInstance()
23+
public function testInstance(): Value
2724
{
2825
$tw = new TestWrapper4(self::VALID_VALUE);
2926

@@ -41,7 +38,7 @@ public function testSetMagicProperty(Value $o)
4138
$prop = "magic_property_3453465110";
4239
$setto = 86;
4340

44-
$pv = (isset($o->{$prop})) ? $o->{$prop} : null;
41+
$pv = $o->{$prop} ?? null;
4542
$this->assertNull($pv,
4643
"Newly-create object already has a magic property?!");
4744

@@ -56,7 +53,7 @@ public function testSetMagicProperty(Value $o)
5653
$this->assertNotNull($e,
5754
"Setting a magic property did NOT result in an exception!");
5855

59-
$pv = (isset($o->{$prop})) ? $o->{$prop} : null;
56+
$pv = $o->{$prop} ?? null;
6057
$this->assertNotEquals($setto, $pv,
6158
"Setting a magic property WORKED, despite throwing an exception!");
6259
$this->assertNull($pv,

0 commit comments

Comments
 (0)