| 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 |
||
| 100 | public function testGeneratesClass() : void |
||
| 101 | { |
||
| 102 | $generateProxy = new ReflectionMethod($this->factory, 'generateProxy'); |
||
| 103 | |||
| 104 | $generateProxy->setAccessible(true); |
||
| 105 | $generatedClass = UniqueIdentifierGenerator::getIdentifier('fooBar'); |
||
| 106 | |||
| 107 | $this |
||
| 108 | ->classNameInflector |
||
| 109 | ->method('getProxyClassName') |
||
| 110 | ->with('stdClass') |
||
| 111 | ->willReturn($generatedClass); |
||
| 112 | |||
| 113 | $this |
||
| 114 | ->generatorStrategy |
||
| 115 | ->expects(self::once()) |
||
| 116 | ->method('generate') |
||
| 117 | ->with(self::isInstanceOf(ClassGenerator::class)); |
||
| 118 | $this |
||
| 119 | ->proxyAutoloader |
||
| 120 | ->expects(self::once()) |
||
| 121 | ->method('__invoke') |
||
| 122 | ->with($generatedClass) |
||
| 123 | ->will(self::returnCallback(static function ($className) : bool { |
||
| 124 | eval('class ' . $className . ' {}'); |
||
| 125 | |||
| 126 | return true; |
||
| 127 | })); |
||
| 128 | |||
| 129 | $this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature'); |
||
| 130 | $this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0)); |
||
| 131 | $this |
||
| 132 | ->generator |
||
| 133 | ->expects(self::once()) |
||
| 134 | ->method('generate') |
||
| 135 | ->with( |
||
| 136 | self::callback(static function (ReflectionClass $reflectionClass) : bool { |
||
| 137 | return $reflectionClass->getName() === 'stdClass'; |
||
| 138 | }), |
||
| 139 | self::isInstanceOf(ClassGenerator::class), |
||
| 140 | ['some' => 'proxy', 'options' => 'here'] |
||
| 141 | ); |
||
| 142 | |||
| 143 | self::assertSame( |
||
| 144 | $generatedClass, |
||
| 145 | $generateProxy->invoke($this->factory, stdClass::class, ['some' => 'proxy', 'options' => 'here']) |
||
| 146 | ); |
||
| 147 | self::assertTrue(class_exists($generatedClass, false)); |
||
| 148 | self::assertSame( |
||
| 149 | $generatedClass, |
||
| 150 | $generateProxy->invoke($this->factory, stdClass::class, ['some' => 'proxy', 'options' => 'here']) |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | } |
||
| 154 |