Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 68 |
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 |
||
42 | public function testDefaultTargetDirCreation() |
||
43 | { |
||
44 | $input = new ArrayInput([]); |
||
45 | $output = new Output(); |
||
46 | |||
47 | $configurationHelper = m::mock(ConfigurationHelper::class); |
||
48 | $configurationHelper->shouldReceive('getName') |
||
|
|||
49 | ->andReturn('phpdocumentor_configuration'); |
||
50 | $configurationHelper->shouldReceive('setHelperSet'); |
||
51 | $configurationHelper->shouldReceive('getOption') |
||
52 | ->with($input, 'extensions', 'parser/extensions', array('php', 'php3', 'phtml'), true) |
||
53 | ->andReturn([]); |
||
54 | $configurationHelper->shouldReceive('getOption') |
||
55 | ->with($input, 'target', 'parser/target'); |
||
56 | $configurationHelper->shouldReceive('getOption') |
||
57 | ->with($input, m::any(), m::any(), m::any(), m::any()) |
||
58 | ->andReturn([]); |
||
59 | $configurationHelper->shouldReceive('getOption') |
||
60 | ->with($input, m::any(), m::any(), m::any()) |
||
61 | ->andReturn([]); |
||
62 | $configurationHelper->shouldReceive('getOption') |
||
63 | ->with($input, m::any(), m::any()) |
||
64 | ->andReturn('Title'); |
||
65 | $configurationHelper->shouldReceive('getConfigValueFromPath') |
||
66 | ->andReturn([]); |
||
67 | |||
68 | $loggerHelper = m::mock(LoggerHelper::class); |
||
69 | $loggerHelper->shouldReceive('getName') |
||
70 | ->andReturn('phpdocumentor_logger'); |
||
71 | $loggerHelper->shouldReceive('setHelperSet'); |
||
72 | $loggerHelper->shouldReceive('addOptions'); |
||
73 | $loggerHelper->shouldReceive('connectOutputToLogging'); |
||
74 | |||
75 | $translator = m::mock(Translator::class); |
||
76 | $translator->shouldReceive('translate') |
||
77 | ->zeroOrMoreTimes(); |
||
78 | |||
79 | $cache = m::mock(StorageInterface::class); |
||
80 | $cache->shouldReceive('getOptions') |
||
81 | ->twice() |
||
82 | ->andReturnSelf(); |
||
83 | $cache->shouldReceive('setCacheDir'); |
||
84 | $cache->shouldReceive('getCacheDir'); |
||
85 | $cache->shouldReceive('getItem'); |
||
86 | $cache->shouldReceive('setItem'); |
||
87 | $cache->shouldReceive('getIterator') |
||
88 | ->andReturn(new \ArrayIterator()); |
||
89 | |||
90 | $parser = m::mock(Parser::class); |
||
91 | $parser->shouldReceive( |
||
92 | 'setForced', |
||
93 | 'setEncoding', |
||
94 | 'setMarkers', |
||
95 | 'setIgnoredTags', |
||
96 | 'setValidate', |
||
97 | 'setDefaultPackageName', |
||
98 | 'setPath', |
||
99 | 'parse' |
||
100 | ); |
||
101 | |||
102 | $projectDescriptorBuilder = m::mock(ProjectDescriptorBuilder::class); |
||
103 | $projectDescriptorBuilder->shouldReceive('createProjectDescriptor', 'getProjectDescriptor') |
||
104 | ->andReturn(new ProjectDescriptor('test')); |
||
105 | |||
106 | $command = new ParseCommand( |
||
107 | $projectDescriptorBuilder, |
||
108 | $parser, |
||
109 | m::mock(FileCollector::class), |
||
110 | $translator, |
||
111 | $cache, |
||
112 | new ExampleFinder(), |
||
113 | m::mock(\phpDocumentor\Partials\Collection::class) |
||
114 | ); |
||
115 | |||
116 | |||
117 | |||
118 | $command->setHelperSet( |
||
119 | new HelperSet( |
||
120 | [ |
||
121 | $configurationHelper, |
||
122 | $loggerHelper |
||
123 | ] |
||
124 | ) |
||
125 | ); |
||
126 | |||
127 | $command->run($input, $output); |
||
128 | } |
||
129 | } |
||
130 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: