| Conditions | 6 |
| Paths | 32 |
| Total Lines | 61 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 33 | public function testGetHooks() { |
||
| 34 | |||
| 35 | $classpath = getcwd() . "/Tests/Utility/"; |
||
| 36 | $namespace = "WBW\\Library\\Core\\Tests\\Utility\\"; |
||
| 37 | |||
| 38 | $hooks1 = HookUtility::getHooks($classpath, $namespace); |
||
| 39 | foreach ($hooks1 as $current) { |
||
| 40 | |||
| 41 | $this->assertEquals($classpath, $current["classpath"]); |
||
| 42 | $this->assertEquals($namespace, $current["namespace"]); |
||
| 43 | $this->assertStringEndsWith(".php", $current["filename"]); |
||
| 44 | $this->assertContainsOnlyInstancesOf(ReflectionClass::class, [$current["class"]]); |
||
| 45 | $this->assertNull($current["method"], "The method getHooks() does not return the expected value"); |
||
| 46 | } |
||
| 47 | |||
| 48 | $hooks2 = HookUtility::getHooks($classpath, $namespace, "/Exception/"); |
||
| 49 | $this->assertCount(0, $hooks2); |
||
| 50 | |||
| 51 | $hooks3 = HookUtility::getHooks($classpath, $namespace, "/HookUtilityTest/"); |
||
| 52 | $this->assertCount(1, $hooks3); |
||
| 53 | foreach ($hooks3 as $current) { |
||
| 54 | |||
| 55 | $this->assertEquals($classpath, $current["classpath"]); |
||
| 56 | $this->assertEquals($namespace, $current["namespace"]); |
||
| 57 | $this->assertEquals("HookUtilityTest.php", $current["filename"]); |
||
| 58 | $this->assertContainsOnlyInstancesOf(ReflectionClass::class, [$current["class"]]); |
||
| 59 | $this->assertNull($current["method"], "The method getHooks() does not return the expected value"); |
||
| 60 | } |
||
| 61 | |||
| 62 | $hooks4 = HookUtility::getHooks($classpath, $namespace, "/HookUtilityTest/", "Exception"); |
||
| 63 | $this->assertCount(0, $hooks4); |
||
| 64 | |||
| 65 | $hooks5 = HookUtility::getHooks($classpath, $namespace, "/HookUtilityTest/", PHPUnit_Framework_TestCase::class); |
||
| 66 | $this->assertCount(1, $hooks5); |
||
| 67 | foreach ($hooks5 as $current) { |
||
| 68 | |||
| 69 | $this->assertEquals($classpath, $current["classpath"]); |
||
| 70 | $this->assertEquals($namespace, $current["namespace"]); |
||
| 71 | $this->assertEquals("HookUtilityTest.php", $current["filename"]); |
||
| 72 | $this->assertContainsOnlyInstancesOf(ReflectionClass::class, [$current["class"]]); |
||
| 73 | $this->assertNull($current["method"], "The method getHooks() does not return the expected value"); |
||
| 74 | } |
||
| 75 | |||
| 76 | $hooks6 = HookUtility::getHooks($classpath, $namespace, "/HookUtilityTest/", PHPUnit_Framework_TestCase::class, "testGetHooks"); |
||
| 77 | $this->assertCount(1, $hooks6); |
||
| 78 | foreach ($hooks6 as $current) { |
||
| 79 | |||
| 80 | $this->assertEquals($classpath, $current["classpath"]); |
||
| 81 | $this->assertEquals($namespace, $current["namespace"]); |
||
| 82 | $this->assertEquals("HookUtilityTest.php", $current["filename"]); |
||
| 83 | $this->assertContainsOnlyInstancesOf(ReflectionClass::class, [$current["class"]]); |
||
| 84 | $this->assertContainsOnlyInstancesOf(ReflectionMethod::class, [$current["method"]]); |
||
| 85 | } |
||
| 86 | |||
| 87 | try { |
||
| 88 | HookUtility::getHooks($classpath, $namespace, "/HookUtilityTest/", PHPUnit_Framework_TestCase::class, "testGetHook"); |
||
| 89 | } catch (Exception $ex) { |
||
| 90 | $this->assertInstanceOf(HookMethodNotFoundException::class, $ex); |
||
| 91 | $this->assertEquals("The hook method \"testGetHook\" is not found", $ex->getMessage()); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 96 |