@@ -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 /**
@@ -136,11 +147,11 @@ public function getLicenses()
136147 /**
137148 * @return array<string, string|bool|null|string[]>
138149 */
139- public function toArray (UrlGenerator $ generator )
150+ public function toArray ()
140151 {
141152 $ array = $ this ->toBaseArray ();
142- $ array ['compare ' ] = $ this ->getUrl ($ generator );
143- $ array ['link ' ] = $ this ->getProjectUrl ($ generator );
153+ $ array ['compare ' ] = $ this ->getUrl ();
154+ $ array ['link ' ] = $ this ->getProjectUrl ();
144155
145156 return $ array ;
146157 }
@@ -191,30 +202,38 @@ public function toBaseArray()
191202 /**
192203 * @return string|null
193204 */
194- public function getUrl (UrlGenerator $ generator )
205+ public function getUrl ()
195206 {
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- }
207+ return $ this ->compareUrl ;
208+ }
205209
206- return null ;
210+ /**
211+ * @return string|null
212+ */
213+ public function getProjectUrl ()
214+ {
215+ return $ this ->projectUrl ;
207216 }
208217
209- public function getProjectUrl (UrlGenerator $ generator )
218+ private function setUrls (UrlGenerator $ generator )
210219 {
211220 $ package = $ this ->getPackage ();
212221
213- if (!isset ($ package )) {
214- return null ;
222+ if (isset ($ package )) {
223+ $ this ->projectUrl = $ generator ->getProjectUrl ($ package );
224+ }
225+
226+ $ operation = $ this ->getOperation ();
227+
228+ if ($ operation instanceof UpdateOperation) {
229+ $ this ->compareUrl = $ generator ->getCompareUrl ($ operation ->getInitialPackage (), $ operation ->getTargetPackage ());
230+
231+ return ;
215232 }
216233
217- return $ generator ->getProjectUrl ($ package );
234+ if ($ operation instanceof InstallOperation || $ operation instanceof UninstallOperation) {
235+ $ this ->compareUrl = $ generator ->getReleaseUrl ($ operation ->getPackage ());
236+ }
218237 }
219238
220239 /**
0 commit comments