I am working with some terrible written online system (Laravel framework), and I see some of the code that is highly possible to be dead one.

The problem is that I cannot trust that much to my IDE whenever some of the lines are used somewhere. Stacktrace during code coverage seems to not use that, but I still think there are better ways to check for it.

Comment the block of code, run your tests. If it’s all green, forget it for a few days/weeks. One day you’ll find this code again and be like “this hasn’t been a problem since I commented it weeks ago, I can delete it”.

What’s a “test”?
put a log around the code and wait if you cant trust the IDE in your scenario
You need to have tests in every supported functionality in order to know what you use and what not. There is no other way to know for sure.
IDE’s don’t do full regression tests.

Runs your tests with coverage, it will tell you if a particular section is being touched, assuming your tests are written well.
Put a false condition around the code (don’t comment it out, as then it’s no longer syntax-checked), and add an else with a logging statement (to file or database), so that you can track whether the code ever comes to that point.
You can optionally log with the possibly unused code intact, so that nothing breaks if the code actually should run.

I went to a PHP conference where they gave a workshop on code analysis. The tool we used was https://www.exakat.io/en/ and I believe it included a function to find dead code. Good luck!
I don’t use this myself, as dead code isn’t such a problem for me, but: https://github.com/krakjoe/tombs

Tombs is a Zend extension for PHP that provides a way to track if a piece of code is actually invoked. This concept is called Tombstones.
It uses Zend hooks to populate a graveyard at runtime, wherein a tomb is representative of every function that Zend has constructed. As Zend executes, functions that are used have their tombs vacated. When the programmer connects to the Tombs socket, a background thread will send populated tombs without interrupting the execution of your application.
i started to use this https://github.com/rectorphp/rector, works fine for me 🙂

There’s a tool literally called “PHP Dead Code Detector (PHPDCD)” by sebastianbergmann (aka the guy behind PhpUnit).
https://github.com/sebastianbergmann/phpdcd
It hasn’t been updated in a while (October 2015), however, and its static analysis is limited (it’s not as powerful as, say, Psalm).
So speaking of Psalm: it does have a dead code detection feature: https://psalm.dev/docs/running_psalm/configuration/#findunusedvariablesandparams
Is the code a part of a function? Who calls that function? If nobody calls that function, you can be pretty confident it’s dead.
Is this app in production? Set a log line in that dead code. If you don’t see the log line execute in 1 year, it’s likely dead.

If it is horribly written put an error_log() statement in the suspected dead code. Come back a year later and see if it ever executed. If it did then it isn’t quite dead yet.

source