How to use service container correcly? I want to use service container inside my class so I have this this: 

class SomeController extends ControllerBase {

  protected $entityTypeManager;
  protected $requestStack;

  public function __construct(EntityTypeManagerInterface $entityTypeManager,RequestStack $requestStack){
    $this-&gt;entityTypeManager = $entityTypeManager;
    $this-&gt;requestStack = $requestStack;
   }

  public static function create(ContainerInterface $container) {
    return new static(
      $container-&gt;get('entity_type.manager'),
      $container-&gt;get('request_stack'),
    );
  }

  public function content() {
    $testEntityTypeManager = $this-&gt;entityTypeManager-&gt;getStorage('node')-&gt;getQuery();
    $testRequest = $requestStack-&gt;getCurrentRequest();
    //do something with these...
  }

}


What I wanted to do here is create a container for EntityTypeManager and RequestStack. Now phpStorm is giving me a warning regarding public static function create(ContainerInterface $container) and it says Method call uses 2 parameters, but method signature uses 1 parameters and I can't use it in my method content(). 

$testEntityTypeManager and $testRequest are just examples with which I would do something else but even now it doesn't work and phpStorm tells me getCurrentRequest().

Sure I can use them statically but that is not what I'm trying to achieve here. Any push in right direction is appreciated!
The error:


  Method call uses 2 parameters, but method signature uses 1


Your create() method is defined to only receive a single argument, $container. This must be a debugger in PHPStorm giving you this output, because what it is saying is that the code calling SomeController::create() is passing two arguments. So the second is getting lost. Your problem is likely stemming from that, and probably means one of two things:


The code calling the create() function is mistakenly passing a second value, or
Your create() function needs to be re-defined to catch the second argument, and do something with it.


ControllerBase::create only expects a single argument, $container, and since your function defines that, I'd guess the more likely culprit is the calling function passing an unnecessary argument (#1 above). However, if the passed variable is necessary for some reason, SomeController::create() can be redefined to catch an optional argument:

public function create(ContainerInteface $container, $additional_param1 = NULL) {
  if (is_null($additional_param1)) {
    throw new \Exception('$additional_param_1 is required');
  }

  // Continue as normal.

}