Skip to content

Commit fea2432

Browse files
authored
Merge pull request #29 from bc-luke/bump-composer
PHPMNT-100 Bump injector
2 parents de981df + a570229 commit fea2432

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

.phpstan/baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,3 @@ parameters:
8989
message: "#^Unable to resolve the template type T in call to method Prophecy\\\\Prophet\\:\\:prophesize\\(\\)$#"
9090
count: 1
9191
path: ../src/ProphecyMockingContainer.php
92-
93-
-
94-
message: "#^Static property Bigcommerce\\\\MockInjector\\\\StaticArrayServiceCache\\:\\:\\$cache \\(Bigcommerce\\\\Injector\\\\Cache\\\\ArrayServiceCache\\) in isset\\(\\) is not nullable\\.$#"
95-
count: 1
96-
path: ../src/StaticArrayServiceCache.php

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"prefer-stable": true,
2424
"require": {
2525
"php": "^8.1",
26-
"bigcommerce/injector": "^3.0",
26+
"bigcommerce/injector": "^4.1",
2727
"phpspec/prophecy-phpunit": "^2.0",
2828
"phpunit/phpunit": " ^10.0"
2929
},

src/MockInjector.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
namespace Bigcommerce\MockInjector;
33

4-
use Bigcommerce\Injector\Injector;
4+
use Bigcommerce\Injector\InjectorFactory;
55
use Bigcommerce\Injector\InjectorInterface;
6-
use Bigcommerce\Injector\Reflection\ParameterInspector;
76
use Prophecy\Exception\Prediction\AggregateException;
87
use Prophecy\Prophecy\ObjectProphecy;
98
use Prophecy\Prophet;
@@ -39,10 +38,7 @@ public function __construct(
3938
) {
4039
$this->mockingContainer = $mockingContainer ?? new ProphecyMockingContainer(new Prophet());
4140
if (!$injector) {
42-
$injector = new Injector(
43-
$this->mockingContainer,
44-
new ParameterInspector(new StaticArrayServiceCache())
45-
);
41+
$injector = InjectorFactory::create($this->mockingContainer, serviceCache: new StaticArrayServiceCache());
4642
}
4743
$this->injector = $injector;
4844
}

src/StaticArrayServiceCache.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
* Test only "singleton" for MockInjector reflection.
1010
* This allows reflection between separate instances of the MockInjector created for each unit test (which otherwise
1111
* causes unnecessary reflection of classes that have already been inspected).
12+
*
13+
* @template T
1214
*/
1315
class StaticArrayServiceCache implements ServiceCacheInterface
1416
{
15-
/** @var ArrayServiceCache */
17+
/** @var ArrayServiceCache<T>|null */
1618
public static $cache;
1719
public function __construct()
1820
{
@@ -25,9 +27,9 @@ public function __construct()
2527
* Retrieve the value of a key in the cache.
2628
*
2729
* @param string $key
28-
* @return mixed|false cached value or false when key not present in a cache
30+
* @return T|false cached value or false when key not present in a cache
2931
*/
30-
public function get($key)
32+
public function get(string $key): mixed
3133
{
3234
return self::$cache->get($key);
3335
}
@@ -36,10 +38,10 @@ public function get($key)
3638
* Save a key/value pair to the cache.
3739
*
3840
* @param string $key
39-
* @param mixed $value
41+
* @param T $value
4042
* @return void
4143
*/
42-
public function set($key, $value)
44+
public function set(string $key, mixed $value)
4345
{
4446
self::$cache->set($key, $value);
4547
}
@@ -50,8 +52,19 @@ public function set($key, $value)
5052
* @param string $key
5153
* @return void
5254
*/
53-
public function remove($key)
55+
public function remove($key): void
5456
{
5557
self::$cache->remove($key);
5658
}
59+
60+
/**
61+
* Check if a key exists in the cache.
62+
*
63+
* @param string $key
64+
* @return bool
65+
*/
66+
public function has(string $key): bool
67+
{
68+
return self::$cache->has($key);
69+
}
5770
}

0 commit comments

Comments
 (0)