This class seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate
the same code in three or more different places, we strongly encourage you to
look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
19
{
20
public function fieldDefinitions()
21
{
22
return [
23
'action' => [static::TYPE => 'string'],
24
'locale' => [static::TYPE => 'string'],
25
];
26
}
27
28
/**
29
* @param string $locale
30
* @param Context|callable $context
31
* @return CartSetLocaleAction
32
*/
33
public static function ofLocale($locale, $context = null)
34
{
35
return static::of($context)->setLocale($locale);
36
}
37
38
/**
39
* @param array $data
40
* @param Context|callable $context
41
*/
42
public function __construct(array $data = [], $context = null)
It seems like you code against a specific sub-type and not the parent class Commercetools\Core\Request\AbstractAction as the method setLocale() does only exist in the following sub-classes of Commercetools\Core\Request\AbstractAction: Commercetools\Core\Reque...and\CartSetLocaleAction, Commercetools\Core\Reque...CustomerSetLocaleAction, Commercetools\Core\Reque...nd\OrderSetLocaleAction, Commercetools\Core\Reque...d\ReviewSetLocaleAction. Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example:
abstractclassUser{/** @return string */abstractpublicfunctiongetPassword();}classMyUserextendsUser{publicfunctiongetPassword(){// return something}publicfunctiongetDisplayName(){// return some name.}}classAuthSystem{publicfunctionauthenticate(User$user){$this->logger->info(sprintf('Authenticating %s.',$user->getDisplayName()));// do something.}}
In the above example, the authenticate() method works fine as long as you just pass
instances of MyUser. However, if you now also want to pass a different sub-classes
of User which does not have a getDisplayName() method, the code will break.
classAuthSystem{publicfunctionauthenticate(User$user){if($userinstanceofMyUser){$this->logger->info(/** ... */);}// or alternativelyif(!$userinstanceofMyUser){thrownew\LogicException('$user must be an instance of MyUser, '.'other instances are not supported.');}}}
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
It seems like you call parent on a different method (toArray() instead of toJson()). Are you sure this is correct? If so, you might want to change this to $this->toArray().
This check looks for a call to a parent method whose name is different than
the method from which it is called.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.