8 – How to get the site path with DrupalKernel :: getSitePath ()?

I am trying to get the site path with DrupalKernel :: getSitePath () but I have the following error:

Fatal error: use $ this when it is not in the context of the object in C: Users julen Sites devdesktop drupal-8.6.1 core lib Drupal Core DrupalKernel.php on line 426

It says that it is not in the context of the object, so how can I get the route without being in the context of the object?