| Conditions | 1 |
| Paths | 1 |
| Total Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | function demonstrate() |
||
|
|
|||
| 20 | { |
||
| 21 | $blockFactory = $this->getBlockGeneratorFactory(); |
||
| 22 | $documentationFactory = $this->getDocumentationGeneratorFactory(); |
||
| 23 | $methodFactory = $this->getMethodGeneratorFactory(); |
||
| 24 | |||
| 25 | $myMethod = $methodFactory->create(); |
||
| 26 | $myMethod->setDocumentation($documentationFactory->create()); |
||
| 27 | $myMethod->markAsPublic(); |
||
| 28 | $myMethod->markAsFinal(); |
||
| 29 | $myMethod->setName('myMethod'); |
||
| 30 | $myMethod->addParameter('foo', null, 'Foo'); |
||
| 31 | $myMethod->addParameter('bar', 'null', 'Bar'); |
||
| 32 | $myMethodBody = $blockFactory->create(); |
||
| 33 | $myMethodBody |
||
| 34 | ->add('$foobar = $foo->toString();') |
||
| 35 | ->add('') |
||
| 36 | ->add('if (!is_null($bar)) {') |
||
| 37 | ->startIndention() |
||
| 38 | ->add('$foobar .= $bar->toString();') |
||
| 39 | ->stopIndention() |
||
| 40 | ->add('}') |
||
| 41 | ->add('') |
||
| 42 | ->add('return $foobar'); |
||
| 43 | $myMethod->setBody($myMethodBody, 'string'); |
||
| 44 | |||
| 45 | echo $myMethod->generate() . PHP_EOL; |
||
| 46 | } |
||
| 47 | } |
||
| 50 | $example->demonstrate(); |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.