| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| 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 |
||
| 50 | public function testRetrieveInstantiatedTemplate() |
||
| 51 | { |
||
| 52 | // Arrange |
||
| 53 | $templateName = 'clean'; |
||
| 54 | $xml = <<<'XML' |
||
| 55 | <?xml version="1.0" encoding="utf-8"?> |
||
| 56 | <template> |
||
| 57 | <name>clean</name> |
||
| 58 | <author>Mike van Riel</author> |
||
| 59 | <email>[email protected]</email> |
||
| 60 | <version>1.0.0</version> |
||
| 61 | <copyright>Mike van Riel 2013</copyright> |
||
| 62 | <description><![CDATA[This is the description]]></description> |
||
| 63 | <transformations> |
||
| 64 | <transformation query="copy" writer="FileIo" source="templates/clean/htaccess.dist" artifact=".htaccess"/> |
||
| 65 | <transformation query="copy" writer="FileIo" source="templates/clean/images" artifact="images"/> |
||
| 66 | <transformation query="copy" writer="FileIo" source="templates/clean/css" artifact="css"/> |
||
| 67 | <transformation query="copy" writer="FileIo" source="templates/clean/js" artifact="js"/> |
||
| 68 | <transformation query="copy" writer="FileIo" source="templates/clean/font" artifact="font"/> |
||
| 69 | <transformation writer="twig" query="namespace" source="templates/clean/namespace.html.twig" artifact="index.html"/> |
||
| 70 | <transformation writer="twig" query="indexes.namespaces" source="templates/clean/namespace.html.twig" /> |
||
| 71 | <transformation writer="twig" query="indexes.classes" source="templates/clean/class.html.twig" /> |
||
| 72 | <transformation writer="twig" query="indexes.interfaces" source="templates/clean/interface.html.twig" /> |
||
| 73 | <transformation writer="twig" query="indexes.traits" source="templates/clean/class.html.twig" /> |
||
| 74 | <transformation writer="twig" query="files" source="templates/clean/file.html.twig" /> |
||
| 75 | <transformation |
||
| 76 | writer="twig" |
||
| 77 | query="files" |
||
| 78 | source="templates/clean/file.source.txt.twig" |
||
| 79 | artifact="files/{{path}}.txt" |
||
| 80 | /> |
||
| 81 | <transformation writer="twig" source="templates/clean/reports/markers.html.twig" artifact="reports/markers.html"/> |
||
| 82 | <transformation writer="twig" source="templates/clean/reports/errors.html.twig" artifact="reports/errors.html"/> |
||
| 83 | <transformation |
||
| 84 | writer="twig" |
||
| 85 | source="templates/clean/reports/deprecated.html.twig" |
||
| 86 | artifact="reports/deprecated.html" |
||
| 87 | /> |
||
| 88 | <transformation writer="twig" source="templates/clean/graphs/class.html.twig" artifact="graphs/class.html"/> |
||
| 89 | <transformation writer="Graph" source="Class" artifact="graphs/classes.svg" /> |
||
| 90 | </transformations> |
||
| 91 | </template> |
||
| 92 | XML; |
||
| 93 | vfsStream::setup('exampleDir')->addChild(vfsStream::newFile('template.xml')->setContent($xml)); |
||
| 94 | $this->pathResolverMock->shouldReceive('resolve')->with($templateName)->andReturn(vfsStream::url('exampleDir')); |
||
|
|
|||
| 95 | |||
| 96 | // Act |
||
| 97 | $result = $this->fixture->get($templateName); |
||
| 98 | |||
| 99 | // Assert |
||
| 100 | $this->assertSame($templateName, $result->getName()); |
||
| 101 | $this->assertSame('Mike van Riel <[email protected]>', $result->getAuthor()); |
||
| 102 | $this->assertSame('1.0.0', $result->getVersion()); |
||
| 103 | $this->assertSame('Mike van Riel 2013', $result->getCopyright()); |
||
| 104 | $this->assertSame('This is the description', $result->getDescription()); |
||
| 105 | $this->assertSame(17, $result->count()); |
||
| 106 | $this->assertSame('copy', $result[0]->getQuery()); |
||
| 107 | $this->assertSame('FileIo', $result[0]->getWriter()); |
||
| 108 | $this->assertSame('templates/clean/htaccess.dist', $result[0]->getSource()); |
||
| 109 | $this->assertSame('.htaccess', $result[0]->getArtifact()); |
||
| 110 | } |
||
| 111 | |||
| 148 |
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: