Skip to content

Commit 07b4461

Browse files
committed
refactoring with new phpstan
1 parent 1336edd commit 07b4461

File tree

6 files changed

+285
-6
lines changed

6 files changed

+285
-6
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?php
2+
3+
namespace Illuminate\Contracts\Container;
4+
5+
use Closure;
6+
use Psr\Container\ContainerInterface;
7+
8+
interface Container extends ContainerInterface
9+
{
10+
/**
11+
* Determine if the given abstract type has been bound.
12+
*
13+
* @param string $abstract
14+
* @return bool
15+
*/
16+
public function bound($abstract);
17+
18+
/**
19+
* Alias a type to a different name.
20+
*
21+
* @param string $abstract
22+
* @param string $alias
23+
* @return void
24+
*
25+
* @throws \LogicException
26+
*/
27+
public function alias($abstract, $alias);
28+
29+
/**
30+
* Assign a set of tags to a given binding.
31+
*
32+
* @param array|string $abstracts
33+
* @param array|mixed ...$tags
34+
* @return void
35+
*/
36+
public function tag($abstracts, $tags);
37+
38+
/**
39+
* Resolve all of the bindings for a given tag.
40+
*
41+
* @param string $tag
42+
* @return iterable
43+
*/
44+
public function tagged($tag);
45+
46+
/**
47+
* Register a binding with the container.
48+
*
49+
* @param string $abstract
50+
* @param \Closure|string|null $concrete
51+
* @param bool $shared
52+
* @return void
53+
*/
54+
public function bind($abstract, $concrete = null, $shared = false);
55+
56+
/**
57+
* Register a binding if it hasn't already been registered.
58+
*
59+
* @param string $abstract
60+
* @param \Closure|string|null $concrete
61+
* @param bool $shared
62+
* @return void
63+
*/
64+
public function bindIf($abstract, $concrete = null, $shared = false);
65+
66+
/**
67+
* Register a shared binding in the container.
68+
*
69+
* @param string $abstract
70+
* @param \Closure|string|null $concrete
71+
* @return void
72+
*/
73+
public function singleton($abstract, $concrete = null);
74+
75+
/**
76+
* Register a shared binding if it hasn't already been registered.
77+
*
78+
* @param string $abstract
79+
* @param \Closure|string|null $concrete
80+
* @return void
81+
*/
82+
public function singletonIf($abstract, $concrete = null);
83+
84+
/**
85+
* Register a scoped binding in the container.
86+
*
87+
* @param string $abstract
88+
* @param \Closure|string|null $concrete
89+
* @return void
90+
*/
91+
public function scoped($abstract, $concrete = null);
92+
93+
/**
94+
* Register a scoped binding if it hasn't already been registered.
95+
*
96+
* @param string $abstract
97+
* @param \Closure|string|null $concrete
98+
* @return void
99+
*/
100+
public function scopedIf($abstract, $concrete = null);
101+
102+
/**
103+
* "Extend" an abstract type in the container.
104+
*
105+
* @param string $abstract
106+
* @param \Closure $closure
107+
* @return void
108+
*
109+
* @throws \InvalidArgumentException
110+
*/
111+
public function extend($abstract, Closure $closure);
112+
113+
/**
114+
* Register an existing instance as shared in the container.
115+
*
116+
* @param string $abstract
117+
* @param mixed $instance
118+
* @return mixed
119+
*/
120+
public function instance($abstract, $instance);
121+
122+
/**
123+
* Add a contextual binding to the container.
124+
*
125+
* @param string $concrete
126+
* @param string $abstract
127+
* @param \Closure|string $implementation
128+
* @return void
129+
*/
130+
public function addContextualBinding($concrete, $abstract, $implementation);
131+
132+
/**
133+
* Define a contextual binding.
134+
*
135+
* @param string|array $concrete
136+
* @return \Illuminate\Contracts\Container\ContextualBindingBuilder
137+
*/
138+
public function when($concrete);
139+
140+
/**
141+
* Get a closure to resolve the given type from the container.
142+
*
143+
* @param string $abstract
144+
* @return \Closure
145+
*/
146+
public function factory($abstract);
147+
148+
/**
149+
* Flush the container of all bindings and resolved instances.
150+
*
151+
* @return void
152+
*/
153+
public function flush();
154+
155+
/**
156+
* Resolve the given type from the container.
157+
*
158+
* @template T
159+
* @param class-string<T> $abstract
160+
* @param array $parameters
161+
* @return T
162+
*
163+
* @throws \Illuminate\Contracts\Container\BindingResolutionException
164+
*/
165+
public function make($abstract, array $parameters = []);
166+
167+
/**
168+
* Call the given Closure / class@method and inject its dependencies.
169+
*
170+
* @param callable|string $callback
171+
* @param array $parameters
172+
* @param string|null $defaultMethod
173+
* @return mixed
174+
*/
175+
public function call($callback, array $parameters = [], $defaultMethod = null);
176+
177+
/**
178+
* Determine if the given abstract type has been resolved.
179+
*
180+
* @param string $abstract
181+
* @return bool
182+
*/
183+
public function resolved($abstract);
184+
185+
/**
186+
* Register a new before resolving callback.
187+
*
188+
* @param \Closure|string $abstract
189+
* @param \Closure|null $callback
190+
* @return void
191+
*/
192+
public function beforeResolving($abstract, Closure $callback = null);
193+
194+
/**
195+
* Register a new resolving callback.
196+
*
197+
* @param \Closure|string $abstract
198+
* @param \Closure|null $callback
199+
* @return void
200+
*/
201+
public function resolving($abstract, Closure $callback = null);
202+
203+
/**
204+
* Register a new after resolving callback.
205+
*
206+
* @param \Closure|string $abstract
207+
* @param \Closure|null $callback
208+
* @return void
209+
*/
210+
public function afterResolving($abstract, Closure $callback = null);
211+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Psr\Container;
6+
7+
/**
8+
* Describes the interface of a container that exposes methods to read its entries.
9+
*/
10+
interface ContainerInterface
11+
{
12+
/**
13+
* Finds an entry of the container by its identifier and returns it.
14+
*
15+
* @template T
16+
* @param class-string<T> $id Identifier of the entry to look for.
17+
*
18+
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
19+
* @throws ContainerExceptionInterface Error while retrieving the entry.
20+
*
21+
* @return T
22+
*/
23+
public function get(string $id);
24+
25+
/**
26+
* Returns true if the container can return an entry for the given identifier.
27+
* Returns false otherwise.
28+
*
29+
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
30+
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
31+
*
32+
* @param string $id Identifier of the entry to look for.
33+
*
34+
* @return bool
35+
*/
36+
public function has(string $id): bool;
37+
}

phpstan.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ includes:
44
parameters:
55
stubFiles:
66
- analyze/phpstan/stubs/helpers.stub
7-
level: 8
7+
- analyze/phpstan/stubs/Container.stub
8+
- analyze/phpstan/stubs/ContainerInterface.stub
9+
level: 9
810
fileExtensions:
911
- php
1012
ergebnis:

src/Services/AtomicServiceInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
interface AtomicServiceInterface
1414
{
1515
/**
16+
* @template T
17+
* @param Wallet $object
18+
* @param callable(): T $callback
19+
* @return T
20+
*
1621
* @throws LockProviderNotFoundException
1722
* @throws RecordsNotFoundException
1823
* @throws TransactionFailedException

src/Traits/MorphOneWallet.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ trait MorphOneWallet
2222
public function wallet(): MorphOne
2323
{
2424
$castService = app(CastServiceInterface::class);
25+
/** @var class-string $related */
26+
$related = config('wallet.wallet.model', WalletModel::class);
27+
assert(is_string($related));
28+
29+
$slug = config('wallet.wallet.default.slug', 'default');
30+
assert(is_string($slug));
2531

2632
return $castService
2733
->getHolder($this)
28-
->morphOne(config('wallet.wallet.model', WalletModel::class), 'holder')
29-
->where('slug', config('wallet.wallet.default.slug', 'default'))
34+
->morphOne($related, 'holder')
35+
->where('slug', $slug)
3036
->withDefault(static function (WalletModel $wallet, object $holder) use ($castService) {
3137
$model = $castService->getModel($holder);
32-
$wallet->forceFill(array_merge(config('wallet.wallet.creating', []), [
38+
$wallet->forceFill(array_merge((array) config('wallet.wallet.creating', []), [
3339
'name' => config('wallet.wallet.default.name', 'Default Wallet'),
3440
'slug' => config('wallet.wallet.default.slug', 'default'),
3541
'meta' => config('wallet.wallet.default.meta', []),

src/WalletServiceProvider.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ public function register(): void
142142
$this->mergeConfigFrom(dirname(__DIR__) . '/config/config.php', 'wallet');
143143
$this->commands([TransferFixCommand::class]);
144144

145+
/**
146+
* @var array{
147+
* internal?: array<class-string|null>,
148+
* services?: array<class-string|null>,
149+
* cache?: array{driver: string|null},
150+
* repositories?: array<class-string|null>,
151+
* transformers?: array<class-string|null>,
152+
* assemblers?: array<class-string|null>,
153+
* events?: array<class-string|null>,
154+
* transaction?: array{model?: class-string|null},
155+
* transfer?: array{model?: class-string|null},
156+
* wallet?: array{model?: class-string|null},
157+
* } $configure
158+
*/
145159
$configure = config('wallet', []);
146160

147161
$this->internal($configure['internal'] ?? []);
@@ -200,7 +214,7 @@ private function internal(array $configure): void
200214

201215
/**
202216
* @param array<class-string|null> $configure
203-
* @param array{driver: string|null} $cache
217+
* @param array{driver?: string|null} $cache
204218
*/
205219
private function services(array $configure, array $cache): void
206220
{
@@ -352,7 +366,11 @@ private function events(array $configure): void
352366
}
353367

354368
/**
355-
* @param array<array<class-string|null>> $configure
369+
* @param array{
370+
* transaction?: array{model?: class-string|null},
371+
* transfer?: array{model?: class-string|null},
372+
* wallet?: array{model?: class-string|null},
373+
* } $configure
356374
*/
357375
private function bindObjects(array $configure): void
358376
{

0 commit comments

Comments
 (0)