Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
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 |
||
87 | public function testWillTryAutoGeneration() |
||
88 | { |
||
89 | $className = UniqueIdentifierGenerator::getIdentifier('foo'); |
||
90 | $generatedClassName = UniqueIdentifierGenerator::getIdentifier('bar'); |
||
91 | $generator = $this->createMock(GeneratorStrategyInterface::class); |
||
92 | $autoloader = $this->createMock(AutoloaderInterface::class); |
||
93 | |||
94 | $this->config->expects(self::any())->method('getHydratedClassName')->will(self::returnValue($className)); |
||
95 | $this->config->expects(self::any())->method('doesAutoGenerateProxies')->will(self::returnValue(true)); |
||
96 | $this->config->expects(self::any())->method('getGeneratorStrategy')->will(self::returnValue($generator)); |
||
97 | $this->config->expects(self::any())->method('getHydratorGenerator')->willReturn(new DefaultHydratorGenerator()); |
||
98 | $this |
||
99 | ->config |
||
100 | ->expects(self::any()) |
||
101 | ->method('getGeneratedClassAutoloader') |
||
102 | ->will(self::returnValue($autoloader)); |
||
103 | |||
104 | $generator |
||
105 | ->expects(self::once()) |
||
106 | ->method('generate') |
||
107 | ->with(self::isType('array')); |
||
108 | |||
109 | // simulate autoloading |
||
110 | $autoloader |
||
111 | ->expects(self::once()) |
||
112 | ->method('__invoke') |
||
113 | ->with($generatedClassName) |
||
114 | ->willReturnCallback(static function () use ($generatedClassName) : bool { |
||
115 | eval('class ' . $generatedClassName . ' {}'); |
||
116 | |||
117 | return true; |
||
118 | }); |
||
119 | |||
120 | $this |
||
121 | ->inflector |
||
122 | ->expects(self::once()) |
||
123 | ->method('getGeneratedClassName') |
||
124 | ->with('GeneratedHydratorTestAsset\BaseClass') |
||
125 | ->will(self::returnValue($generatedClassName)); |
||
126 | |||
127 | $this |
||
128 | ->inflector |
||
129 | ->expects(self::once()) |
||
130 | ->method('getUserClassName') |
||
131 | ->with($className) |
||
132 | ->will(self::returnValue('GeneratedHydratorTestAsset\BaseClass')); |
||
133 | |||
134 | $factory = new HydratorFactory($this->config); |
||
135 | /** @var LazyLoadingMock $generatedClass */ |
||
136 | $generatedClass = $factory->getHydratorClass(); |
||
137 | |||
138 | self::assertInstanceOf($generatedClassName, new $generatedClass()); |
||
139 | } |
||
140 | } |
||
141 |
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: