hasMethod() public method

public hasMethod ( string $methodName ) : boolean
$methodName string
return boolean
 /**
  * @inherit Zend\Code\Generator\GeneratorInterface
  */
 public function generate()
 {
     $output = '';
     $indent = $this->getIndentation();
     $traits = $this->getTraits();
     if (empty($traits)) {
         return $output;
     }
     $output .= $indent . 'use ' . implode(', ', $traits);
     $aliases = $this->getTraitAliases();
     $overrides = $this->getTraitOverrides();
     if (empty($aliases) && empty($overrides)) {
         $output .= ";" . self::LINE_FEED . self::LINE_FEED;
         return $output;
     }
     $output .= ' {' . self::LINE_FEED;
     foreach ($aliases as $method => $alias) {
         $visibility = null !== $alias['visibility'] ? current(Reflection::getModifierNames($alias['visibility'])) . ' ' : '';
         // validation check
         if ($this->classGenerator->hasMethod($alias['alias'])) {
             throw new Exception\RuntimeException(sprintf('Generation Error: Aliased method %s already exists on this class', $alias['alias']));
         }
         $output .= $indent . $indent . $method . ' as ' . $visibility . $alias['alias'] . ';' . self::LINE_FEED;
     }
     foreach ($overrides as $method => $insteadofTraits) {
         foreach ($insteadofTraits as $insteadofTrait) {
             $output .= $indent . $indent . $method . ' insteadof ' . $insteadofTrait . ';' . self::LINE_FEED;
         }
     }
     $output .= self::LINE_FEED . $indent . '}' . self::LINE_FEED . self::LINE_FEED;
     return $output;
 }
Example #2
0
 private function writeParamFile()
 {
     $file = $this->path . DIRECTORY_SEPARATOR . 'Params.php';
     if (file_exists($file) && class_exists($this->namespace . '\\Params')) {
         $class = new ClassReflection($this->namespace . '\\Params');
         $paramsClass = ClassGenerator::fromReflection($class);
     } else {
         $paramsClass = new ClassGenerator('Params', $this->namespace, null, 'OpenStack\\Common\\Api\\AbstractParams');
     }
     foreach ($this->operations as $operation) {
         $params = $operation['params'];
         if (empty($params)) {
             continue;
         }
         foreach ($params as $paramName => $paramVal) {
             $name = $paramName . ucfirst($paramVal['location']);
             if ($paramsClass->hasMethod($name)) {
                 continue;
             }
             $body = sprintf("return %s;", $this->arrayEncoder->encode($paramVal, ['array.align' => true]));
             $body = str_replace("'\$", '$', $body);
             $body = str_replace("()'", '()', $body);
             $docblock = new DocBlockGenerator(sprintf("Returns information about %s parameter", $paramName), null, [new ReturnTag(['array'])]);
             $paramsClass->addMethod($name, [], MethodGenerator::FLAG_PUBLIC, $body, $docblock);
         }
     }
     $output = sprintf("<?php\n\n%s", $paramsClass->generate());
     file_put_contents($file, $output);
 }
    /**
     * @group ZF-7361
     */
    public function testHasMethod()
    {
        $classGenerator = new ClassGenerator();
        $classGenerator->addMethod('methodOne');

        $this->assertTrue($classGenerator->hasMethod('methodOne'));
    }
Example #4
0
 /**
  * @group ZF-7361
  */
 public function testHasMethod()
 {
     $method = new MethodGenerator();
     $method->setName('methodOne');
     $classGenerator = new ClassGenerator();
     $classGenerator->setMethod($method);
     $this->assertTrue($classGenerator->hasMethod('methodOne'));
 }
Example #5
0
 public function testRemoveMethodInsensitive()
 {
     $classGenerator = new ClassGenerator();
     $classGenerator->addMethod('methodOne');
     $classGenerator->removeMethod('METHODONe');
     $this->assertFalse($classGenerator->hasMethod('methodOne'));
 }