Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InterfaceMethodGenerator.php
Go to the documentation of this file.
1 <?php
7 
11 class InterfaceMethodGenerator extends \Zend\Code\Generator\MethodGenerator
12 {
16  public function generate()
17  {
18  $this->validateMethodModifiers();
19  $output = '';
20  if (!$this->getName()) {
21  return $output;
22  }
23 
24  $indent = $this->getIndentation();
25 
26  if (($docBlock = $this->getDocBlock()) !== null) {
27  $docBlock->setIndentation($indent);
28  $output .= $docBlock->generate();
29  }
30 
31  $output .= $indent;
32 
33  $output .= $this->getVisibility() . (($this->isStatic()) ? ' static' : '')
34  . ' function ' . $this->getName() . '(';
35 
36  $parameters = $this->getParameters();
37  if (!empty($parameters)) {
38  $parameterOutput = [];
39  foreach ($parameters as $parameter) {
40  $parameterOutput[] = $parameter->generate();
41  }
42  $output .= implode(', ', $parameterOutput);
43  }
44 
45  $output .= ');' . self::LINE_FEED;
46 
47  return $output;
48  }
49 
56  protected function validateMethodModifiers()
57  {
58  if ($this->getVisibility() != self::VISIBILITY_PUBLIC) {
59  throw new \LogicException(
60  "Interface method visibility can only be 'public'. Method name: '{$this->getName()}'"
61  );
62  }
63  if ($this->isFinal()) {
64  throw new \LogicException(
65  "Interface method cannot be marked as 'final'. Method name: '{$this->getName()}'"
66  );
67  }
68  if ($this->isAbstract()) {
69  throw new \LogicException(
70  "'abstract' modifier cannot be used for interface method. Method name: '{$this->getName()}'"
71  );
72  }
73  }
74 }