Conditions | 1 |
Total Lines | 72 |
Lines | 0 |
Ratio | 0 % |
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 |
||
23 | public function setUp(): void |
||
24 | { |
||
25 | AbstractClassResolver::addAnonymousGlobal( |
||
26 | $this, |
||
27 | new class() extends AbstractConfig { |
||
28 | public function getValues(): array |
||
29 | { |
||
30 | return ['1', 2, [3]]; |
||
31 | } |
||
32 | } |
||
33 | ); |
||
34 | |||
35 | AbstractClassResolver::addAnonymousGlobal( |
||
36 | $this, |
||
37 | new class() extends AbstractDependencyProvider { |
||
38 | public function provideModuleDependencies(Container $container): void |
||
39 | { |
||
40 | $container->set('key', 'value'); |
||
41 | } |
||
42 | } |
||
43 | ); |
||
44 | |||
45 | AbstractClassResolver::addAnonymousGlobal( |
||
46 | $this, |
||
47 | new class() extends AbstractFactory { |
||
48 | public function createDomainClass(): object |
||
49 | { |
||
50 | /** @var array $configValues */ |
||
51 | $configValues = $this->getConfig()->getValues(); |
||
1 ignored issue
–
show
|
|||
52 | |||
53 | /** @var string $valueFromDependencyProvider */ |
||
54 | $valueFromDependencyProvider = $this->getProvidedDependency('key'); |
||
55 | |||
56 | return new class($configValues, $valueFromDependencyProvider) { |
||
57 | private array $configValues; |
||
58 | private string $valueFromDependencyProvider; |
||
59 | |||
60 | public function __construct( |
||
61 | array $configValues, |
||
62 | string $valueFromDependencyProvider |
||
63 | ) { |
||
64 | $this->configValues = $configValues; |
||
65 | $this->valueFromDependencyProvider = $valueFromDependencyProvider; |
||
66 | } |
||
67 | |||
68 | public function getConfigValues(): array |
||
69 | { |
||
70 | return $this->configValues; |
||
71 | } |
||
72 | |||
73 | public function getValueFromDependencyProvider(): string |
||
74 | { |
||
75 | return $this->valueFromDependencyProvider; |
||
76 | } |
||
77 | }; |
||
78 | } |
||
79 | } |
||
80 | ); |
||
81 | |||
82 | $this->facade = new class() extends AbstractFacade { |
||
83 | public function getConfigValues(): array |
||
84 | { |
||
85 | return $this->getFactory() |
||
86 | ->createDomainClass() |
||
1 ignored issue
–
show
|
|||
87 | ->getConfigValues(); |
||
88 | } |
||
89 | |||
90 | public function getValueFromDependencyProvider(): string |
||
91 | { |
||
92 | return $this->getFactory() |
||
93 | ->createDomainClass() |
||
94 | ->getValueFromDependencyProvider(); |
||
95 | } |
||
105 |