Skip to content

Commit c4bd956

Browse files
authored
Merge pull request #15 from kingsquare/phpstan-level8
Phpstan level 8
2 parents 4b37872 + af86f29 commit c4bd956

10 files changed

+66
-43
lines changed

src/CommunibaseId.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function fromValidString(string $string = null): CommunibaseId
5656

5757
public function __toString(): string
5858
{
59-
return $this->id;
59+
return (string) $this->id;
6060
}
6161

6262
public function toString(): string

src/CommunibaseIdCollection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
/**
1010
* @author Kingsquare (source@kingsquare.nl)
1111
* @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl)
12+
*
13+
* @implements \IteratorAggregate<CommunibaseId>
1214
*/
13-
class CommunibaseIdCollection implements \Countable, \IteratorAggregate, \JsonSerializable
15+
final class CommunibaseIdCollection implements \Countable, \IteratorAggregate, \JsonSerializable
1416
{
1517
/**
1618
* @var CommunibaseId[]
1719
*/
1820
private $ids;
1921

2022
/**
23+
* @param string[] $strings
2124
* @throws InvalidIdException
2225
*/
2326
private function __construct(array $strings)
@@ -31,6 +34,7 @@ static function (string $string) {
3134
}
3235

3336
/**
37+
* @param string[] $strings
3438
* @throws InvalidIdException
3539
*/
3640
public static function fromStrings(array $strings): CommunibaseIdCollection
@@ -40,6 +44,7 @@ public static function fromStrings(array $strings): CommunibaseIdCollection
4044

4145
/**
4246
* Filter out all invalid strings
47+
* @param string[] $strings
4348
*/
4449
public static function fromValidStrings(array $strings): CommunibaseIdCollection
4550
{
@@ -81,21 +86,24 @@ public function isEmpty(): bool
8186
}
8287

8388
/**
84-
* @return \ArrayIterator|\Traversable|CommunibaseId[]
89+
* @return \ArrayIterator<int, CommunibaseId>
8590
*/
86-
public function getIterator()
91+
public function getIterator(): \ArrayIterator
8792
{
8893
return new \ArrayIterator($this->ids);
8994
}
9095

9196
/**
92-
* @return array|string[]
97+
* @return string[]
9398
*/
9499
public function toStrings(): array
95100
{
96101
return array_map('\strval', $this->ids);
97102
}
98103

104+
/**
105+
* @return array{array{"$ObjectId":string}}
106+
*/
99107
public function toObjectQueryArray(): array
100108
{
101109
return array_reduce(

src/Entity/Address.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ class Address
2121
*/
2222
protected $dataBag;
2323

24-
protected function __construct(array $addressData = [])
24+
/**
25+
* @param array{'_id'?: string, 'type'?: string, 'property'?: string, 'street'?: string, 'streetNumber'?: string, 'streetNumberAddition'?: string, 'zipcode'?: string, 'city'?: string, 'countryCode'?: string, point?: array{coordinates: array{float, float}}, latitude?: float, longitude?: float} $addressData
26+
*/
27+
final private function __construct(array $addressData = [])
2528
{
2629
$this->dataBag = DataBag::create();
2730
if ($addressData === []) {
@@ -30,18 +33,15 @@ protected function __construct(array $addressData = [])
3033
$this->dataBag->addEntityData('address', $addressData);
3134
}
3235

33-
/**
34-
* @return static
35-
*/
36-
public static function create()
36+
public static function create(): Address
3737
{
3838
return new static();
3939
}
4040

4141
/**
42-
* @return static
42+
* @param ?array{'_id'?: string, 'type'?: string, 'property'?: string, 'street'?: string, 'streetNumber'?: string, 'streetNumberAddition'?: string, 'zipcode'?: string, 'city'?: string, 'countryCode'?: string, point?: array{coordinates: array{float, float}}, latitude?: float, longitude?: float} $addressData
4343
*/
44-
public static function fromAddressData(array $addressData = null)
44+
public static function fromAddressData(array $addressData = null): Address
4545
{
4646
if ($addressData === null) {
4747
$addressData = [];
@@ -134,7 +134,7 @@ public function getId(): CommunibaseId
134134
return CommunibaseId::fromString($this->dataBag->get('address._id'));
135135
}
136136

137-
public function __toString()
137+
public function __toString(): string
138138
{
139139
return $this->toString();
140140
}
@@ -172,7 +172,7 @@ public function toString(bool $singleLine = true): string
172172
}
173173

174174
/**
175-
* @return float[]|null
175+
* @return ?array<float>
176176
*/
177177
public function getGeoLocation(): ?array
178178
{
@@ -229,9 +229,6 @@ private function isGeoStorageUsingNativePoint(): bool
229229
return !empty($this->dataBag->get('address.point'));
230230
}
231231

232-
/**
233-
* @return bool
234-
*/
235232
public function isEmpty(): bool
236233
{
237234
return empty(
@@ -256,7 +253,7 @@ public function __clone()
256253
}
257254

258255
/**
259-
* @return array|null
256+
* @return ?array{'_id'?: string, 'type'?: string, 'property'?: string, 'street'?: string, 'streetNumber'?: string, 'streetNumberAddition'?: string, 'zipcode'?: string, 'city'?: string, 'countryCode'?: string, point?: array{coordinates: array{float, float}}, latitude?: float, longitude?: float}
260257
*/
261258
public function getState(): ?array
262259
{
@@ -269,7 +266,7 @@ public function getState(): ?array
269266
/**
270267
* @throws InvalidGeoLocationException
271268
*/
272-
protected function guardAgainstInvalidLatLong(float $latitude, float $longitude): void
269+
private function guardAgainstInvalidLatLong(float $latitude, float $longitude): void
273270
{
274271
if ($latitude < -90 || $latitude > 90 || $longitude < -180 || $longitude > 180) {
275272
throw new InvalidGeoLocationException(

src/Entity/Email.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class Email
1919
*/
2020
protected $dataBag;
2121

22-
protected function __construct(array $emailAddressData = [])
22+
/**
23+
* @param array{'_id'?: string, 'type'?: string, 'emailAddress'?: string} $emailAddressData
24+
*/
25+
final private function __construct(array $emailAddressData = [])
2326
{
2427
if (empty($emailAddressData['type'])) {
2528
$emailAddressData['type'] = 'private';
@@ -28,29 +31,23 @@ protected function __construct(array $emailAddressData = [])
2831
$this->dataBag->addEntityData('email', $emailAddressData);
2932
}
3033

31-
/**
32-
* @return static
33-
*/
34-
public static function create()
34+
public static function create(): Email
3535
{
3636
return new static();
3737
}
3838

3939
/**
40-
* @return static
40+
* @param ?array{'_id'?: string, 'type'?: string, 'emailAddress'?: string} $emailAddressData
4141
*/
42-
public static function fromEmailAddressData(array $emailAddressData = null)
42+
public static function fromEmailAddressData(array $emailAddressData = null): Email
4343
{
4444
if ($emailAddressData === null) {
4545
$emailAddressData = [];
4646
}
4747
return new static($emailAddressData);
4848
}
4949

50-
/**
51-
* @return static
52-
*/
53-
public static function fromEmailAddress(string $emailAddress)
50+
public static function fromEmailAddress(string $emailAddress): Email
5451
{
5552
return static::fromEmailAddressData(
5653
[
@@ -88,6 +85,9 @@ public function __clone()
8885
}
8986
}
9087

88+
/**
89+
* @return ?array{'_id'?: string, 'type'?: string, 'emailAddress'?: string}
90+
*/
9191
public function getState(): ?array
9292
{
9393
if (empty($this->getEmailAddress())) {

src/Entity/PhoneNumber.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ class PhoneNumber
1919
*/
2020
protected $dataBag;
2121

22+
/**
23+
* @var PhoneNumberUtil
24+
*/
2225
private static $phoneNumberUtil;
2326

24-
protected function __construct(array $phoneNumberData = [])
27+
/**
28+
* @param array{'_id'?: string, 'type'?: string, 'areaCode'?: string|int, 'countryCode'?: string|int, 'subscriberNumber'?: string|int} $phoneNumberData
29+
*/
30+
final private function __construct(array $phoneNumberData = [])
2531
{
2632
$this->dataBag = DataBag::create();
2733
if (empty($phoneNumberData['type'])) {
@@ -31,26 +37,20 @@ protected function __construct(array $phoneNumberData = [])
3137
self::$phoneNumberUtil = self::$phoneNumberUtil ?? PhoneNumberUtil::getInstance();
3238
}
3339

34-
/**
35-
* @return static
36-
*/
37-
public static function create()
40+
public static function create(): PhoneNumber
3841
{
3942
return new static();
4043
}
4144

4245
/**
43-
* @return static
46+
* @param ?array{'_id'?: string, 'type'?: string, 'areaCode'?: string|int, 'countryCode'?: string|int, 'subscriberNumber'?: string|int} $phoneNumberData
4447
*/
45-
public static function fromPhoneNumberData(array $phoneNumberData = null)
48+
public static function fromPhoneNumberData(array $phoneNumberData = null): PhoneNumber
4649
{
4750
return new static($phoneNumberData ?? []);
4851
}
4952

50-
/**
51-
* @return static
52-
*/
53-
public static function fromString(string $phoneNumberString)
53+
public static function fromString(string $phoneNumberString): PhoneNumber
5454
{
5555
$phoneNumber = static::create();
5656
$phoneNumber->setPhoneNumber($phoneNumberString);
@@ -151,6 +151,9 @@ public function __clone()
151151
}
152152
}
153153

154+
/**
155+
* @return ?array{'_id'?: string, 'type'?: string, 'areaCode'?: string|int, 'countryCode'?: string|int, 'subscriberNumber'?: string|int}
156+
*/
154157
public function getState(): ?array
155158
{
156159
if (!array_filter([$this->dataBag->get('phone.areaCode'), $this->dataBag->get('phone.subscriberNumber')])) {

src/Exception/InvalidGeoLocationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
* @author Kingsquare (source@kingsquare.nl)
99
* @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl)
1010
*/
11-
class InvalidGeoLocationException extends \Exception
11+
final class InvalidGeoLocationException extends \Exception
1212
{
1313
}

src/Exception/InvalidIdException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
* @author Kingsquare (source@kingsquare.nl)
99
* @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl)
1010
*/
11-
class InvalidIdException extends \Exception
11+
final class InvalidIdException extends \Exception
1212
{
1313
}

tests/CommunibaseIdTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function test_it_can_be_created_from_a_valid_string(): void
4242
self::assertEquals(self::VALID_ID_STRING, $id->toString());
4343
}
4444

45+
/**
46+
* @return array<string, array<string>>
47+
*/
4548
public function invalidStringSources(): array
4649
{
4750
return [

tests/Entity/AddressTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function test_setters(string $property, string $value): void
4949
self::assertSame($value, $address->{'get' . $property}());
5050
}
5151

52+
/**
53+
* @return array<array<string>>
54+
*/
5255
public function setSetterProvider(): array
5356
{
5457
return [
@@ -188,6 +191,9 @@ public function test_can_set_geolocation_using_point(): void
188191
);
189192
}
190193

194+
/**
195+
* @return array<array<float, float>>
196+
*/
191197
public function invalidGeolocationProvider(): array
192198
{
193199
return [

tests/Entity/PhoneNumberTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*/
1414
class PhoneNumberTest extends TestCase
1515
{
16+
/**
17+
* @return array<string, array<string>>
18+
*/
1619
public function dataProvider(): array
1720
{
1821
return [
@@ -61,6 +64,9 @@ public function testExplodePhoneNumber(
6164
self::assertSame($expected, $phoneNumber->getState());
6265
}
6366

67+
/**
68+
* @return array<string, array<string|null>>
69+
*/
6470
public function provider(): array
6571
{
6672
return [

0 commit comments

Comments
 (0)