Remove and uninstall module in a single patch
You can use ModuleInstaller::uninstall():

\Drupal::service('module_installer')-&gt;uninstall(['social_stats_views']);


In D8 there is a lot of housekeeping to do. You can see this in the code of uninstall():

https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Extension!ModuleInstaller.php/function/ModuleInstaller%3A%3Auninstall/8.2.x