Shares of Apple (AAPL 0.51%) have gained some momentum over the past month thanks to a small tech stock rally, but the iPhone maker will be facing a litmus test when it releases its fiscal 2022 third-quarter earnings report on July 28.

Apple stock is down 18% so far in 2022 in the wake of the broad market sell-off, so it trades at an attractive valuation right now. That might tempt investors to buy shares before it releases its quarterly results, as a strong showing could send the stock higher. But then, the global smartphone market hasn't been in the best shape this year, and that could hurt the company's biggest business.

So investors might be undecided about what to do with Apple stock this earnings season. Should they be buying in anticipation of more gains? Or will it be a good idea to sell this tech stock and cut any further losses? Let's find out.

Reasons to sell Apple stock

Global smartphone sales are declining this year. Counterpoint Research estimates that smartphone shipments were down 8% year over year in the first quarter of 2022 to 326 million units. The second quarter isn't looking good for smartphone sales, either, as shipments in May reportedly fell 10% year over year to 96 million units. According to Counterpoint, this was only the second time in nearly a decade that monthly shipments fell below 100 million units.

The smartphone market has been hit hard by headwinds such as surging inflation and weak consumer confidence, along with renewed COVID-19-induced lockdowns in China and geopolitical instability in Europe that are hurting sales. Not surprisingly, the 2022 outlook for smartphone sales doesn't look promising. Counterpoint estimates a 3% decline in shipments this year.

The headwinds mentioned above could weigh on Apple's iPhone sales this year. According to third-party estimates, the company is expected to keep iPhone production flat at 220 million units in 2022. The iPhone was its biggest source of revenue in the second quarter of fiscal 2022, accounting for 52% of its top line. So, a flat performance from the iPhone could hinder the company's ability to meet Wall Street's expectations.

Analysts are looking for $1.16 per share in earnings on revenue of $82.5 billion from Apple for the fiscal third quarter. Those numbers don't look inspiring as compared to the prior-year period's earnings of $1.30 per share and revenue of $81.4 billion. The decline in earnings amid a weak smartphone sales environment could strengthen the bear case and send Apple lower, which is why investors looking to cut their losses might consider selling the stock.

Reasons to buy Apple stock

Wall Street's expectations indicate that Apple's business is going to hit a speed bump in the fiscal third quarter. Moreover, the company hadn't provided any guidance citing the near-term uncertainty surrounding its business.

But then, Apple might turn in better-than-expected results on the back of healthy iPhone demand. According to Morgan Stanley, the company reportedly built 44.3 million iPhones in the quarter that ended in June. The investment bank has raised its iPhone build forecast by 14% for the June quarter over the past four months.

That doesn't seem surprising, as Apple has been outperforming the broader smartphone market. It increased its iPhone sales in the first quarter of the calendar year while the overall market declined, driven by the growing adoption of 5G smartphones.

Apple leads the 5G smartphone market and enjoys strong pricing power. So the iPhone could thrive despite the smartphone market's gloom. It is also worth noting that the company has a massive installed base of users who are in an upgrade window, which could set the company up for a strong second half. Foxconn, which is a key contractor that assembles iPhones, recently raised its guidance for the full year citing strong smartphone demand.

Meanwhile, the growth of the high-margin services business has played an important role in helping Apple crush consensus earnings estimates over the past four quarters. It expects the services business to grow in the double digits in the June quarter. That could give its margins and the bottom line a nice boost as the services business reported a gross margin of 72.6% in the fiscal second quarter, way higher than the company's overall gross margin of 43.7%.

In all, the company could spring a positive surprise when it releases its quarterly report later this month. A strong set of results and outlook can help Apple sustain its rally and inflate its valuation. That's why investors might consider buying the stock since it is trading at 24 times earnings right now, a discount to last year's earnings multiple of 31.