- 
                Notifications
    You must be signed in to change notification settings 
- Fork 66
          Add generic support to @method definitions
          #160
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      93e9088
              
                Add generic support to `@method` definitions
              
              
                tyabu12 6e9c776
              
                Avoid BC break and reuse TemplateTagValueNode
              
              
                tyabu12 e661949
              
                Fix PHP 7.2 lint
              
              
                tyabu12 ba315ab
              
                Fix PHP 7.2 lint again
              
              
                tyabu12 cbcd76b
              
                Fix PHP 7.2 lint again 2
              
              
                tyabu12 6838eed
              
                Fix coding standard errors
              
              
                tyabu12 96d3a2f
              
                Reuse parseTemplateTagValue
              
              
                tyabu12 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php declare(strict_types = 1); | ||
|  | ||
| namespace PHPStan\PhpDocParser\Ast\PhpDoc; | ||
|  | ||
| use PHPStan\PhpDocParser\Ast\Node; | ||
| use PHPStan\PhpDocParser\Ast\NodeAttributes; | ||
| use PHPStan\PhpDocParser\Ast\Type\TypeNode; | ||
|  | ||
| class MethodTagValueGenericNode implements Node | ||
| { | ||
|  | ||
| use NodeAttributes; | ||
|  | ||
| /** @var string */ | ||
| public $name; | ||
|  | ||
| /** @var TypeNode|null */ | ||
| public $bound; | ||
|  | ||
| public function __construct(string $name, ?TypeNode $bound) | ||
| { | ||
| $this->name = $name; | ||
| $this->bound = $bound; | ||
| } | ||
|  | ||
|  | ||
| public function __toString(): string | ||
| { | ||
| $bound = $this->bound !== null ? " of {$this->bound}" : ''; | ||
| return trim("{$this->name}{$bound}"); | ||
| } | ||
|  | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -20,17 +20,21 @@ class MethodTagValueNode implements PhpDocTagValueNode | |
| /** @var string */ | ||
| public $methodName; | ||
|  | ||
| /** @var MethodTagValueGenericNode[] */ | ||
| public $generics; | ||
|          | ||
|  | ||
| /** @var MethodTagValueParameterNode[] */ | ||
| public $parameters; | ||
|  | ||
| /** @var string (may be empty) */ | ||
| public $description; | ||
|  | ||
| public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $parameters, string $description) | ||
| public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $generics, array $parameters, string $description) | ||
|          | ||
| { | ||
| $this->isStatic = $isStatic; | ||
| $this->returnType = $returnType; | ||
| $this->methodName = $methodName; | ||
| $this->generics = $generics; | ||
| $this->parameters = $parameters; | ||
| $this->description = $description; | ||
| } | ||
|  | @@ -40,9 +44,10 @@ public function __toString(): string | |
| { | ||
| $static = $this->isStatic ? 'static ' : ''; | ||
| $returnType = $this->returnType !== null ? "{$this->returnType} " : ''; | ||
| $generics = count($this->generics) > 0 ? '<' . implode(', ', $this->generics) . '>' : ''; | ||
| $parameters = implode(', ', $this->parameters); | ||
| $description = $this->description !== '' ? " {$this->description}" : ''; | ||
| return "{$static}{$returnType}{$this->methodName}({$parameters}){$description}"; | ||
| return "{$static}{$returnType}{$this->methodName}{$generics}({$parameters}){$description}"; | ||
| } | ||
|  | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this doesn't need a new node, but TemplateTagValueNode can be reused instead. We'd also gain default template types (#148) automatically :)