Skip to content

Commit 1e0599b

Browse files
committed
Applied strict types and type declarations to every PHP file.
Fixed issue where ImportSpecification::setProviderName would not accept null. Fixed some exception message assertions that were not being applied.
1 parent 15bb4c9 commit 1e0599b

File tree

71 files changed

+334
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+334
-237
lines changed

src/Cache/CacheItem.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
use Psr\Cache\CacheItemInterface;
@@ -14,41 +16,47 @@ final class CacheItem implements CacheItemInterface
1416

1517
private $hit;
1618

17-
private function __construct($key, $value, $hit)
19+
private function __construct(string $key, $value, bool $hit)
1820
{
19-
$this->key = "$key";
21+
$this->key = $key;
2022
$this->value = $value;
21-
$this->hit = (bool)$hit;
23+
$this->hit = $hit;
2224
}
2325

24-
public function getKey()
26+
public function getKey(): string
2527
{
2628
return $this->key;
2729
}
2830

31+
/**
32+
* @return mixed
33+
*/
2934
public function get()
3035
{
3136
return $this->value;
3237
}
3338

34-
public function isHit()
39+
public function isHit(): bool
3540
{
3641
return $this->hit;
3742
}
3843

39-
public function set($value)
44+
/**
45+
* @param mixed $value
46+
*/
47+
public function set($value): self
4048
{
4149
$this->value = $value;
4250

4351
return $this;
4452
}
4553

46-
public function expiresAt($expiration)
54+
public function expiresAt($expiration): self
4755
{
4856
throw new NotImplementedException;
4957
}
5058

51-
public function expiresAfter($time)
59+
public function expiresAfter($time): self
5260
{
5361
throw new NotImplementedException;
5462
}

src/Cache/CacheKeyGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
interface CacheKeyGenerator
57
{
6-
const RESERVED_CHARACTERS = '{}()/\@:';
8+
public const RESERVED_CHARACTERS = '{}()/\@:';
79

810
/**
911
* @param string $source
1012
* @param array $sortedOptions Options sorted by key.
1113
*
1214
* @return string A PSR-6 compatible cache key.
1315
*/
14-
public function generateCacheKey($source, array $sortedOptions);
16+
public function generateCacheKey(string $source, array $sortedOptions): string;
1517
}

src/Cache/CacheUnavailableException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
use Psr\Cache\CacheException;
@@ -8,7 +10,7 @@
810
*/
911
final class CacheUnavailableException extends \RuntimeException implements CacheException
1012
{
11-
public static function createUnsupported()
13+
public static function createUnsupported(): self
1214
{
1315
return new self('Cannot cache: connector does not support caching.');
1416
}

src/Cache/InvalidArgumentException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
final class InvalidArgumentException extends \InvalidArgumentException implements \Psr\Cache\InvalidArgumentException

src/Cache/InvalidCacheKeyException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
class InvalidCacheKeyException extends \RuntimeException implements \Psr\Cache\InvalidArgumentException

src/Cache/JsonCacheKeyGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
class JsonCacheKeyGenerator implements CacheKeyGenerator
57
{
6-
public function generateCacheKey($source, array $sortedOptions)
8+
public function generateCacheKey(string $source, array $sortedOptions): string
79
{
810
return str_replace(
911
str_split(self::RESERVED_CHARACTERS),

src/Cache/MemoryCache.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
use Psr\Cache\CacheItemInterface;
@@ -9,42 +11,45 @@
911
*/
1012
class MemoryCache extends \ArrayObject implements CacheItemPoolInterface
1113
{
14+
/**
15+
* @param string $key
16+
*
17+
* @return mixed
18+
*/
1219
public function getItem($key)
1320
{
14-
return call_user_func(
15-
\Closure::bind(
16-
function () use ($key) {
17-
return new self($key, $this->hasItem($key) ? $this[$key] : null, $this->hasItem($key));
18-
},
19-
$this,
20-
CacheItem::class
21-
)
22-
);
21+
return \Closure::bind(
22+
function () use ($key): CacheItem {
23+
return new self($key, $this->hasItem($key) ? $this[$key] : null, $this->hasItem($key));
24+
},
25+
$this,
26+
CacheItem::class
27+
)();
2328
}
2429

25-
public function getItems(array $keys = [])
30+
public function getItems(array $keys = []): iterable
2631
{
2732
foreach ($keys as $key) {
2833
yield $this->getItem($key);
2934
}
3035
}
3136

32-
public function hasItem($key)
37+
public function hasItem($key): bool
3338
{
3439
return isset($this[$key]);
3540
}
3641

37-
public function clear()
42+
public function clear(): void
3843
{
3944
$this->exchangeArray([]);
4045
}
4146

42-
public function deleteItem($key)
47+
public function deleteItem($key): void
4348
{
4449
unset($this[$key]);
4550
}
4651

47-
public function deleteItems(array $keys)
52+
public function deleteItems(array $keys): void
4853
{
4954
foreach ($keys as $key) {
5055
if (!$this->hasItem($key)) {
@@ -55,17 +60,17 @@ public function deleteItems(array $keys)
5560
}
5661
}
5762

58-
public function save(CacheItemInterface $item)
63+
public function save(CacheItemInterface $item): void
5964
{
6065
$this[$item->getKey()] = $item->get();
6166
}
6267

63-
public function saveDeferred(CacheItemInterface $item)
68+
public function saveDeferred(CacheItemInterface $item): void
6469
{
6570
$this->save($item);
6671
}
6772

68-
public function commit()
73+
public function commit(): bool
6974
{
7075
return true;
7176
}

src/Cache/NotImplementedException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Cache;
35

46
use Psr\Cache\CacheException;

src/Collection/CountablePorterRecords.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Collection;
35

46
use ScriptFUSION\Porter\Specification\ImportSpecification;
@@ -12,7 +14,7 @@ class CountablePorterRecords extends PorterRecords implements \Countable
1214
* @param int $count
1315
* @param ImportSpecification $specification
1416
*/
15-
public function __construct(RecordCollection $records, $count, ImportSpecification $specification)
17+
public function __construct(RecordCollection $records, int $count, ImportSpecification $specification)
1618
{
1719
parent::__construct($records, $specification);
1820

src/Collection/CountableProviderRecords.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace ScriptFUSION\Porter\Collection;
35

46
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
@@ -12,7 +14,7 @@ class CountableProviderRecords extends ProviderRecords implements \Countable
1214
* @param int $count
1315
* @param ProviderResource $resource
1416
*/
15-
public function __construct(\Iterator $providerRecords, $count, ProviderResource $resource)
17+
public function __construct(\Iterator $providerRecords, int $count, ProviderResource $resource)
1618
{
1719
parent::__construct($providerRecords, $resource);
1820

0 commit comments

Comments
 (0)