Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
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 |
||
102 | public function testWillTryAutoGeneration() : void |
||
103 | { |
||
104 | $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); |
||
105 | $generator = $this->createMock(GeneratorStrategyInterface::class); |
||
106 | $autoloader = $this->createMock(AutoloaderInterface::class); |
||
107 | |||
108 | $this->config->method('getGeneratorStrategy')->willReturn($generator); |
||
109 | $this->config->method('getProxyAutoloader')->willReturn($autoloader); |
||
110 | |||
111 | $generator |
||
112 | ->expects(self::once()) |
||
113 | ->method('generate') |
||
114 | ->with( |
||
115 | self::callback( |
||
116 | static function (ClassGenerator $targetClass) use ($proxyClassName) : bool { |
||
117 | return $targetClass->getName() === $proxyClassName; |
||
118 | } |
||
119 | ) |
||
120 | ); |
||
121 | |||
122 | // simulate autoloading |
||
123 | $autoloader |
||
124 | ->expects(self::once()) |
||
125 | ->method('__invoke') |
||
126 | ->with($proxyClassName) |
||
127 | ->willReturnCallback(static function () use ($proxyClassName) : bool { |
||
128 | eval( |
||
129 | 'class ' . $proxyClassName . ' implements \ProxyManager\Proxy\RemoteObjectInterface {' |
||
130 | . 'public static function staticProxyConstructor() : self { return new static(); }' |
||
131 | . '}' |
||
132 | ); |
||
133 | |||
134 | return true; |
||
135 | }); |
||
136 | |||
137 | $this |
||
138 | ->inflector |
||
139 | ->expects(self::once()) |
||
140 | ->method('getProxyClassName') |
||
141 | ->with(BaseInterface::class) |
||
142 | ->willReturn($proxyClassName); |
||
143 | |||
144 | $this |
||
145 | ->inflector |
||
146 | ->expects(self::once()) |
||
147 | ->method('getUserClassName') |
||
148 | ->with(BaseInterface::class) |
||
149 | ->willReturn('stdClass'); |
||
150 | |||
151 | $this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature'); |
||
152 | $this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0)); |
||
153 | |||
154 | /** @var AdapterInterface $adapter */ |
||
155 | $adapter = $this->createMock(AdapterInterface::class); |
||
156 | $factory = new RemoteObjectFactory($adapter, $this->config); |
||
157 | $factory->createProxy(BaseInterface::class); |
||
158 | } |
||
159 | } |
||
160 |