88use Dacastro4 \LaravelGmail \Traits \SendsParameters ;
99use Google_Service_Gmail ;
1010use Google_Service_Gmail_ListMessagesResponse ;
11+ use Google_Service_Gmail_Message ;
12+ use Illuminate \Support \Collection ;
1113
1214class Message
1315{
1416 use Filterable,
1517 SendsParameters;
1618
17- public $ service ;
19+ private Google_Service_Gmail $ service ;
1820
19- public $ preload = false ;
21+ private bool $ preload = false ;
2022
21- public $ pageToken ;
23+ private ? string $ pageToken = null ;
2224
23- public $ client ;
25+ private LaravelGmailClass $ client ;
2426
2527 /**
2628 * Optional parameter for getting single and multiple emails
27- *
28- * @var array
2929 */
30- protected $ params = [];
30+ protected array $ params = [];
3131
3232 /**
3333 * Message constructor.
@@ -41,28 +41,21 @@ public function __construct(LaravelGmailClass $client)
4141 /**
4242 * Returns next page if available of messages or an empty collection
4343 *
44- * @return \Illuminate\Support\Collection
45- *
4644 * @throws \Google_Exception
4745 */
48- public function next ()
46+ public function next (): Collection
4947 {
50- if ($ this ->pageToken ) {
51- return $ this ->all ($ this ->pageToken );
52- } else {
53- return new MessageCollection ([], $ this );
54- }
48+ return $ this ->pageToken
49+ ? $ this ->all ($ this ->pageToken )
50+ : new MessageCollection ([], $ this );
5551 }
5652
5753 /**
5854 * Returns a collection of Mail instances
5955 *
60- *
61- * @return \Illuminate\Support\Collection
62- *
6356 * @throws \Google_Exception
6457 */
65- public function all (?string $ pageToken = null )
58+ public function all (?string $ pageToken = null ): Collection
6659 {
6760 if (! is_null ($ pageToken )) {
6861 $ this ->add ($ pageToken , 'pageToken ' );
@@ -87,31 +80,28 @@ public function all(?string $pageToken = null)
8780
8881 /**
8982 * Returns boolean if the page token variable is null or not
90- *
91- * @return bool
9283 */
93- public function hasNextPage ()
84+ public function hasNextPage (): bool
9485 {
9586 return (bool ) $ this ->pageToken ;
9687 }
9788
89+ public function getPageToken (): ?string
90+ {
91+ return $ this ->pageToken ;
92+ }
93+
9894 /**
9995 * Limit the messages coming from the query
100- *
101- * @param int $number
102- * @return Message
10396 */
104- public function take ($ number )
97+ public function take (int $ number ): self
10598 {
106- $ this ->params ['maxResults ' ] = abs (( int ) $ number );
99+ $ this ->params ['maxResults ' ] = abs ($ number );
107100
108101 return $ this ;
109102 }
110103
111- /**
112- * @return Mail
113- */
114- public function get ($ id )
104+ public function get (string $ id ): Mail
115105 {
116106 $ message = $ this ->getRequest ($ id );
117107
@@ -120,11 +110,8 @@ public function get($id)
120110
121111 /**
122112 * Creates a batch request to get all emails in a single call
123- *
124- *
125- * @return array|null
126113 */
127- public function batchRequest ($ allMessages )
114+ public function batchRequest (array $ allMessages ): array
128115 {
129116 $ this ->client ->setUseBatch (true );
130117
@@ -151,26 +138,21 @@ public function batchRequest($allMessages)
151138 * Preload the information on each Mail objects.
152139 * If is not preload you will have to call the load method from the Mail class
153140 *
154- * @return $this
155- *
156141 * @see Mail::load()
157142 */
158- public function preload ()
143+ public function preload (): self
159144 {
160145 $ this ->preload = true ;
161146
162147 return $ this ;
163148 }
164149
165- public function getUser ()
150+ public function getUser (): string
166151 {
167152 return $ this ->client ->user ();
168153 }
169154
170- /**
171- * @return \Google_Service_Gmail_Message
172- */
173- private function getRequest ($ id )
155+ private function getRequest (string $ id ): Google_Service_Gmail_Message
174156 {
175157 return $ this ->service ->users_messages ->get ('me ' , $ id );
176158 }
0 commit comments