@@ -17,7 +17,7 @@ class InvoiceTemplate {
1717 private $ contributionId ;
1818
1919 private $ contributionOwnerCompany ;
20-
20+
2121 private static $ processedInvoices = 0 ;
2222 private static $ contributionCache = [];
2323 private static $ contributionCacheOrder = [];
@@ -34,7 +34,7 @@ public function __construct(&$templateParams, $context) {
3434
3535 public function handle () {
3636 self ::$ processedInvoices ++;
37-
37+
3838 try {
3939 $ this ->addTaxConversionTable ();
4040
@@ -45,14 +45,14 @@ public function handle() {
4545 // Cache using LRU
4646 $ this ->addToLRUCache (self ::$ ownerCompanyCache , self ::$ ownerCompanyCacheOrder , $ this ->contributionId , $ this ->contributionOwnerCompany );
4747 }
48-
48+
4949 if (empty ($ this ->contributionOwnerCompany )) {
5050 return ;
5151 }
5252
5353 $ this ->useContributionOwnerOrganisationInvoiceTemplate ();
5454 $ this ->replaceDomainTokensWithOwnerOrganisationTokens ();
55-
55+
5656 // Adaptive memory management: Batch-complete trigger after each invoice
5757 // Uses conservative approach with memory-threshold backup
5858 GCManager::maybeCollectGarbage ('invoice_processing ' );
@@ -65,7 +65,7 @@ public function handle() {
6565
6666 private function addTaxConversionTable () {
6767 $ showTaxConversionTable = TRUE ;
68-
68+
6969 // Check LRU cache first
7070 $ contribution = $ this ->getContributionFromCache ($ this ->contributionId );
7171 if (!$ contribution ) {
@@ -79,7 +79,7 @@ private function addTaxConversionTable() {
7979 ->addWhere ('id ' , '= ' , $ this ->contributionId )
8080 ->execute ()
8181 ->first ();
82-
82+
8383 // Cache the result using LRU
8484 $ this ->addToLRUCache (self ::$ contributionCache , self ::$ contributionCacheOrder , $ this ->contributionId , $ contribution );
8585 }
@@ -174,7 +174,7 @@ private function replaceDomainTokensWithOwnerOrganisationTokens() {
174174 */
175175 private function getOwnerOrganisationLocation () {
176176 $ ownerOrganisationId = $ this ->contributionOwnerCompany ['contact_id ' ];
177-
177+
178178 // Check LRU cache first
179179 $ locationDefaults = $ this ->getLocationFromCache ($ ownerOrganisationId );
180180 if (!$ locationDefaults ) {
@@ -199,7 +199,7 @@ private function getOwnerOrganisationLocation() {
199199
200200 return $ locationDefaults ;
201201 }
202-
202+
203203 /**
204204 * Gets contribution data from LRU cache.
205205 */
@@ -210,7 +210,7 @@ private function getContributionFromCache($contributionId) {
210210 }
211211 return FALSE ;
212212 }
213-
213+
214214 /**
215215 * Gets owner company data from LRU cache.
216216 */
@@ -221,7 +221,7 @@ private function getOwnerCompanyFromCache($contributionId) {
221221 }
222222 return FALSE ;
223223 }
224-
224+
225225 /**
226226 * Gets location data from LRU cache.
227227 */
@@ -232,7 +232,7 @@ private function getLocationFromCache($contactId) {
232232 }
233233 return FALSE ;
234234 }
235-
235+
236236 /**
237237 * Updates LRU order by moving item to end (most recently used).
238238 */
@@ -244,7 +244,7 @@ private function updateLRUOrder(&$orderArray, $key) {
244244 }
245245 $ orderArray [] = $ key ;
246246 }
247-
247+
248248 /**
249249 * Adds item to LRU cache, evicting least recently used if at capacity.
250250 */
@@ -255,13 +255,13 @@ private function addToLRUCache(&$cache, &$orderArray, $key, $value) {
255255 $ this ->updateLRUOrder ($ orderArray , $ key );
256256 return ;
257257 }
258-
258+
259259 // If at capacity, remove least recently used item
260260 if (count ($ cache ) >= self ::$ maxCacheSize ) {
261261 $ lruKey = array_shift ($ orderArray );
262262 unset($ cache [$ lruKey ]);
263263 }
264-
264+
265265 // Add new item
266266 $ cache [$ key ] = $ value ;
267267 $ orderArray [] = $ key ;
0 commit comments