@@ -27,14 +27,25 @@ class DiffEntry
2727 /** @var string */
2828 private $ type ;
2929
30+ /** @var string|null */
31+ private $ compareUrl ;
32+
33+ /** @var string|null */
34+ private $ projectUrl ;
35+
3036 /**
31- * @param bool $direct
37+ * @param UrlGenerator|null $urlGenerator
38+ * @param bool $direct
3239 */
33- public function __construct (OperationInterface $ operation , $ direct = false )
40+ public function __construct (OperationInterface $ operation , $ urlGenerator = null , $ direct = false )
3441 {
3542 $ this ->operation = $ operation ;
3643 $ this ->direct = $ direct ;
3744 $ this ->type = $ this ->determineType ();
45+
46+ if ($ urlGenerator instanceof UrlGenerator) {
47+ $ this ->setUrls ($ urlGenerator );
48+ }
3849 }
3950
4051 /**
@@ -134,19 +145,35 @@ public function getLicenses()
134145 }
135146
136147 /**
137- * @return array<string, string|bool|null|string[]>
148+ * @return array{
149+ * name: string,
150+ * direct: bool,
151+ * operation: string,
152+ * version_base: string|null,
153+ * version_target: string|null,
154+ * licenses: string[],
155+ * compare: string|null,
156+ * link: string|null,
157+ * }
138158 */
139- public function toArray (UrlGenerator $ generator )
159+ public function toArray ()
140160 {
141161 $ array = $ this ->toBaseArray ();
142- $ array ['compare ' ] = $ this ->getUrl ($ generator );
143- $ array ['link ' ] = $ this ->getProjectUrl ($ generator );
162+ $ array ['compare ' ] = $ this ->getUrl ();
163+ $ array ['link ' ] = $ this ->getProjectUrl ();
144164
145165 return $ array ;
146166 }
147167
148168 /**
149- * @return array<string, string|bool|null|string[]>
169+ * @return array{
170+ * name: string,
171+ * direct: bool,
172+ * operation: string,
173+ * version_base: string|null,
174+ * version_target: string|null,
175+ * licenses: string[],
176+ * }
150177 */
151178 public function toBaseArray ()
152179 {
@@ -191,30 +218,41 @@ public function toBaseArray()
191218 /**
192219 * @return string|null
193220 */
194- public function getUrl (UrlGenerator $ generator )
221+ public function getUrl ()
195222 {
196- $ operation = $ this ->getOperation ();
197-
198- if ($ operation instanceof UpdateOperation) {
199- return $ generator ->getCompareUrl ($ operation ->getInitialPackage (), $ operation ->getTargetPackage ());
200- }
201-
202- if ($ operation instanceof InstallOperation || $ operation instanceof UninstallOperation) {
203- return $ generator ->getReleaseUrl ($ operation ->getPackage ());
204- }
223+ return $ this ->compareUrl ;
224+ }
205225
206- return null ;
226+ /**
227+ * @return string|null
228+ */
229+ public function getProjectUrl ()
230+ {
231+ return $ this ->projectUrl ;
207232 }
208233
209- public function getProjectUrl (UrlGenerator $ generator )
234+ /**
235+ * @return void
236+ */
237+ private function setUrls (UrlGenerator $ generator )
210238 {
211239 $ package = $ this ->getPackage ();
212240
213- if (! isset ($ package )) {
214- return null ;
241+ if (isset ($ package )) {
242+ $ this -> projectUrl = $ generator -> getProjectUrl ( $ package ) ;
215243 }
216244
217- return $ generator ->getProjectUrl ($ package );
245+ $ operation = $ this ->getOperation ();
246+
247+ if ($ operation instanceof UpdateOperation) {
248+ $ this ->compareUrl = $ generator ->getCompareUrl ($ operation ->getInitialPackage (), $ operation ->getTargetPackage ());
249+
250+ return ;
251+ }
252+
253+ if ($ operation instanceof InstallOperation || $ operation instanceof UninstallOperation) {
254+ $ this ->compareUrl = $ generator ->getReleaseUrl ($ operation ->getPackage ());
255+ }
218256 }
219257
220258 /**
0 commit comments