3131
3232class GroupHelper {
3333 /** @var IEvent[] */
34- protected $ event = [];
35- /** @var int */
36- protected $ lastEvent = 0 ;
37-
38- /** @var bool */
39- protected $ allowGrouping ;
34+ protected array $ event = [];
35+ protected int $ lastEvent = 0 ;
36+ protected bool $ allowGrouping = true ;
4037
4138 /** @var IL10N */
4239 protected $ l ;
@@ -53,30 +50,36 @@ class GroupHelper {
5350 public function __construct (IL10N $ l ,
5451 IManager $ activityManager ,
5552 IValidator $ richObjectValidator ,
56- ILogger $ logger ) {
57- $ this ->allowGrouping = true ;
58-
53+ ILogger $ logger
54+ ) {
5955 $ this ->l = $ l ;
6056 $ this ->activityManager = $ activityManager ;
6157 $ this ->richObjectValidator = $ richObjectValidator ;
6258 $ this ->logger = $ logger ;
6359 }
6460
65- /**
66- * @param IL10N $l
67- */
68- public function setL10n (IL10N $ l ) {
61+ public function resetEvents (): void {
62+ $ this ->event = [];
63+ $ this ->lastEvent = 0 ;
64+ }
65+
66+ public function setL10n (IL10N $ l ): void {
6967 $ this ->l = $ l ;
7068 }
7169
7270 /**
7371 * Add an activity to the internal array
74- *
75- * @param array $activity
7672 */
77- public function addActivity ($ activity ) {
73+ public function addActivity (array $ activity ): void {
7874 $ id = (int ) $ activity ['activity_id ' ];
7975 $ event = $ this ->arrayToEvent ($ activity );
76+ $ this ->addEvent ($ id , $ event );
77+ }
78+
79+ /**
80+ * Add an event to the internal array
81+ */
82+ public function addEvent (int $ id , IEvent $ event ): void {
8083 $ language = $ this ->l ->getLanguageCode ();
8184
8285 foreach ($ this ->activityManager ->getProviders () as $ provider ) {
@@ -87,34 +90,37 @@ public function addActivity($activity) {
8790 } else {
8891 $ event = $ provider ->parse ($ language , $ event );
8992 }
90- try {
91- $ this ->richObjectValidator ->validate ($ event ->getRichSubject (), $ event ->getRichSubjectParameters ());
92- } catch (InvalidObjectExeption $ e ) {
93- $ this ->logger ->logException ($ e );
94- $ event ->setRichSubject ('Rich subject or a parameter for " ' . $ event ->getRichSubject () . '" is malformed ' , []);
95- $ event ->setParsedSubject ('Rich subject or a parameter for " ' . $ event ->getRichSubject () . '" is malformed ' );
96- }
97-
98- if ($ event ->getRichMessage ()) {
99- try {
100- $ this ->richObjectValidator ->validate ($ event ->getRichMessage (), $ event ->getRichMessageParameters ());
101- } catch (InvalidObjectExeption $ e ) {
102- $ this ->logger ->logException ($ e );
103- $ event ->setRichMessage ('Rich message or a parameter is malformed ' , []);
104- $ event ->setParsedMessage ('Rich message or a parameter is malformed ' );
105- }
106- }
93+ } catch (\InvalidArgumentException $ e ) {
94+ } catch (\Throwable $ e ) {
95+ $ this ->logger ->error ('Error while parsing activity event ' , ['exception ' => $ e ]);
96+ }
97+ }
10798
108- $ this ->activityManager ->setFormattingObject ('' , 0 );
99+ try {
100+ $ this ->richObjectValidator ->validate ($ event ->getRichSubject (), $ event ->getRichSubjectParameters ());
101+ } catch (InvalidObjectExeption $ e ) {
102+ $ this ->logger ->logException ($ e );
103+ $ event ->setRichSubject ('Rich subject or a parameter for " ' . $ event ->getRichSubject () . '" is malformed ' , []);
104+ $ event ->setParsedSubject ('Rich subject or a parameter for " ' . $ event ->getRichSubject () . '" is malformed ' );
105+ }
109106
110- $ child = $ event ->getChildEvent ();
111- if ($ child instanceof IEvent) {
112- unset($ this ->event [$ this ->lastEvent ]);
113- }
114- } catch (\InvalidArgumentException $ e ) {
107+ if ($ event ->getRichMessage ()) {
108+ try {
109+ $ this ->richObjectValidator ->validate ($ event ->getRichMessage (), $ event ->getRichMessageParameters ());
110+ } catch (InvalidObjectExeption $ e ) {
111+ $ this ->logger ->logException ($ e );
112+ $ event ->setRichMessage ('Rich message or a parameter is malformed ' , []);
113+ $ event ->setParsedMessage ('Rich message or a parameter is malformed ' );
115114 }
116115 }
117116
117+ $ this ->activityManager ->setFormattingObject ('' , 0 );
118+
119+ $ child = $ event ->getChildEvent ();
120+ if ($ child instanceof IEvent) {
121+ unset($ this ->event [$ this ->lastEvent ]);
122+ }
123+
118124 if (!$ event ->getParsedSubject ()) {
119125 $ this ->logger ->debug ('Activity " ' . $ event ->getRichSubject () . '" was not parsed by any provider ' );
120126 return ;
@@ -129,7 +135,7 @@ public function addActivity($activity) {
129135 *
130136 * @return array translated activities ready for use
131137 */
132- public function getActivities () {
138+ public function getActivities (): array {
133139 $ return = [];
134140 foreach ($ this ->event as $ id => $ event ) {
135141 $ return [] = $ this ->eventToArray ($ event , $ id );
@@ -148,11 +154,7 @@ public function getEvents(): array {
148154 return $ return ;
149155 }
150156
151- /**
152- * @param array $row
153- * @return IEvent
154- */
155- protected function arrayToEvent (array $ row ) {
157+ protected function arrayToEvent (array $ row ): IEvent {
156158 $ event = $ this ->activityManager ->generateEvent ();
157159 $ event ->setApp ((string ) $ row ['app ' ])
158160 ->setType ((string ) $ row ['type ' ])
@@ -168,10 +170,8 @@ protected function arrayToEvent(array $row) {
168170 }
169171
170172 /**
171- * @param IEvent $event
172- * @return array
173173 */
174- protected function eventToArray (IEvent $ event , $ id ) {
174+ protected function eventToArray (IEvent $ event , $ id ): array {
175175 return [
176176 'activity_id ' => $ id ,
177177 'app ' => $ event ->getApp (),
@@ -198,10 +198,6 @@ protected function eventToArray(IEvent $event, $id) {
198198 ];
199199 }
200200
201- /**
202- * @param IEvent $event
203- * @return array
204- */
205201 protected function getObjectsFromChildren (IEvent $ event ): array {
206202 $ child = $ event ->getChildEvent ();
207203 $ objects = [];
0 commit comments