| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace ChangelogGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use function array_values; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use function sprintf; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Issue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     private const SINGLE_CONTRIBUTOR_ISSUE_LINE_FORMAT = ' - [%d: %s](%s) thanks to @%s'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     private const MULTI_CONTRIBUTOR_ISSUE_LINE_FORMAT  = ' - [%d: %s](%s) thanks to @%s and @%s'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** @var int */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private $number; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $body; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     private $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** @var string[] */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private $labels = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** @var bool */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     private $isPullRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** @var Issue|null */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     private $linkedPullRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** @var Issue|null */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private $linkedIssue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @param string[] $labels | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 15 |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         int $number, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         string $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         string $body, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         string $url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         string $user, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         array $labels, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         bool $isPullRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 15 |  |         $this->number        = $number; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 15 |  |         $this->title         = $title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 15 |  |         $this->body          = $body; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 15 |  |         $this->url           = $url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 15 |  |         $this->user          = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 15 |  |         $this->labels        = $labels; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 15 |  |         $this->isPullRequest = $isPullRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 15 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 4 |  |     public function getNumber() : int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 4 |  |         return $this->number; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2 |  |     public function getTitle() : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 2 |  |         return $this->title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 4 |  |     public function getBody() : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 4 |  |         return $this->body; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 2 |  |     public function getUrl() : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 2 |  |         return $this->url; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 4 |  |     public function getUser() : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 4 |  |         return $this->user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @return string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 4 |  |     public function getLabels() : array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 4 |  |         return $this->labels; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 4 |  |     public function isPullRequest() : bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 4 |  |         return $this->isPullRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 3 |  |     public function getLinkedPullRequest() : ?Issue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 3 |  |         return $this->linkedPullRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 4 |  |     public function setLinkedPullRequest(Issue $linkedPullRequest) : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 4 |  |         $this->linkedPullRequest = $linkedPullRequest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 2 |  |     public function getLinkedIssue() : ?Issue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 2 |  |         return $this->linkedIssue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 5 |  |     public function setLinkedIssue(Issue $linkedIssue) : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 5 |  |         $this->linkedIssue = $linkedIssue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 5 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * @return string[] | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 123 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 124 | 1 |  |     public function getContributors() : array | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 126 | 1 |  |         $contributors = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 128 | 1 |  |         $contributors[$this->user] = $this->user; | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 130 | 1 |  |         if ($this->linkedPullRequest !== null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 131 | 1 |  |             $contributors[$this->linkedPullRequest->getUser()] = $this->linkedPullRequest->getUser(); | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 134 | 1 |  |         if ($this->linkedIssue !== null) { | 
            
                                                                        
                            
            
                                    
            
            
                | 135 | 1 |  |             $contributors[$this->linkedIssue->getUser()] = $this->linkedIssue->getUser(); | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 138 | 1 |  |         return array_values($contributors); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 3 |  |     public function render() : string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 3 |  |         if ($this->linkedIssue instanceof self && $this->linkedIssue->getUser() !== $this->user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 2 |  |             return sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 2 |  |                 self::MULTI_CONTRIBUTOR_ISSUE_LINE_FORMAT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 | 2 |  |                 $this->number, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 2 |  |                 $this->title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 2 |  |                 $this->url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 2 |  |                 $this->user, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 2 |  |                 $this->linkedIssue->getUser() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 1 |  |         return sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 1 |  |             self::SINGLE_CONTRIBUTOR_ISSUE_LINE_FORMAT, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 1 |  |             $this->number, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 1 |  |             $this->title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 1 |  |             $this->url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 1 |  |             $this->user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 162 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 163 |  |  |  |