Exemplo n.º 1
0
 public function build(int $depth = 0) : string
 {
     $method = $this->tab($depth) . MemberAccess::convert($this->access) . ' ';
     if ($this->isAbstract()) {
         $method .= 'abstract ';
     }
     $method .= 'function ' . $this->getName() . '(';
     $parameters = [];
     foreach ($this->getSignature() as $property) {
         $p = '';
         if ($property->getType()) {
             $p .= $property->getType() . ' ';
         }
         $p .= '$' . $property->getName();
         if ($property->hasDefault()) {
             $default = $property->getDefault();
             if (is_string($default) && !defined($default)) {
                 $default = '"' . addslashes($default) . '"';
             }
             $p .= ' = ' . $default;
         }
         $parameters[] = $p;
     }
     $method .= implode(', ', $parameters) . ')';
     if ($this->getReturns()) {
         $method .= ': ' . $this->getReturns();
     }
     if (!$this->isAbstract()) {
         if (!$this->getCode()) {
             throw new \InvalidArgumentException('A method not declared abstract MUST execute code');
         }
         $method .= ' { ' . PHP_EOL;
         $lines = explode("\n", $this->getCode());
         foreach ($lines as $i => $line) {
             if (strlen($line) > 0) {
                 $lines[$i] = $this->tab($depth + 1) . $line;
             }
         }
         $method .= implode("\n", $lines) . PHP_EOL . $this->tab($depth) . '}';
     } else {
         $method .= ';';
     }
     return $method;
 }
Exemplo n.º 2
0
 /**
  * @param int $depth
  *
  * @return string
  */
 public function build(int $depth = 0) : string
 {
     $prop = str_repeat("\t", $depth);
     if ($this->getAccess()) {
         $prop .= MemberAccess::convert($this->getAccess()) . ' ';
     } else {
         if ($this->getType()) {
             $prop .= $this->getType() . ' ';
         }
     }
     $prop .= '$' . $this->getName();
     if ($this->hasDefault()) {
         $default = $this->getDefault();
         if (is_string($default) && !defined($default)) {
             $default = '"' . addslashes($default) . '"';
         }
         $prop .= ' = ' . $default;
     }
     if ($this->getAccess()) {
         $prop .= ';';
     }
     return $prop;
 }