Conditions | 2 |
Paths | 2 |
Total Lines | 68 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Tests | 34 |
CRAP Score | 2 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
20 | function bootstrap( |
||
21 | Socket $transport, |
||
22 | UrlInterface $server, |
||
23 | ElapsedPeriod $timeout, |
||
24 | TimeContinuumInterface $clock, |
||
25 | LoggerInterface $logger = null, |
||
26 | SetInterface $protocols = null, |
||
27 | SetInterface $argumentTranslators = null |
||
28 | ): array { |
||
29 | 1 | $argumentTranslators = $argumentTranslators ?? Set::of( |
|
30 | 1 | Transport\Protocol\ArgumentTranslator::class, |
|
31 | 1 | new Transport\Protocol\ArgumentTranslator\ValueTranslator |
|
32 | ); |
||
33 | 1 | $protocols = $protocols ?? Set::of( |
|
34 | 1 | Transport\Protocol::class, |
|
35 | 1 | new Transport\Protocol\v091\Protocol( |
|
36 | 1 | new Transport\Protocol\ArgumentTranslator\Delegate(...$argumentTranslators) |
|
37 | ) |
||
38 | ); |
||
39 | |||
40 | 1 | $connection = new Transport\Connection\Lazy( |
|
41 | 1 | $transport, |
|
42 | 1 | $server, |
|
43 | 1 | new Transport\Protocol\Delegate(...$protocols), |
|
44 | 1 | $timeout, |
|
45 | 1 | $clock |
|
46 | ); |
||
47 | |||
48 | 1 | if ($logger instanceof LoggerInterface) { |
|
49 | 1 | $connection = new Transport\Connection\Logger($connection, $logger); |
|
50 | } |
||
51 | |||
52 | return [ |
||
53 | 'client' => [ |
||
54 | 1 | 'basic' => new Client\Client($connection), |
|
55 | 'fluent' => static function(Client $client): Client { |
||
56 | 1 | return new Client\Fluent($client); |
|
57 | 1 | }, |
|
58 | 'logger' => static function(Client $client) use ($logger): Client { |
||
59 | 1 | return new Client\Logger($client, $logger); |
|
1 ignored issue
–
show
|
|||
60 | 1 | }, |
|
61 | 'signal_aware' => static function(Client $client): Client { |
||
62 | 1 | return new Client\SignalAware($client); |
|
63 | 1 | }, |
|
64 | 'auto_declare' => static function(SetInterface $exchanges, SetInterface $queues, SetInterface $bindings): callable { |
||
65 | return static function(Client $client) use ($exchanges, $queues, $bindings): Client { |
||
66 | 1 | return new Client\AutoDeclare($client, $exchanges, $queues, $bindings); |
|
67 | 1 | }; |
|
68 | 1 | }, |
|
69 | ], |
||
70 | 'command' => [ |
||
71 | 'purge' => static function(Client $client): CLICommand { |
||
72 | 1 | return new Command\Purge($client); |
|
73 | 1 | }, |
|
74 | 'get' => static function(MapInterface $consumers): callable { |
||
75 | return static function(Client $client) use ($consumers): CLICommand { |
||
76 | 1 | return new Command\Get($client, new Consumers($consumers)); |
|
77 | 1 | }; |
|
78 | 1 | }, |
|
79 | 'consume' => static function(MapInterface $consumers): callable { |
||
80 | return static function(Client $client) use ($consumers): CLICommand { |
||
81 | 1 | return new Command\Consume($client, new Consumers($consumers)); |
|
82 | 1 | }; |
|
83 | 1 | }, |
|
84 | ], |
||
85 | 'producers' => static function(SetInterface $exchanges): callable { |
||
86 | return static function(Client $client) use ($exchanges): Producers { |
||
87 | 1 | return Producers::fromDeclarations($client, ...$exchanges); |
|
88 | 1 | }; |
|
92 |