Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
41 | public function testDefaultTargetDirCreation() |
||
42 | { |
||
43 | $input = new ArrayInput([]); |
||
44 | $output = new Output(); |
||
45 | |||
46 | $configurationHelper = m::mock(ConfigurationHelper::class); |
||
47 | $configurationHelper->shouldReceive('getName') |
||
|
|||
48 | ->andReturn('phpdocumentor_configuration'); |
||
49 | $configurationHelper->shouldReceive('setHelperSet'); |
||
50 | $configurationHelper->shouldReceive('getOption') |
||
51 | ->with($input, 'extensions', 'parser/extensions', array('php', 'php3', 'phtml'), true) |
||
52 | ->andReturn([]); |
||
53 | $configurationHelper->shouldReceive('getOption') |
||
54 | ->with($input, 'target', 'parser/target'); |
||
55 | $configurationHelper->shouldReceive('getOption') |
||
56 | ->with($input, m::any(), m::any(), m::any(), m::any()) |
||
57 | ->andReturn([]); |
||
58 | $configurationHelper->shouldReceive('getOption') |
||
59 | ->with($input, m::any(), m::any(), m::any()) |
||
60 | ->andReturn([]); |
||
61 | $configurationHelper->shouldReceive('getOption') |
||
62 | ->with($input, m::any(), m::any()) |
||
63 | ->andReturn('Title'); |
||
64 | $configurationHelper->shouldReceive('getConfigValueFromPath') |
||
65 | ->andReturn([]); |
||
66 | |||
67 | $loggerHelper = m::mock(LoggerHelper::class); |
||
68 | $loggerHelper->shouldReceive('getName') |
||
69 | ->andReturn('phpdocumentor_logger'); |
||
70 | $loggerHelper->shouldReceive('setHelperSet'); |
||
71 | $loggerHelper->shouldReceive('addOptions'); |
||
72 | $loggerHelper->shouldReceive('connectOutputToLogging'); |
||
73 | |||
74 | $translator = m::mock(Translator::class); |
||
75 | $translator->shouldReceive('translate') |
||
76 | ->zeroOrMoreTimes(); |
||
77 | |||
78 | $cache = m::mock(StorageInterface::class); |
||
79 | $cache->shouldReceive('getOptions') |
||
80 | ->twice() |
||
81 | ->andReturnSelf(); |
||
82 | $cache->shouldReceive('setCacheDir'); |
||
83 | $cache->shouldReceive('getCacheDir'); |
||
84 | $cache->shouldReceive('getItem'); |
||
85 | $cache->shouldReceive('setItem'); |
||
86 | $cache->shouldReceive('getIterator') |
||
87 | ->andReturn(new \ArrayIterator()); |
||
88 | |||
89 | $parser = m::mock(Parser::class); |
||
90 | $parser->shouldReceive( |
||
91 | 'setForced', |
||
92 | 'setEncoding', |
||
93 | 'setMarkers', |
||
94 | 'setIgnoredTags', |
||
95 | 'setValidate', |
||
96 | 'setDefaultPackageName', |
||
97 | 'setPath', |
||
98 | 'parse' |
||
99 | ); |
||
100 | |||
101 | $projectDescriptorBuilder = m::mock(ProjectDescriptorBuilder::class); |
||
102 | $projectDescriptorBuilder->shouldReceive('createProjectDescriptor', 'getProjectDescriptor') |
||
103 | ->andReturn(new ProjectDescriptor('test')); |
||
104 | |||
105 | $command = new ParseCommand( |
||
106 | $projectDescriptorBuilder, |
||
107 | $parser, |
||
108 | $translator, |
||
109 | new Collection(), |
||
110 | $cache, |
||
111 | new ExampleFinder(), |
||
112 | m::mock(\phpDocumentor\Partials\Collection::class) |
||
113 | ); |
||
114 | |||
115 | |||
116 | |||
117 | $command->setHelperSet( |
||
118 | new HelperSet( |
||
119 | [ |
||
120 | $configurationHelper, |
||
121 | $loggerHelper |
||
122 | ] |
||
123 | ) |
||
124 | ); |
||
125 | |||
126 | $command->run($input, $output); |
||
127 | } |
||
128 | } |
||
129 |
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: